blob: c105e12197c2159eaf106de17899a952306136ca [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040045#include <linux/mnt_namespace.h>
46#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040047#include <linux/nfs_idmap.h>
48#include <linux/vfs.h>
49#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <linux/in6.h>
51#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
Chuck Leverbf0fd762007-07-01 12:13:44 -040069enum {
70 /* Mount options that take no arguments */
71 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040072 Opt_posix, Opt_noposix,
73 Opt_cto, Opt_nocto,
74 Opt_ac, Opt_noac,
75 Opt_lock, Opt_nolock,
76 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040077 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_acl, Opt_noacl,
79 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040080 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050081 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010082 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040083
84 /* Mount options that take integer arguments */
85 Opt_port,
86 Opt_rsize, Opt_wsize, Opt_bsize,
87 Opt_timeo, Opt_retrans,
88 Opt_acregmin, Opt_acregmax,
89 Opt_acdirmin, Opt_acdirmax,
90 Opt_actimeo,
91 Opt_namelen,
92 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040093 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040094 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -040095 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -040096
97 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050098 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040099 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400100 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100101 Opt_fscache_uniq,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
Chuck Leverf45663c2008-06-24 19:28:02 -0400103 /* Special mount options */
104 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400105
106 Opt_err
107};
108
Steven Whitehousea447c092008-10-13 10:46:57 +0100109static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110 { Opt_userspace, "bg" },
111 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400112 { Opt_userspace, "retry=%s" },
113
Chuck Leverf45663c2008-06-24 19:28:02 -0400114 { Opt_sloppy, "sloppy" },
115
Chuck Leverbf0fd762007-07-01 12:13:44 -0400116 { Opt_soft, "soft" },
117 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400118 { Opt_deprecated, "intr" },
119 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400120 { Opt_posix, "posix" },
121 { Opt_noposix, "noposix" },
122 { Opt_cto, "cto" },
123 { Opt_nocto, "nocto" },
124 { Opt_ac, "ac" },
125 { Opt_noac, "noac" },
126 { Opt_lock, "lock" },
127 { Opt_nolock, "nolock" },
128 { Opt_v2, "v2" },
129 { Opt_v3, "v3" },
130 { Opt_udp, "udp" },
131 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400132 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400133 { Opt_acl, "acl" },
134 { Opt_noacl, "noacl" },
135 { Opt_rdirplus, "rdirplus" },
136 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400137 { Opt_sharecache, "sharecache" },
138 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500139 { Opt_resvport, "resvport" },
140 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100141 { Opt_fscache, "fsc" },
142 { Opt_fscache_uniq, "fsc=%s" },
143 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144
Chuck Levera5a16ba2009-06-17 18:02:14 -0700145 { Opt_port, "port=%s" },
146 { Opt_rsize, "rsize=%s" },
147 { Opt_wsize, "wsize=%s" },
148 { Opt_bsize, "bsize=%s" },
149 { Opt_timeo, "timeo=%s" },
150 { Opt_retrans, "retrans=%s" },
151 { Opt_acregmin, "acregmin=%s" },
152 { Opt_acregmax, "acregmax=%s" },
153 { Opt_acdirmin, "acdirmin=%s" },
154 { Opt_acdirmax, "acdirmax=%s" },
155 { Opt_actimeo, "actimeo=%s" },
156 { Opt_namelen, "namlen=%s" },
157 { Opt_mountport, "mountport=%s" },
158 { Opt_mountvers, "mountvers=%s" },
159 { Opt_nfsvers, "nfsvers=%s" },
160 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400161 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400162
163 { Opt_sec, "sec=%s" },
164 { Opt_proto, "proto=%s" },
165 { Opt_mountproto, "mountproto=%s" },
166 { Opt_addr, "addr=%s" },
167 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500168 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400169 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400170
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400171 { Opt_lookupcache, "lookupcache=%s" },
172
Chuck Leverbf0fd762007-07-01 12:13:44 -0400173 { Opt_err, NULL }
174};
175
176enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400177 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400178
179 Opt_xprt_err
180};
181
Steven Whitehousea447c092008-10-13 10:46:57 +0100182static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400183 { Opt_xprt_udp, "udp" },
184 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400185 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400186
187 { Opt_xprt_err, NULL }
188};
189
190enum {
191 Opt_sec_none, Opt_sec_sys,
192 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
193 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
194 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
195
196 Opt_sec_err
197};
198
Steven Whitehousea447c092008-10-13 10:46:57 +0100199static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200 { Opt_sec_none, "none" },
201 { Opt_sec_none, "null" },
202 { Opt_sec_sys, "sys" },
203
204 { Opt_sec_krb5, "krb5" },
205 { Opt_sec_krb5i, "krb5i" },
206 { Opt_sec_krb5p, "krb5p" },
207
208 { Opt_sec_lkey, "lkey" },
209 { Opt_sec_lkeyi, "lkeyi" },
210 { Opt_sec_lkeyp, "lkeyp" },
211
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500212 { Opt_sec_spkm, "spkm3" },
213 { Opt_sec_spkmi, "spkm3i" },
214 { Opt_sec_spkmp, "spkm3p" },
215
Chuck Leverbf0fd762007-07-01 12:13:44 -0400216 { Opt_sec_err, NULL }
217};
218
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400219enum {
220 Opt_lookupcache_all, Opt_lookupcache_positive,
221 Opt_lookupcache_none,
222
223 Opt_lookupcache_err
224};
225
226static match_table_t nfs_lookupcache_tokens = {
227 { Opt_lookupcache_all, "all" },
228 { Opt_lookupcache_positive, "pos" },
229 { Opt_lookupcache_positive, "positive" },
230 { Opt_lookupcache_none, "none" },
231
232 { Opt_lookupcache_err, NULL }
233};
234
Chuck Leverbf0fd762007-07-01 12:13:44 -0400235
Al Viro42faad92008-04-24 07:21:56 -0400236static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400237static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400238static int nfs_show_options(struct seq_file *, struct vfsmount *);
239static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400240static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400241static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400242 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400243static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400244static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400245
246static struct file_system_type nfs_fs_type = {
247 .owner = THIS_MODULE,
248 .name = "nfs",
249 .get_sb = nfs_get_sb,
250 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700251 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400252};
253
David Howells54ceac42006-08-22 20:06:13 -0400254struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400255 .owner = THIS_MODULE,
256 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400257 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400258 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400260};
261
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800262static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode,
266 .statfs = nfs_statfs,
267 .clear_inode = nfs_clear_inode,
268 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400271 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400272};
273
274#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400275static int nfs4_validate_text_mount_data(void *options,
276 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400277static int nfs4_try_mount(int flags, const char *dev_name,
278 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400279static int nfs4_get_sb(struct file_system_type *fs_type,
280 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400281static int nfs4_remote_get_sb(struct file_system_type *fs_type,
282 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400283static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
284 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
285static int nfs4_referral_get_sb(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400287static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400289static void nfs4_kill_super(struct super_block *sb);
290
291static struct file_system_type nfs4_fs_type = {
292 .owner = THIS_MODULE,
293 .name = "nfs4",
294 .get_sb = nfs4_get_sb,
295 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700296 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400297};
298
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400299static struct file_system_type nfs4_remote_fs_type = {
300 .owner = THIS_MODULE,
301 .name = "nfs4",
302 .get_sb = nfs4_remote_get_sb,
303 .kill_sb = nfs4_kill_super,
304 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
305};
306
David Howells54ceac42006-08-22 20:06:13 -0400307struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400308 .owner = THIS_MODULE,
309 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400310 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400311 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700312 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400313};
314
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400315static struct file_system_type nfs4_remote_referral_fs_type = {
316 .owner = THIS_MODULE,
317 .name = "nfs4",
318 .get_sb = nfs4_remote_referral_get_sb,
319 .kill_sb = nfs4_kill_super,
320 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
321};
322
David Howells54ceac42006-08-22 20:06:13 -0400323struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400324 .owner = THIS_MODULE,
325 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400326 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400327 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700328 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400329};
330
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800331static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400332 .alloc_inode = nfs_alloc_inode,
333 .destroy_inode = nfs_destroy_inode,
334 .write_inode = nfs_write_inode,
335 .statfs = nfs_statfs,
336 .clear_inode = nfs4_clear_inode,
337 .umount_begin = nfs_umount_begin,
338 .show_options = nfs_show_options,
339 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400340 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400341};
342#endif
343
Rusty Russell8e1f9362007-07-17 04:03:17 -0700344static struct shrinker acl_shrinker = {
345 .shrink = nfs_access_cache_shrinker,
346 .seeks = DEFAULT_SEEKS,
347};
Trond Myklebust979df722006-07-25 11:28:19 -0400348
David Howellsf7b422b2006-06-09 09:34:33 -0400349/*
350 * Register the NFS filesystems
351 */
352int __init register_nfs_fs(void)
353{
354 int ret;
355
356 ret = register_filesystem(&nfs_fs_type);
357 if (ret < 0)
358 goto error_0;
359
David Howellsf7b422b2006-06-09 09:34:33 -0400360 ret = nfs_register_sysctl();
361 if (ret < 0)
362 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800363#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400364 ret = register_filesystem(&nfs4_fs_type);
365 if (ret < 0)
366 goto error_2;
367#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700368 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400369 return 0;
370
371#ifdef CONFIG_NFS_V4
372error_2:
373 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800374#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400375error_1:
376 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400377error_0:
378 return ret;
379}
380
381/*
382 * Unregister the NFS filesystems
383 */
384void __exit unregister_nfs_fs(void)
385{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700386 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400387#ifdef CONFIG_NFS_V4
388 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400389#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700390 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400391 unregister_filesystem(&nfs_fs_type);
392}
393
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400394void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500395{
396 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400397
398 if (atomic_inc_return(&server->active) == 1)
399 atomic_inc(&sb->s_active);
400}
401
402void nfs_sb_deactive(struct super_block *sb)
403{
404 struct nfs_server *server = NFS_SB(sb);
405
406 if (atomic_dec_and_test(&server->active))
407 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500408}
409
David Howellsf7b422b2006-06-09 09:34:33 -0400410/*
411 * Deliver file system statistics to userspace
412 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400413static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400414{
David Howells0c7d90c2006-08-22 20:06:10 -0400415 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400416 unsigned char blockbits;
417 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400418 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400419 struct nfs_fattr fattr;
420 struct nfs_fsstat res = {
421 .fattr = &fattr,
422 };
423 int error;
424
David Howells8fa5c002006-08-22 20:06:12 -0400425 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400426 if (error < 0)
427 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700428 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400429
430 /*
431 * Current versions of glibc do not correctly handle the
432 * case where f_frsize != f_bsize. Eventually we want to
433 * report the value of wtmult in this field.
434 */
David Howells0c7d90c2006-08-22 20:06:10 -0400435 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400436
437 /*
438 * On most *nix systems, f_blocks, f_bfree, and f_bavail
439 * are reported in units of f_frsize. Linux hasn't had
440 * an f_frsize field in its statfs struct until recently,
441 * thus historically Linux's sys_statfs reports these
442 * fields in units of f_bsize.
443 */
David Howells0c7d90c2006-08-22 20:06:10 -0400444 buf->f_bsize = dentry->d_sb->s_blocksize;
445 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400446 blockres = (1 << blockbits) - 1;
447 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
448 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
449 buf->f_bavail = (res.abytes + blockres) >> blockbits;
450
451 buf->f_files = res.tfiles;
452 buf->f_ffree = res.afiles;
453
454 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700455
David Howellsf7b422b2006-06-09 09:34:33 -0400456 return 0;
457
458 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700459 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700460 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400461}
462
David Howells7d4e2742006-08-22 20:06:07 -0400463/*
464 * Map the security flavour number to a name
465 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400466static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
467{
David Howells7d4e2742006-08-22 20:06:07 -0400468 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400469 rpc_authflavor_t flavour;
470 const char *str;
471 } sec_flavours[] = {
472 { RPC_AUTH_NULL, "null" },
473 { RPC_AUTH_UNIX, "sys" },
474 { RPC_AUTH_GSS_KRB5, "krb5" },
475 { RPC_AUTH_GSS_KRB5I, "krb5i" },
476 { RPC_AUTH_GSS_KRB5P, "krb5p" },
477 { RPC_AUTH_GSS_LKEY, "lkey" },
478 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
479 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
480 { RPC_AUTH_GSS_SPKM, "spkm" },
481 { RPC_AUTH_GSS_SPKMI, "spkmi" },
482 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400483 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400484 };
485 int i;
486
Chuck Lever4d81cd12007-07-01 12:12:40 -0400487 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400488 if (sec_flavours[i].flavour == flavour)
489 break;
490 }
491 return sec_flavours[i].str;
492}
493
Chuck Lever82d101d2008-03-14 14:10:37 -0400494static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
495 int showdefaults)
496{
497 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
498
499 switch (sap->sa_family) {
500 case AF_INET: {
501 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700502 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400503 break;
504 }
505 case AF_INET6: {
506 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700507 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400508 break;
509 }
510 default:
511 if (showdefaults)
512 seq_printf(m, ",mountaddr=unspecified");
513 }
514
515 if (nfss->mountd_version || showdefaults)
516 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
517 if (nfss->mountd_port || showdefaults)
518 seq_printf(m, ",mountport=%u", nfss->mountd_port);
519
520 switch (nfss->mountd_protocol) {
521 case IPPROTO_UDP:
522 seq_printf(m, ",mountproto=udp");
523 break;
524 case IPPROTO_TCP:
525 seq_printf(m, ",mountproto=tcp");
526 break;
527 default:
528 if (showdefaults)
529 seq_printf(m, ",mountproto=auto");
530 }
531}
532
David Howellsf7b422b2006-06-09 09:34:33 -0400533/*
534 * Describe the mount options in force on this server representation
535 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400536static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
537 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400538{
David Howells509de812006-08-22 20:06:11 -0400539 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400540 int flag;
David Howells509de812006-08-22 20:06:11 -0400541 const char *str;
542 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400543 } nfs_info[] = {
544 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400545 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400546 { NFS_MOUNT_NOCTO, ",nocto", "" },
547 { NFS_MOUNT_NOAC, ",noac", "" },
548 { NFS_MOUNT_NONLM, ",nolock", "" },
549 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400550 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500551 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
552 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400553 { 0, NULL, NULL }
554 };
David Howells509de812006-08-22 20:06:11 -0400555 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400556 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400557 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400558
Chuck Lever82d101d2008-03-14 14:10:37 -0400559 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400560 seq_printf(m, ",rsize=%u", nfss->rsize);
561 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400562 if (nfss->bsize != 0)
563 seq_printf(m, ",bsize=%u", nfss->bsize);
564 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400565 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400566 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400567 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400568 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400569 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400570 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400571 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400572 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400573 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
574 if (nfss->flags & nfs_infop->flag)
575 seq_puts(m, nfs_infop->str);
576 else
577 seq_puts(m, nfs_infop->nostr);
578 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400579 seq_printf(m, ",proto=%s",
580 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400581 if (version == 4) {
582 if (nfss->port != NFS_PORT)
583 seq_printf(m, ",port=%u", nfss->port);
584 } else
585 if (nfss->port)
586 seq_printf(m, ",port=%u", nfss->port);
587
Trond Myklebust33170232007-12-20 16:03:59 -0500588 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
589 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400590 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400591
592 if (version != 4)
593 nfs_show_mountd_options(m, nfss, showdefaults);
594
595#ifdef CONFIG_NFS_V4
596 if (clp->rpc_ops->version == 4)
597 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
598#endif
David Howellsb797cac2009-04-03 16:42:48 +0100599 if (nfss->options & NFS_OPTION_FSCACHE)
600 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400601}
602
603/*
604 * Describe the mount options on this VFS mountpoint
605 */
606static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
607{
608 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
609
610 nfs_show_mount_options(m, nfss, 0);
611
Chuck Lever5d8515c2007-12-10 14:57:16 -0500612 seq_printf(m, ",addr=%s",
613 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
614 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400615
616 return 0;
617}
618
619/*
620 * Present statistical information for this VFS mountpoint
621 */
622static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
623{
624 int i, cpu;
625 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
626 struct rpc_auth *auth = nfss->client->cl_auth;
627 struct nfs_iostats totals = { };
628
629 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
630
631 /*
632 * Display all mount option settings
633 */
634 seq_printf(m, "\n\topts:\t");
635 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
636 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
637 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
638 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
639 nfs_show_mount_options(m, nfss, 1);
640
641 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
642
643 seq_printf(m, "\n\tcaps:\t");
644 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400645 seq_printf(m, ",wtmult=%u", nfss->wtmult);
646 seq_printf(m, ",dtsize=%u", nfss->dtsize);
647 seq_printf(m, ",bsize=%u", nfss->bsize);
648 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400649
650#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500651 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400652 seq_printf(m, "\n\tnfsv4:\t");
653 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
654 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
655 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
656 }
657#endif
658
659 /*
660 * Display security flavor in effect for this mount
661 */
Chuck Lever2d767432008-03-14 14:10:08 -0400662 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400663 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400664 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400665
666 /*
667 * Display superblock I/O counters
668 */
669 for_each_possible_cpu(cpu) {
670 struct nfs_iostats *stats;
671
672 preempt_disable();
673 stats = per_cpu_ptr(nfss->io_stats, cpu);
674
675 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
676 totals.events[i] += stats->events[i];
677 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
678 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100679#ifdef CONFIG_NFS_FSCACHE
680 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
681 totals.fscache[i] += stats->fscache[i];
682#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400683
684 preempt_enable();
685 }
686
687 seq_printf(m, "\n\tevents:\t");
688 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
689 seq_printf(m, "%lu ", totals.events[i]);
690 seq_printf(m, "\n\tbytes:\t");
691 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
692 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100693#ifdef CONFIG_NFS_FSCACHE
694 if (nfss->options & NFS_OPTION_FSCACHE) {
695 seq_printf(m, "\n\tfsc:\t");
696 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
697 seq_printf(m, "%Lu ", totals.bytes[i]);
698 }
699#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400700 seq_printf(m, "\n");
701
702 rpc_print_iostats(m, nfss->client);
703
704 return 0;
705}
706
707/*
708 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400709 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400710 */
Al Viro42faad92008-04-24 07:21:56 -0400711static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400712{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200713 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400714 struct rpc_clnt *rpc;
715
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200716 lock_kernel();
717
718 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400719 /* -EIO all pending I/O */
720 rpc = server->client_acl;
721 if (!IS_ERR(rpc))
722 rpc_killall_tasks(rpc);
723 rpc = server->client;
724 if (!IS_ERR(rpc))
725 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200726
727 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400728}
729
730/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500731 * Sanity-check a server address provided by the mount command.
732 *
733 * Address family must be initialized, and address must not be
734 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400735 */
736static int nfs_verify_server_address(struct sockaddr *addr)
737{
738 switch (addr->sa_family) {
739 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500740 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700741 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500742 }
743 case AF_INET6: {
744 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
745 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400746 }
747 }
748
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400749 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400750 return 0;
751}
752
Chuck Lever9412b922007-12-10 14:59:21 -0500753/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400754 * Select between a default port value and a user-specified port value.
755 * If a zero value is set, then autobind will be used.
756 */
757static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port,
758 const unsigned short default_port)
759{
760 unsigned short port = default_port;
761
762 if (parsed_port != NFS_UNSPEC_PORT)
763 port = parsed_port;
764
765 rpc_set_port(sap, port);
766}
767
768/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400769 * Sanity check the NFS transport protocol.
770 *
771 */
772static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
773{
774 switch (mnt->nfs_server.protocol) {
775 case XPRT_TRANSPORT_UDP:
776 case XPRT_TRANSPORT_TCP:
777 case XPRT_TRANSPORT_RDMA:
778 break;
779 default:
780 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
781 }
782}
783
784/*
785 * For text based NFSv2/v3 mounts, the mount protocol transport default
786 * settings should depend upon the specified NFS transport.
787 */
788static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
789{
790 nfs_validate_transport_protocol(mnt);
791
792 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
793 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
794 return;
795 switch (mnt->nfs_server.protocol) {
796 case XPRT_TRANSPORT_UDP:
797 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
798 break;
799 case XPRT_TRANSPORT_TCP:
800 case XPRT_TRANSPORT_RDMA:
801 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
802 }
803}
804
805/*
Chuck Lever01060c82008-06-24 16:33:38 -0400806 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400807 */
808static int nfs_parse_security_flavors(char *value,
809 struct nfs_parsed_mount_data *mnt)
810{
811 substring_t args[MAX_OPT_ARGS];
812
813 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
814
815 switch (match_token(value, nfs_secflavor_tokens, args)) {
816 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400817 mnt->auth_flavors[0] = RPC_AUTH_NULL;
818 break;
819 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400820 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
821 break;
822 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400823 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
824 break;
825 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400826 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
827 break;
828 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400829 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
830 break;
831 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400832 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
833 break;
834 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400835 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
836 break;
837 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400838 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
839 break;
840 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400841 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
842 break;
843 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400844 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
845 break;
846 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400847 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
848 break;
849 default:
850 return 0;
851 }
852
Chuck Lever059f90b2009-08-09 15:09:31 -0400853 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400854 return 1;
855}
856
857/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400858 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400859 * a data structure. The whole mount string is processed; bad options are
860 * skipped as they are encountered. If there were no errors, return 1;
861 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400862 */
863static int nfs_parse_mount_options(char *raw,
864 struct nfs_parsed_mount_data *mnt)
865{
Eric Parisf9c3a382008-03-05 14:20:18 -0500866 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700867 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400868
869 if (!raw) {
870 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
871 return 1;
872 }
873 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
874
Eric Parisf9c3a382008-03-05 14:20:18 -0500875 secdata = alloc_secdata();
876 if (!secdata)
877 goto out_nomem;
878
879 rc = security_sb_copy_data(raw, secdata);
880 if (rc)
881 goto out_security_failure;
882
883 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
884 if (rc)
885 goto out_security_failure;
886
887 free_secdata(secdata);
888
Chuck Leverbf0fd762007-07-01 12:13:44 -0400889 while ((p = strsep(&raw, ",")) != NULL) {
890 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700891 unsigned long option;
892 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400893
894 if (!*p)
895 continue;
896
897 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
898
899 token = match_token(p, nfs_mount_option_tokens, args);
900 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400901
902 /*
903 * boolean options: foo/nofoo
904 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400905 case Opt_soft:
906 mnt->flags |= NFS_MOUNT_SOFT;
907 break;
908 case Opt_hard:
909 mnt->flags &= ~NFS_MOUNT_SOFT;
910 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400911 case Opt_posix:
912 mnt->flags |= NFS_MOUNT_POSIX;
913 break;
914 case Opt_noposix:
915 mnt->flags &= ~NFS_MOUNT_POSIX;
916 break;
917 case Opt_cto:
918 mnt->flags &= ~NFS_MOUNT_NOCTO;
919 break;
920 case Opt_nocto:
921 mnt->flags |= NFS_MOUNT_NOCTO;
922 break;
923 case Opt_ac:
924 mnt->flags &= ~NFS_MOUNT_NOAC;
925 break;
926 case Opt_noac:
927 mnt->flags |= NFS_MOUNT_NOAC;
928 break;
929 case Opt_lock:
930 mnt->flags &= ~NFS_MOUNT_NONLM;
931 break;
932 case Opt_nolock:
933 mnt->flags |= NFS_MOUNT_NONLM;
934 break;
935 case Opt_v2:
936 mnt->flags &= ~NFS_MOUNT_VER3;
937 break;
938 case Opt_v3:
939 mnt->flags |= NFS_MOUNT_VER3;
940 break;
941 case Opt_udp:
942 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400943 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400944 break;
945 case Opt_tcp:
946 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400947 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400948 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400949 case Opt_rdma:
950 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
951 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -0400952 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400953 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400954 case Opt_acl:
955 mnt->flags &= ~NFS_MOUNT_NOACL;
956 break;
957 case Opt_noacl:
958 mnt->flags |= NFS_MOUNT_NOACL;
959 break;
960 case Opt_rdirplus:
961 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
962 break;
963 case Opt_nordirplus:
964 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
965 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400966 case Opt_sharecache:
967 mnt->flags &= ~NFS_MOUNT_UNSHARED;
968 break;
969 case Opt_nosharecache:
970 mnt->flags |= NFS_MOUNT_UNSHARED;
971 break;
Chuck Leverd7403512008-12-23 15:21:37 -0500972 case Opt_resvport:
973 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
974 break;
975 case Opt_noresvport:
976 mnt->flags |= NFS_MOUNT_NORESVPORT;
977 break;
David Howellsb797cac2009-04-03 16:42:48 +0100978 case Opt_fscache:
979 mnt->options |= NFS_OPTION_FSCACHE;
980 kfree(mnt->fscache_uniq);
981 mnt->fscache_uniq = NULL;
982 break;
983 case Opt_nofscache:
984 mnt->options &= ~NFS_OPTION_FSCACHE;
985 kfree(mnt->fscache_uniq);
986 mnt->fscache_uniq = NULL;
987 break;
988 case Opt_fscache_uniq:
989 string = match_strdup(args);
990 if (!string)
991 goto out_nomem;
992 kfree(mnt->fscache_uniq);
993 mnt->fscache_uniq = string;
994 mnt->options |= NFS_OPTION_FSCACHE;
995 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400996
Chuck Leverf45663c2008-06-24 19:28:02 -0400997 /*
998 * options that take numeric values
999 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001001 string = match_strdup(args);
1002 if (string == NULL)
1003 goto out_nomem;
1004 rc = strict_strtoul(string, 10, &option);
1005 kfree(string);
1006 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001007 goto out_invalid_value;
1008 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001009 break;
1010 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001011 string = match_strdup(args);
1012 if (string == NULL)
1013 goto out_nomem;
1014 rc = strict_strtoul(string, 10, &option);
1015 kfree(string);
1016 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001017 goto out_invalid_value;
1018 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001019 break;
1020 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001021 string = match_strdup(args);
1022 if (string == NULL)
1023 goto out_nomem;
1024 rc = strict_strtoul(string, 10, &option);
1025 kfree(string);
1026 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001027 goto out_invalid_value;
1028 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001029 break;
1030 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001031 string = match_strdup(args);
1032 if (string == NULL)
1033 goto out_nomem;
1034 rc = strict_strtoul(string, 10, &option);
1035 kfree(string);
1036 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001037 goto out_invalid_value;
1038 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001039 break;
1040 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001041 string = match_strdup(args);
1042 if (string == NULL)
1043 goto out_nomem;
1044 rc = strict_strtoul(string, 10, &option);
1045 kfree(string);
1046 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001047 goto out_invalid_value;
1048 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001049 break;
1050 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001051 string = match_strdup(args);
1052 if (string == NULL)
1053 goto out_nomem;
1054 rc = strict_strtoul(string, 10, &option);
1055 kfree(string);
1056 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001057 goto out_invalid_value;
1058 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001059 break;
1060 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001061 string = match_strdup(args);
1062 if (string == NULL)
1063 goto out_nomem;
1064 rc = strict_strtoul(string, 10, &option);
1065 kfree(string);
1066 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001067 goto out_invalid_value;
1068 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001069 break;
1070 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001071 string = match_strdup(args);
1072 if (string == NULL)
1073 goto out_nomem;
1074 rc = strict_strtoul(string, 10, &option);
1075 kfree(string);
1076 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001077 goto out_invalid_value;
1078 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001079 break;
1080 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001081 string = match_strdup(args);
1082 if (string == NULL)
1083 goto out_nomem;
1084 rc = strict_strtoul(string, 10, &option);
1085 kfree(string);
1086 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001087 goto out_invalid_value;
1088 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001089 break;
1090 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001091 string = match_strdup(args);
1092 if (string == NULL)
1093 goto out_nomem;
1094 rc = strict_strtoul(string, 10, &option);
1095 kfree(string);
1096 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001097 goto out_invalid_value;
1098 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001099 break;
1100 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001101 string = match_strdup(args);
1102 if (string == NULL)
1103 goto out_nomem;
1104 rc = strict_strtoul(string, 10, &option);
1105 kfree(string);
1106 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001107 goto out_invalid_value;
1108 mnt->acregmin = mnt->acregmax =
1109 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001110 break;
1111 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001112 string = match_strdup(args);
1113 if (string == NULL)
1114 goto out_nomem;
1115 rc = strict_strtoul(string, 10, &option);
1116 kfree(string);
1117 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001118 goto out_invalid_value;
1119 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001120 break;
1121 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001122 string = match_strdup(args);
1123 if (string == NULL)
1124 goto out_nomem;
1125 rc = strict_strtoul(string, 10, &option);
1126 kfree(string);
1127 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001128 goto out_invalid_value;
1129 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001131 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001132 string = match_strdup(args);
1133 if (string == NULL)
1134 goto out_nomem;
1135 rc = strict_strtoul(string, 10, &option);
1136 kfree(string);
1137 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001138 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001139 option > NFS_MNT3_VERSION)
1140 goto out_invalid_value;
1141 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001142 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001143 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001144 string = match_strdup(args);
1145 if (string == NULL)
1146 goto out_nomem;
1147 rc = strict_strtoul(string, 10, &option);
1148 kfree(string);
1149 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001150 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001151 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001152 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001153 mnt->flags &= ~NFS_MOUNT_VER3;
1154 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001155 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001156 mnt->flags |= NFS_MOUNT_VER3;
1157 break;
1158 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001159 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160 }
1161 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001162 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001163 string = match_strdup(args);
1164 if (string == NULL)
1165 goto out_nomem;
1166 rc = strict_strtoul(string, 10, &option);
1167 kfree(string);
1168 if (rc != 0)
1169 goto out_invalid_value;
1170 if (option > NFS4_MAX_MINOR_VERSION)
1171 goto out_invalid_value;
1172 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001173 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001174
Chuck Leverf45663c2008-06-24 19:28:02 -04001175 /*
1176 * options that take text values
1177 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001178 case Opt_sec:
1179 string = match_strdup(args);
1180 if (string == NULL)
1181 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001182 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001183 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001184 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001185 dfprintk(MOUNT, "NFS: unrecognized "
1186 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001187 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001188 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 break;
1190 case Opt_proto:
1191 string = match_strdup(args);
1192 if (string == NULL)
1193 goto out_nomem;
1194 token = match_token(string,
1195 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001196
1197 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001198 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001200 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001201 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001202 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001203 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001205 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001206 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001207 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001208 case Opt_xprt_rdma:
1209 /* vector side protocols to TCP */
1210 mnt->flags |= NFS_MOUNT_TCP;
1211 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001212 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001213 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001214 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001215 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001216 dfprintk(MOUNT, "NFS: unrecognized "
1217 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001218 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 }
1220 break;
1221 case Opt_mountproto:
1222 string = match_strdup(args);
1223 if (string == NULL)
1224 goto out_nomem;
1225 token = match_token(string,
1226 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001227 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001228
1229 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001230 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001231 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001233 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001234 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001236 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001237 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001238 dfprintk(MOUNT, "NFS: unrecognized "
1239 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001240 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001241 }
1242 break;
1243 case Opt_addr:
1244 string = match_strdup(args);
1245 if (string == NULL)
1246 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001247 mnt->nfs_server.addrlen =
1248 rpc_pton(string, strlen(string),
1249 (struct sockaddr *)
1250 &mnt->nfs_server.address,
1251 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001253 if (mnt->nfs_server.addrlen == 0)
1254 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 break;
1256 case Opt_clientaddr:
1257 string = match_strdup(args);
1258 if (string == NULL)
1259 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001260 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 mnt->client_address = string;
1262 break;
Chuck Lever33832032007-12-10 14:59:13 -05001263 case Opt_mounthost:
1264 string = match_strdup(args);
1265 if (string == NULL)
1266 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001267 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001268 mnt->mount_server.hostname = string;
1269 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001270 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001271 string = match_strdup(args);
1272 if (string == NULL)
1273 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001274 mnt->mount_server.addrlen =
1275 rpc_pton(string, strlen(string),
1276 (struct sockaddr *)
1277 &mnt->mount_server.address,
1278 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001279 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001280 if (mnt->mount_server.addrlen == 0)
1281 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001283 case Opt_lookupcache:
1284 string = match_strdup(args);
1285 if (string == NULL)
1286 goto out_nomem;
1287 token = match_token(string,
1288 nfs_lookupcache_tokens, args);
1289 kfree(string);
1290 switch (token) {
1291 case Opt_lookupcache_all:
1292 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1293 break;
1294 case Opt_lookupcache_positive:
1295 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1296 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1297 break;
1298 case Opt_lookupcache_none:
1299 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1300 break;
1301 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001302 dfprintk(MOUNT, "NFS: invalid "
1303 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001304 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001305 };
1306 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001307
Chuck Leverf45663c2008-06-24 19:28:02 -04001308 /*
1309 * Special options
1310 */
1311 case Opt_sloppy:
1312 sloppy = 1;
1313 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1314 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 case Opt_userspace:
1316 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001317 dfprintk(MOUNT, "NFS: ignoring mount option "
1318 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 break;
1320
1321 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001322 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001323 dfprintk(MOUNT, "NFS: unrecognized mount option "
1324 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001325 }
1326 }
1327
Chuck Leverd23c45f2009-06-17 18:02:13 -07001328 if (!sloppy && invalid_option)
1329 return 0;
1330
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 return 1;
1332
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001333out_invalid_address:
1334 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1335 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001336out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001337 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001338 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339out_nomem:
1340 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1341 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001342out_security_failure:
1343 free_secdata(secdata);
1344 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1345 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346}
1347
1348/*
Chuck Leverec88f282009-08-09 15:09:32 -04001349 * Match the requested auth flavors with the list returned by
1350 * the server. Returns zero and sets the mount's authentication
1351 * flavor on success; returns -EACCES if server does not support
1352 * the requested flavor.
1353 */
1354static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1355 struct nfs_mount_request *request)
1356{
1357 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1358
1359 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001360 * Certain releases of Linux's mountd return an empty
1361 * flavor list. To prevent behavioral regression with
1362 * these servers (ie. rejecting mounts that used to
1363 * succeed), revert to pre-2.6.32 behavior (no checking)
1364 * if the returned flavor list is empty.
1365 */
1366 if (server_authlist_len == 0)
1367 return 0;
1368
1369 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001370 * We avoid sophisticated negotiating here, as there are
1371 * plenty of cases where we can get it wrong, providing
1372 * either too little or too much security.
1373 *
1374 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1375 * flavor listed first. However, some servers list
1376 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1377 * preferred default, in args->auth_flavors[0] if user
1378 * didn't specify sec= mount option.
1379 */
1380 for (i = 0; i < args->auth_flavor_len; i++)
1381 for (j = 0; j < server_authlist_len; j++)
1382 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1383 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1384 request->auth_flavs[j]);
1385 args->auth_flavors[0] = request->auth_flavs[j];
1386 return 0;
1387 }
1388
1389 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1390 nfs_umount(request);
1391 return -EACCES;
1392}
1393
1394/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001395 * Use the remote server's MOUNT service to request the NFS file handle
1396 * corresponding to the provided path.
1397 */
1398static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1399 struct nfs_fh *root_fh)
1400{
Chuck Leverec88f282009-08-09 15:09:32 -04001401 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1402 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001403 struct nfs_mount_request request = {
1404 .sap = (struct sockaddr *)
1405 &args->mount_server.address,
1406 .dirpath = args->nfs_server.export_path,
1407 .protocol = args->mount_server.protocol,
1408 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001409 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001410 .auth_flav_len = &server_authlist_len,
1411 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001412 };
Chuck Lever4c568012007-12-10 14:59:28 -05001413 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001414
1415 if (args->mount_server.version == 0) {
1416 if (args->flags & NFS_MOUNT_VER3)
1417 args->mount_server.version = NFS_MNT3_VERSION;
1418 else
1419 args->mount_server.version = NFS_MNT_VERSION;
1420 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001421 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001422
Chuck Lever33832032007-12-10 14:59:13 -05001423 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001424 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001425 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001426 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001427
Chuck Lever0076d7b2007-07-01 12:13:49 -04001428 /*
1429 * Construct the mount server's address.
1430 */
Chuck Lever4c568012007-12-10 14:59:28 -05001431 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001432 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001433 args->nfs_server.addrlen);
1434 args->mount_server.addrlen = args->nfs_server.addrlen;
1435 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001436 request.salen = args->mount_server.addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001437 nfs_set_default_port(request.sap, args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001438
1439 /*
1440 * Now ask the mount server to map our export path
1441 * to a file handle.
1442 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001443 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001444 if (status != 0) {
1445 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1446 request.hostname, status);
1447 return status;
1448 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001449
Chuck Leverec88f282009-08-09 15:09:32 -04001450 /*
1451 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1452 */
1453 if (args->mount_server.version != NFS_MNT3_VERSION)
1454 return 0;
1455 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001456}
1457
Chuck Leverd1aa0822008-06-23 12:36:45 -04001458static int nfs_parse_simple_hostname(const char *dev_name,
1459 char **hostname, size_t maxnamlen,
1460 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001461{
1462 size_t len;
1463 char *colon, *comma;
1464
1465 colon = strchr(dev_name, ':');
1466 if (colon == NULL)
1467 goto out_bad_devname;
1468
1469 len = colon - dev_name;
1470 if (len > maxnamlen)
1471 goto out_hostname;
1472
1473 /* N.B. caller will free nfs_server.hostname in all cases */
1474 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1475 if (!*hostname)
1476 goto out_nomem;
1477
1478 /* kill possible hostname list: not supported */
1479 comma = strchr(*hostname, ',');
1480 if (comma != NULL) {
1481 if (comma == *hostname)
1482 goto out_bad_devname;
1483 *comma = '\0';
1484 }
1485
1486 colon++;
1487 len = strlen(colon);
1488 if (len > maxpathlen)
1489 goto out_path;
1490 *export_path = kstrndup(colon, len, GFP_KERNEL);
1491 if (!*export_path)
1492 goto out_nomem;
1493
1494 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1495 return 0;
1496
1497out_bad_devname:
1498 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1499 return -EINVAL;
1500
1501out_nomem:
1502 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1503 return -ENOMEM;
1504
1505out_hostname:
1506 dfprintk(MOUNT, "NFS: server hostname too long\n");
1507 return -ENAMETOOLONG;
1508
1509out_path:
1510 dfprintk(MOUNT, "NFS: export pathname too long\n");
1511 return -ENAMETOOLONG;
1512}
1513
1514/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001515 * Hostname has square brackets around it because it contains one or
1516 * more colons. We look for the first closing square bracket, and a
1517 * colon must follow it.
1518 */
1519static int nfs_parse_protected_hostname(const char *dev_name,
1520 char **hostname, size_t maxnamlen,
1521 char **export_path, size_t maxpathlen)
1522{
1523 size_t len;
1524 char *start, *end;
1525
1526 start = (char *)(dev_name + 1);
1527
1528 end = strchr(start, ']');
1529 if (end == NULL)
1530 goto out_bad_devname;
1531 if (*(end + 1) != ':')
1532 goto out_bad_devname;
1533
1534 len = end - start;
1535 if (len > maxnamlen)
1536 goto out_hostname;
1537
1538 /* N.B. caller will free nfs_server.hostname in all cases */
1539 *hostname = kstrndup(start, len, GFP_KERNEL);
1540 if (*hostname == NULL)
1541 goto out_nomem;
1542
1543 end += 2;
1544 len = strlen(end);
1545 if (len > maxpathlen)
1546 goto out_path;
1547 *export_path = kstrndup(end, len, GFP_KERNEL);
1548 if (!*export_path)
1549 goto out_nomem;
1550
1551 return 0;
1552
1553out_bad_devname:
1554 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1555 return -EINVAL;
1556
1557out_nomem:
1558 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1559 return -ENOMEM;
1560
1561out_hostname:
1562 dfprintk(MOUNT, "NFS: server hostname too long\n");
1563 return -ENAMETOOLONG;
1564
1565out_path:
1566 dfprintk(MOUNT, "NFS: export pathname too long\n");
1567 return -ENAMETOOLONG;
1568}
1569
1570/*
1571 * Split "dev_name" into "hostname:export_path".
1572 *
1573 * The leftmost colon demarks the split between the server's hostname
1574 * and the export path. If the hostname starts with a left square
1575 * bracket, then it may contain colons.
1576 *
1577 * Note: caller frees hostname and export path, even on error.
1578 */
1579static int nfs_parse_devname(const char *dev_name,
1580 char **hostname, size_t maxnamlen,
1581 char **export_path, size_t maxpathlen)
1582{
1583 if (*dev_name == '[')
1584 return nfs_parse_protected_hostname(dev_name,
1585 hostname, maxnamlen,
1586 export_path, maxpathlen);
1587
1588 return nfs_parse_simple_hostname(dev_name,
1589 hostname, maxnamlen,
1590 export_path, maxpathlen);
1591}
1592
1593/*
David Howells54ceac42006-08-22 20:06:13 -04001594 * Validate the NFS2/NFS3 mount data
1595 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001596 *
1597 * For option strings, user space handles the following behaviors:
1598 *
1599 * + DNS: mapping server host name to IP address ("addr=" option)
1600 *
1601 * + failure mode: how to behave if a mount request can't be handled
1602 * immediately ("fg/bg" option)
1603 *
1604 * + retry: how often to retry a mount request ("retry=" option)
1605 *
1606 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1607 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001608 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001609static int nfs_validate_mount_data(void *options,
1610 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001611 struct nfs_fh *mntfh,
1612 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001613{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001614 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001615 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001616
Chuck Lever5df36e72007-07-01 12:12:56 -04001617 if (data == NULL)
1618 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001619
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001620 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1621 args->rsize = NFS_MAX_FILE_IO_SIZE;
1622 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001623 args->acregmin = NFS_DEF_ACREGMIN;
1624 args->acregmax = NFS_DEF_ACREGMAX;
1625 args->acdirmin = NFS_DEF_ACDIRMIN;
1626 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001627 args->mount_server.port = NFS_UNSPEC_PORT;
1628 args->nfs_server.port = NFS_UNSPEC_PORT;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001629 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001630 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04001631 args->auth_flavor_len = 1;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001632
David Howellsf7b422b2006-06-09 09:34:33 -04001633 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001634 case 1:
1635 data->namlen = 0;
1636 case 2:
1637 data->bsize = 0;
1638 case 3:
1639 if (data->flags & NFS_MOUNT_VER3)
1640 goto out_no_v3;
1641 data->root.size = NFS2_FHSIZE;
1642 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1643 case 4:
1644 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1645 goto out_no_sec;
1646 case 5:
1647 memset(data->context, 0, sizeof(data->context));
1648 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001649 if (data->flags & NFS_MOUNT_VER3) {
1650 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1651 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001652 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001653 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001654 mntfh->size = NFS2_FHSIZE;
1655
Chuck Lever5df36e72007-07-01 12:12:56 -04001656
1657 memcpy(mntfh->data, data->root.data, mntfh->size);
1658 if (mntfh->size < sizeof(mntfh->data))
1659 memset(mntfh->data + mntfh->size, 0,
1660 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001661
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001662 /*
1663 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1664 * can deal with.
1665 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001666 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001667 args->rsize = data->rsize;
1668 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001669 args->timeo = data->timeo;
1670 args->retrans = data->retrans;
1671 args->acregmin = data->acregmin;
1672 args->acregmax = data->acregmax;
1673 args->acdirmin = data->acdirmin;
1674 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001675
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001676 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001677 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001678 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001679 goto out_no_address;
1680
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001681 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001682 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001683 /* N.B. caller will free nfs_server.hostname in all cases */
1684 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1685 args->namlen = data->namlen;
1686 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001687
1688 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1689 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001690 if (!args->nfs_server.hostname)
1691 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001692
1693 /*
1694 * The legacy version 6 binary mount data from userspace has a
1695 * field used only to transport selinux information into the
1696 * the kernel. To continue to support that functionality we
1697 * have a touch of selinux knowledge here in the NFS code. The
1698 * userspace code converted context=blah to just blah so we are
1699 * converting back to the full string selinux understands.
1700 */
1701 if (data->context[0]){
1702#ifdef CONFIG_SECURITY_SELINUX
1703 int rc;
1704 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1705 if (!opts_str)
1706 return -ENOMEM;
1707 strcpy(opts_str, "context=");
1708 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1709 strcat(opts_str, &data->context[0]);
1710 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1711 kfree(opts_str);
1712 if (rc)
1713 return rc;
1714#else
1715 return -EINVAL;
1716#endif
1717 }
1718
Chuck Lever5df36e72007-07-01 12:12:56 -04001719 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001720 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001721 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001722
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001723 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001724 return -EINVAL;
1725
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001726 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001727 goto out_no_address;
1728
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001729 nfs_set_default_port(sap, args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001730
Trond Myklebust259875e2008-07-02 14:43:47 -04001731 nfs_set_mount_transport_protocol(args);
1732
Chuck Leverdc045892008-06-23 12:36:37 -04001733 status = nfs_parse_devname(dev_name,
1734 &args->nfs_server.hostname,
1735 PAGE_SIZE,
1736 &args->nfs_server.export_path,
1737 NFS_MAXPATHLEN);
1738 if (!status)
1739 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001740
Chuck Leverdc045892008-06-23 12:36:37 -04001741 kfree(args->nfs_server.export_path);
1742 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001743
Chuck Lever136d5582007-07-01 12:13:54 -04001744 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001745 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001746
Chuck Lever136d5582007-07-01 12:13:54 -04001747 break;
1748 }
David Howellsf7b422b2006-06-09 09:34:33 -04001749 }
David Howells54ceac42006-08-22 20:06:13 -04001750
David Howellsf7b422b2006-06-09 09:34:33 -04001751#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001752 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001753 goto out_v3_not_compiled;
1754#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001755
David Howells54ceac42006-08-22 20:06:13 -04001756 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001757
1758out_no_data:
1759 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1760 return -EINVAL;
1761
1762out_no_v3:
1763 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1764 data->version);
1765 return -EINVAL;
1766
1767out_no_sec:
1768 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1769 return -EINVAL;
1770
Chuck Lever5df36e72007-07-01 12:12:56 -04001771#ifndef CONFIG_NFS_V3
1772out_v3_not_compiled:
1773 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1774 return -EPROTONOSUPPORT;
1775#endif /* !CONFIG_NFS_V3 */
1776
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001777out_nomem:
1778 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1779 return -ENOMEM;
1780
Chuck Lever5df36e72007-07-01 12:12:56 -04001781out_no_address:
1782 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1783 return -EINVAL;
1784
1785out_invalid_fh:
1786 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1787 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001788}
1789
Jeff Layton48b605f2008-06-10 15:38:39 -04001790static int
1791nfs_compare_remount_data(struct nfs_server *nfss,
1792 struct nfs_parsed_mount_data *data)
1793{
1794 if (data->flags != nfss->flags ||
1795 data->rsize != nfss->rsize ||
1796 data->wsize != nfss->wsize ||
1797 data->retrans != nfss->client->cl_timeout->to_retries ||
1798 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1799 data->acregmin != nfss->acregmin / HZ ||
1800 data->acregmax != nfss->acregmax / HZ ||
1801 data->acdirmin != nfss->acdirmin / HZ ||
1802 data->acdirmax != nfss->acdirmax / HZ ||
1803 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1804 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1805 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1806 data->nfs_server.addrlen) != 0)
1807 return -EINVAL;
1808
1809 return 0;
1810}
1811
1812static int
1813nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1814{
1815 int error;
1816 struct nfs_server *nfss = sb->s_fs_info;
1817 struct nfs_parsed_mount_data *data;
1818 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1819 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001820 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001821
1822 /*
1823 * Userspace mount programs that send binary options generally send
1824 * them populated with default values. We have no way to know which
1825 * ones were explicitly specified. Fall back to legacy behavior and
1826 * just return success.
1827 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001828 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1829 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1830 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001831 return 0;
1832
1833 data = kzalloc(sizeof(*data), GFP_KERNEL);
1834 if (data == NULL)
1835 return -ENOMEM;
1836
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001837 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001838 /* fill out struct with values from existing mount */
1839 data->flags = nfss->flags;
1840 data->rsize = nfss->rsize;
1841 data->wsize = nfss->wsize;
1842 data->retrans = nfss->client->cl_timeout->to_retries;
1843 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1844 data->acregmin = nfss->acregmin / HZ;
1845 data->acregmax = nfss->acregmax / HZ;
1846 data->acdirmin = nfss->acdirmin / HZ;
1847 data->acdirmax = nfss->acdirmax / HZ;
1848 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1849 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1850 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1851 data->nfs_server.addrlen);
1852
1853 /* overwrite those values with any that were specified */
1854 error = nfs_parse_mount_options((char *)options, data);
1855 if (error < 0)
1856 goto out;
1857
1858 /* compare new mount options with old ones */
1859 error = nfs_compare_remount_data(nfss, data);
1860out:
1861 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001862 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001863 return error;
1864}
1865
David Howells54ceac42006-08-22 20:06:13 -04001866/*
1867 * Initialise the common bits of the superblock
1868 */
1869static inline void nfs_initialise_sb(struct super_block *sb)
1870{
1871 struct nfs_server *server = NFS_SB(sb);
1872
1873 sb->s_magic = NFS_SUPER_MAGIC;
1874
1875 /* We probably want something more informative here */
1876 snprintf(sb->s_id, sizeof(sb->s_id),
1877 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1878
1879 if (sb->s_blocksize == 0)
1880 sb->s_blocksize = nfs_block_bits(server->wsize,
1881 &sb->s_blocksize_bits);
1882
1883 if (server->flags & NFS_MOUNT_NOAC)
1884 sb->s_flags |= MS_SYNCHRONOUS;
1885
1886 nfs_super_set_maxbytes(sb, server->maxfilesize);
1887}
1888
1889/*
1890 * Finish setting up an NFS2/3 superblock
1891 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001892static void nfs_fill_super(struct super_block *sb,
1893 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001894{
1895 struct nfs_server *server = NFS_SB(sb);
1896
1897 sb->s_blocksize_bits = 0;
1898 sb->s_blocksize = 0;
1899 if (data->bsize)
1900 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1901
1902 if (server->flags & NFS_MOUNT_VER3) {
1903 /* The VFS shouldn't apply the umask to mode bits. We will do
1904 * so ourselves when necessary.
1905 */
1906 sb->s_flags |= MS_POSIXACL;
1907 sb->s_time_gran = 1;
1908 }
1909
1910 sb->s_op = &nfs_sops;
1911 nfs_initialise_sb(sb);
1912}
1913
1914/*
1915 * Finish setting up a cloned NFS2/3 superblock
1916 */
1917static void nfs_clone_super(struct super_block *sb,
1918 const struct super_block *old_sb)
1919{
1920 struct nfs_server *server = NFS_SB(sb);
1921
1922 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1923 sb->s_blocksize = old_sb->s_blocksize;
1924 sb->s_maxbytes = old_sb->s_maxbytes;
1925
1926 if (server->flags & NFS_MOUNT_VER3) {
1927 /* The VFS shouldn't apply the umask to mode bits. We will do
1928 * so ourselves when necessary.
1929 */
1930 sb->s_flags |= MS_POSIXACL;
1931 sb->s_time_gran = 1;
1932 }
1933
1934 sb->s_op = old_sb->s_op;
1935 nfs_initialise_sb(sb);
1936}
1937
Trond Myklebust275a5d22007-05-16 16:53:28 -04001938static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1939{
1940 const struct nfs_server *a = s->s_fs_info;
1941 const struct rpc_clnt *clnt_a = a->client;
1942 const struct rpc_clnt *clnt_b = b->client;
1943
1944 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1945 goto Ebusy;
1946 if (a->nfs_client != b->nfs_client)
1947 goto Ebusy;
1948 if (a->flags != b->flags)
1949 goto Ebusy;
1950 if (a->wsize != b->wsize)
1951 goto Ebusy;
1952 if (a->rsize != b->rsize)
1953 goto Ebusy;
1954 if (a->acregmin != b->acregmin)
1955 goto Ebusy;
1956 if (a->acregmax != b->acregmax)
1957 goto Ebusy;
1958 if (a->acdirmin != b->acdirmin)
1959 goto Ebusy;
1960 if (a->acdirmax != b->acdirmax)
1961 goto Ebusy;
1962 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1963 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001964 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001965Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001966 return 0;
1967}
1968
1969struct nfs_sb_mountdata {
1970 struct nfs_server *server;
1971 int mntflags;
1972};
1973
1974static int nfs_set_super(struct super_block *s, void *data)
1975{
1976 struct nfs_sb_mountdata *sb_mntdata = data;
1977 struct nfs_server *server = sb_mntdata->server;
1978 int ret;
1979
1980 s->s_flags = sb_mntdata->mntflags;
1981 s->s_fs_info = server;
1982 ret = set_anon_super(s, server);
1983 if (ret == 0)
1984 server->s_dev = s->s_dev;
1985 return ret;
1986}
1987
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001988static int nfs_compare_super_address(struct nfs_server *server1,
1989 struct nfs_server *server2)
1990{
1991 struct sockaddr *sap1, *sap2;
1992
1993 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1994 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1995
1996 if (sap1->sa_family != sap2->sa_family)
1997 return 0;
1998
1999 switch (sap1->sa_family) {
2000 case AF_INET: {
2001 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2002 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2003 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2004 return 0;
2005 if (sin1->sin_port != sin2->sin_port)
2006 return 0;
2007 break;
2008 }
2009 case AF_INET6: {
2010 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2011 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2012 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2013 return 0;
2014 if (sin1->sin6_port != sin2->sin6_port)
2015 return 0;
2016 break;
2017 }
2018 default:
2019 return 0;
2020 }
2021
2022 return 1;
2023}
2024
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002025static int nfs_compare_super(struct super_block *sb, void *data)
2026{
2027 struct nfs_sb_mountdata *sb_mntdata = data;
2028 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2029 int mntflags = sb_mntdata->mntflags;
2030
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002031 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002032 return 0;
2033 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2034 if (old->flags & NFS_MOUNT_UNSHARED)
2035 return 0;
2036 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2037 return 0;
2038 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002039}
2040
Miklos Szeredifa799752008-04-30 00:54:33 -07002041static int nfs_bdi_register(struct nfs_server *server)
2042{
2043 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2044}
2045
David Howells54ceac42006-08-22 20:06:13 -04002046static int nfs_get_sb(struct file_system_type *fs_type,
2047 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2048{
2049 struct nfs_server *server = NULL;
2050 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002051 struct nfs_parsed_mount_data *data;
2052 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002053 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002054 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002055 struct nfs_sb_mountdata sb_mntdata = {
2056 .mntflags = flags,
2057 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002058 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002059
Trond Myklebust33852a12008-06-19 14:20:11 -04002060 data = kzalloc(sizeof(*data), GFP_KERNEL);
2061 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2062 if (data == NULL || mntfh == NULL)
2063 goto out_free_fh;
2064
2065 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002066
David Howells54ceac42006-08-22 20:06:13 -04002067 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002068 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002069 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002070 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002071
2072 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002073 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002074 if (IS_ERR(server)) {
2075 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002076 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002077 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002078 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002079
Trond Myklebust75180df2007-05-16 16:53:28 -04002080 if (server->flags & NFS_MOUNT_UNSHARED)
2081 compare_super = NULL;
2082
David Howells54ceac42006-08-22 20:06:13 -04002083 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002084 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002085 if (IS_ERR(s)) {
2086 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002087 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002088 }
2089
David Howells54ceac42006-08-22 20:06:13 -04002090 if (s->s_fs_info != server) {
2091 nfs_free_server(server);
2092 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002093 } else {
2094 error = nfs_bdi_register(server);
2095 if (error)
2096 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002097 }
David Howells54ceac42006-08-22 20:06:13 -04002098
2099 if (!s->s_root) {
2100 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002101 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002102 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002103 }
2104
Trond Myklebust33852a12008-06-19 14:20:11 -04002105 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002106 if (IS_ERR(mntroot)) {
2107 error = PTR_ERR(mntroot);
2108 goto error_splat_super;
2109 }
2110
Trond Myklebust33852a12008-06-19 14:20:11 -04002111 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002112 if (error)
2113 goto error_splat_root;
2114
David Howellsf7b422b2006-06-09 09:34:33 -04002115 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002116 mnt->mnt_sb = s;
2117 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002118 error = 0;
2119
2120out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002121 kfree(data->nfs_server.hostname);
2122 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002123 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002124 security_free_mnt_opts(&data->lsm_opts);
2125out_free_fh:
2126 kfree(mntfh);
2127 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002128 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002129
David Howells54ceac42006-08-22 20:06:13 -04002130out_err_nosb:
2131 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002132 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002133
Eric Parisf9c3a382008-03-05 14:20:18 -05002134error_splat_root:
2135 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002136error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002137 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002138 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002139}
2140
David Howells54ceac42006-08-22 20:06:13 -04002141/*
2142 * Destroy an NFS2/3 superblock
2143 */
David Howellsf7b422b2006-06-09 09:34:33 -04002144static void nfs_kill_super(struct super_block *s)
2145{
2146 struct nfs_server *server = NFS_SB(s);
2147
Miklos Szeredifa799752008-04-30 00:54:33 -07002148 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002149 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002150 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002151 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002152}
2153
David Howells54ceac42006-08-22 20:06:13 -04002154/*
2155 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2156 */
2157static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2158 const char *dev_name, void *raw_data,
2159 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002160{
2161 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002162 struct super_block *s;
2163 struct nfs_server *server;
2164 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002165 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002166 struct nfs_sb_mountdata sb_mntdata = {
2167 .mntflags = flags,
2168 };
David Howells54ceac42006-08-22 20:06:13 -04002169 int error;
2170
2171 dprintk("--> nfs_xdev_get_sb()\n");
2172
2173 /* create a new volume representation */
2174 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2175 if (IS_ERR(server)) {
2176 error = PTR_ERR(server);
2177 goto out_err_noserver;
2178 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002179 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002180
Trond Myklebust75180df2007-05-16 16:53:28 -04002181 if (server->flags & NFS_MOUNT_UNSHARED)
2182 compare_super = NULL;
2183
David Howells54ceac42006-08-22 20:06:13 -04002184 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002185 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002186 if (IS_ERR(s)) {
2187 error = PTR_ERR(s);
2188 goto out_err_nosb;
2189 }
2190
2191 if (s->s_fs_info != server) {
2192 nfs_free_server(server);
2193 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002194 } else {
2195 error = nfs_bdi_register(server);
2196 if (error)
2197 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002198 }
2199
2200 if (!s->s_root) {
2201 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002202 nfs_clone_super(s, data->sb);
2203 }
2204
2205 mntroot = nfs_get_root(s, data->fh);
2206 if (IS_ERR(mntroot)) {
2207 error = PTR_ERR(mntroot);
2208 goto error_splat_super;
2209 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002210 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002211 dput(mntroot);
2212 error = -ESTALE;
2213 goto error_splat_super;
2214 }
David Howells54ceac42006-08-22 20:06:13 -04002215
2216 s->s_flags |= MS_ACTIVE;
2217 mnt->mnt_sb = s;
2218 mnt->mnt_root = mntroot;
2219
Eric Parisf9c3a382008-03-05 14:20:18 -05002220 /* clone any lsm security options from the parent to the new sb */
2221 security_sb_clone_mnt_opts(data->sb, s);
2222
David Howells54ceac42006-08-22 20:06:13 -04002223 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2224 return 0;
2225
2226out_err_nosb:
2227 nfs_free_server(server);
2228out_err_noserver:
2229 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2230 return error;
2231
2232error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002233 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002234 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2235 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002236}
2237
2238#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002239
2240/*
2241 * Finish setting up a cloned NFS4 superblock
2242 */
2243static void nfs4_clone_super(struct super_block *sb,
2244 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002245{
David Howells54ceac42006-08-22 20:06:13 -04002246 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2247 sb->s_blocksize = old_sb->s_blocksize;
2248 sb->s_maxbytes = old_sb->s_maxbytes;
2249 sb->s_time_gran = 1;
2250 sb->s_op = old_sb->s_op;
2251 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002252}
2253
2254/*
2255 * Set up an NFS4 superblock
2256 */
David Howells54ceac42006-08-22 20:06:13 -04002257static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002258{
David Howellsf7b422b2006-06-09 09:34:33 -04002259 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002260 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002261 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002262}
2263
Trond Myklebust01c3f052009-06-17 13:22:58 -07002264static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2265{
2266 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2267}
2268
Chuck Lever7630c852009-09-08 19:49:57 -04002269static int nfs4_validate_text_mount_data(void *options,
2270 struct nfs_parsed_mount_data *args,
2271 const char *dev_name)
2272{
2273 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2274
2275 nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT);
2276
2277 nfs_validate_transport_protocol(args);
2278
2279 nfs4_validate_mount_flags(args);
2280
2281 if (args->auth_flavor_len > 1) {
2282 dfprintk(MOUNT,
2283 "NFS4: Too many RPC auth flavours specified\n");
2284 return -EINVAL;
2285 }
2286
2287 if (args->client_address == NULL) {
2288 dfprintk(MOUNT,
2289 "NFS4: mount program didn't pass callback address\n");
2290 return -EINVAL;
2291 }
2292
2293 return nfs_parse_devname(dev_name,
2294 &args->nfs_server.hostname,
2295 NFS4_MAXNAMLEN,
2296 &args->nfs_server.export_path,
2297 NFS4_MAXPATHLEN);
2298}
2299
David Howells54ceac42006-08-22 20:06:13 -04002300/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002301 * Validate NFSv4 mount options
2302 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002303static int nfs4_validate_mount_data(void *options,
2304 struct nfs_parsed_mount_data *args,
2305 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002306{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002307 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002308 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002309 char *c;
2310
2311 if (data == NULL)
2312 goto out_no_data;
2313
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002314 args->rsize = NFS_MAX_FILE_IO_SIZE;
2315 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002316 args->acregmin = NFS_DEF_ACREGMIN;
2317 args->acregmax = NFS_DEF_ACREGMAX;
2318 args->acdirmin = NFS_DEF_ACDIRMIN;
2319 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002320 args->nfs_server.port = NFS_UNSPEC_PORT;
Chuck Lever6738b252008-06-24 16:33:54 -04002321 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04002322 args->auth_flavor_len = 1;
Mike Sager3fd5be92009-04-01 09:21:48 -04002323 args->minorversion = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002324
Chuck Leverf0768eb2007-07-01 12:13:01 -04002325 switch (data->version) {
2326 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002327 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002328 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002329 if (data->host_addrlen == 0)
2330 goto out_no_address;
2331 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002332 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002333 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002334 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002335 goto out_no_address;
2336
Chuck Lever6738b252008-06-24 16:33:54 -04002337 if (data->auth_flavourlen) {
2338 if (data->auth_flavourlen > 1)
2339 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002340 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002341 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002342 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002343 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002344 }
2345
2346 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2347 if (IS_ERR(c))
2348 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002349 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002350
2351 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2352 if (IS_ERR(c))
2353 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002354 args->nfs_server.export_path = c;
2355 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002356
2357 c = strndup_user(data->client_addr.data, 16);
2358 if (IS_ERR(c))
2359 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002360 args->client_address = c;
2361
2362 /*
2363 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2364 * can deal with.
2365 */
2366
2367 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2368 args->rsize = data->rsize;
2369 args->wsize = data->wsize;
2370 args->timeo = data->timeo;
2371 args->retrans = data->retrans;
2372 args->acregmin = data->acregmin;
2373 args->acregmax = data->acregmax;
2374 args->acdirmin = data->acdirmin;
2375 args->acdirmax = data->acdirmax;
2376 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002377 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002378
2379 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002380 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002381 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002382 return -EINVAL;
2383
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002384 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002385 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002386
Chuck Lever7630c852009-09-08 19:49:57 -04002387 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002388 }
2389
2390 return 0;
2391
2392out_no_data:
2393 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2394 return -EINVAL;
2395
2396out_inval_auth:
2397 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2398 data->auth_flavourlen);
2399 return -EINVAL;
2400
2401out_no_address:
2402 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2403 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002404}
2405
2406/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002407 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002408 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002409static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002410 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002411{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002412 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002413 struct super_block *s;
2414 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002415 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002416 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002417 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002418 struct nfs_sb_mountdata sb_mntdata = {
2419 .mntflags = flags,
2420 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002421 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002422
Trond Myklebust33852a12008-06-19 14:20:11 -04002423 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2424 if (data == NULL || mntfh == NULL)
2425 goto out_free_fh;
2426
2427 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002428
David Howells54ceac42006-08-22 20:06:13 -04002429 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002430 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002431 if (IS_ERR(server)) {
2432 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002433 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002434 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002435 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002436
Trond Myklebust75180df2007-05-16 16:53:28 -04002437 if (server->flags & NFS4_MOUNT_UNSHARED)
2438 compare_super = NULL;
2439
David Howells54ceac42006-08-22 20:06:13 -04002440 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002441 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002442 if (IS_ERR(s)) {
2443 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002444 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002445 }
2446
Trond Myklebust5dd31772006-08-24 01:03:05 -04002447 if (s->s_fs_info != server) {
2448 nfs_free_server(server);
2449 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002450 } else {
2451 error = nfs_bdi_register(server);
2452 if (error)
2453 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002454 }
2455
David Howells54ceac42006-08-22 20:06:13 -04002456 if (!s->s_root) {
2457 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002458 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002459 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002460 }
David Howellsf7b422b2006-06-09 09:34:33 -04002461
Trond Myklebust33852a12008-06-19 14:20:11 -04002462 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002463 if (IS_ERR(mntroot)) {
2464 error = PTR_ERR(mntroot);
2465 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002466 }
David Howells54ceac42006-08-22 20:06:13 -04002467
Trond Myklebust33852a12008-06-19 14:20:11 -04002468 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002469 if (error)
2470 goto error_splat_root;
2471
David Howellsf7b422b2006-06-09 09:34:33 -04002472 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002473 mnt->mnt_sb = s;
2474 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002475 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002476
Chuck Lever29eb9812007-07-01 12:12:30 -04002477out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002478 security_free_mnt_opts(&data->lsm_opts);
2479out_free_fh:
2480 kfree(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002481 return error;
David Howells54ceac42006-08-22 20:06:13 -04002482
Chuck Lever29eb9812007-07-01 12:12:30 -04002483out_free:
2484 nfs_free_server(server);
2485 goto out;
2486
Eric Paris46c8ac72008-05-02 13:42:42 -07002487error_splat_root:
2488 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002489error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002490 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002491 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002492}
2493
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002494static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2495 int flags, void *data, const char *hostname)
2496{
2497 struct vfsmount *root_mnt;
2498 char *root_devname;
2499 size_t len;
2500
2501 len = strlen(hostname) + 3;
2502 root_devname = kmalloc(len, GFP_KERNEL);
2503 if (root_devname == NULL)
2504 return ERR_PTR(-ENOMEM);
2505 snprintf(root_devname, len, "%s:/", hostname);
2506 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2507 kfree(root_devname);
2508 return root_mnt;
2509}
2510
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002511static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2512{
2513 char *page = (char *) __get_free_page(GFP_KERNEL);
2514 char *devname, *tmp;
2515
2516 if (page == NULL)
2517 return;
2518 devname = nfs_path(path->mnt->mnt_devname,
2519 path->mnt->mnt_root, path->dentry,
2520 page, PAGE_SIZE);
2521 if (devname == NULL)
2522 goto out_freepage;
2523 tmp = kstrdup(devname, GFP_KERNEL);
2524 if (tmp == NULL)
2525 goto out_freepage;
2526 kfree(mnt->mnt_devname);
2527 mnt->mnt_devname = tmp;
2528out_freepage:
2529 free_page((unsigned long)page);
2530}
2531
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002532static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2533 const char *export_path, struct vfsmount *mnt_target)
2534{
2535 struct mnt_namespace *ns_private;
2536 struct nameidata nd;
2537 struct super_block *s;
2538 int ret;
2539
2540 ns_private = create_mnt_ns(root_mnt);
2541 ret = PTR_ERR(ns_private);
2542 if (IS_ERR(ns_private))
2543 goto out_mntput;
2544
2545 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2546 export_path, LOOKUP_FOLLOW, &nd);
2547
2548 put_mnt_ns(ns_private);
2549
2550 if (ret != 0)
2551 goto out_err;
2552
2553 s = nd.path.mnt->mnt_sb;
2554 atomic_inc(&s->s_active);
2555 mnt_target->mnt_sb = s;
2556 mnt_target->mnt_root = dget(nd.path.dentry);
2557
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002558 /* Correct the device pathname */
2559 nfs_fix_devname(&nd.path, mnt_target);
2560
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002561 path_put(&nd.path);
2562 down_write(&s->s_umount);
2563 return 0;
2564out_mntput:
2565 mntput(root_mnt);
2566out_err:
2567 return ret;
2568}
2569
Chuck Levera6fe23b2009-09-08 19:50:00 -04002570static int nfs4_try_mount(int flags, const char *dev_name,
2571 struct nfs_parsed_mount_data *data,
2572 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002573{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002574 char *export_path;
2575 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002576 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002577
Chuck Levera6fe23b2009-09-08 19:50:00 -04002578 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002579
2580 export_path = data->nfs_server.export_path;
2581 data->nfs_server.export_path = "/";
2582 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2583 data->nfs_server.hostname);
2584 data->nfs_server.export_path = export_path;
2585
2586 error = PTR_ERR(root_mnt);
2587 if (IS_ERR(root_mnt))
2588 goto out;
2589
2590 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2591
2592out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002593 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2594 error != 0 ? " [error]" : "");
2595 return error;
2596}
2597
2598/*
2599 * Get the superblock for an NFS4 mountpoint
2600 */
2601static int nfs4_get_sb(struct file_system_type *fs_type,
2602 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2603{
2604 struct nfs_parsed_mount_data *data;
2605 int error = -ENOMEM;
2606
2607 data = kzalloc(sizeof(*data), GFP_KERNEL);
2608 if (data == NULL)
2609 goto out_free_data;
2610
2611 /* Validate the mount data */
2612 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2613 if (error < 0)
2614 goto out;
2615
2616 error = nfs4_try_mount(flags, dev_name, data, mnt);
2617
2618out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002619 kfree(data->client_address);
2620 kfree(data->nfs_server.export_path);
2621 kfree(data->nfs_server.hostname);
2622 kfree(data->fscache_uniq);
2623out_free_data:
2624 kfree(data);
2625 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2626 error != 0 ? " [error]" : "");
2627 return error;
2628}
2629
David Howellsf7b422b2006-06-09 09:34:33 -04002630static void nfs4_kill_super(struct super_block *sb)
2631{
2632 struct nfs_server *server = NFS_SB(sb);
2633
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002634 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002635 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002636 kill_anon_super(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002637 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002638 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002639 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002640 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002641}
2642
2643/*
David Howells54ceac42006-08-22 20:06:13 -04002644 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002645 */
David Howells54ceac42006-08-22 20:06:13 -04002646static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2647 const char *dev_name, void *raw_data,
2648 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002649{
2650 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002651 struct super_block *s;
2652 struct nfs_server *server;
2653 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002654 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002655 struct nfs_sb_mountdata sb_mntdata = {
2656 .mntflags = flags,
2657 };
David Howells54ceac42006-08-22 20:06:13 -04002658 int error;
2659
2660 dprintk("--> nfs4_xdev_get_sb()\n");
2661
2662 /* create a new volume representation */
2663 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2664 if (IS_ERR(server)) {
2665 error = PTR_ERR(server);
2666 goto out_err_noserver;
2667 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002668 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002669
Trond Myklebust75180df2007-05-16 16:53:28 -04002670 if (server->flags & NFS4_MOUNT_UNSHARED)
2671 compare_super = NULL;
2672
David Howells54ceac42006-08-22 20:06:13 -04002673 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002674 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002675 if (IS_ERR(s)) {
2676 error = PTR_ERR(s);
2677 goto out_err_nosb;
2678 }
2679
2680 if (s->s_fs_info != server) {
2681 nfs_free_server(server);
2682 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002683 } else {
2684 error = nfs_bdi_register(server);
2685 if (error)
2686 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002687 }
2688
2689 if (!s->s_root) {
2690 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002691 nfs4_clone_super(s, data->sb);
2692 }
2693
2694 mntroot = nfs4_get_root(s, data->fh);
2695 if (IS_ERR(mntroot)) {
2696 error = PTR_ERR(mntroot);
2697 goto error_splat_super;
2698 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002699 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2700 dput(mntroot);
2701 error = -ESTALE;
2702 goto error_splat_super;
2703 }
David Howells54ceac42006-08-22 20:06:13 -04002704
2705 s->s_flags |= MS_ACTIVE;
2706 mnt->mnt_sb = s;
2707 mnt->mnt_root = mntroot;
2708
Eric Paris46c8ac72008-05-02 13:42:42 -07002709 security_sb_clone_mnt_opts(data->sb, s);
2710
David Howells54ceac42006-08-22 20:06:13 -04002711 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2712 return 0;
2713
2714out_err_nosb:
2715 nfs_free_server(server);
2716out_err_noserver:
2717 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2718 return error;
2719
2720error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002721 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002722 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2723 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002724}
2725
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002726static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2727 int flags, const char *dev_name, void *raw_data,
2728 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002729{
2730 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002731 struct super_block *s;
2732 struct nfs_server *server;
2733 struct dentry *mntroot;
2734 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002735 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002736 struct nfs_sb_mountdata sb_mntdata = {
2737 .mntflags = flags,
2738 };
David Howells54ceac42006-08-22 20:06:13 -04002739 int error;
2740
2741 dprintk("--> nfs4_referral_get_sb()\n");
2742
2743 /* create a new volume representation */
2744 server = nfs4_create_referral_server(data, &mntfh);
2745 if (IS_ERR(server)) {
2746 error = PTR_ERR(server);
2747 goto out_err_noserver;
2748 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002749 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002750
Trond Myklebust75180df2007-05-16 16:53:28 -04002751 if (server->flags & NFS4_MOUNT_UNSHARED)
2752 compare_super = NULL;
2753
David Howells54ceac42006-08-22 20:06:13 -04002754 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002755 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002756 if (IS_ERR(s)) {
2757 error = PTR_ERR(s);
2758 goto out_err_nosb;
2759 }
2760
2761 if (s->s_fs_info != server) {
2762 nfs_free_server(server);
2763 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002764 } else {
2765 error = nfs_bdi_register(server);
2766 if (error)
2767 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002768 }
2769
2770 if (!s->s_root) {
2771 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002772 nfs4_fill_super(s);
2773 }
2774
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002775 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002776 if (IS_ERR(mntroot)) {
2777 error = PTR_ERR(mntroot);
2778 goto error_splat_super;
2779 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002780 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2781 dput(mntroot);
2782 error = -ESTALE;
2783 goto error_splat_super;
2784 }
David Howells54ceac42006-08-22 20:06:13 -04002785
2786 s->s_flags |= MS_ACTIVE;
2787 mnt->mnt_sb = s;
2788 mnt->mnt_root = mntroot;
2789
Eric Paris46c8ac72008-05-02 13:42:42 -07002790 security_sb_clone_mnt_opts(data->sb, s);
2791
David Howells54ceac42006-08-22 20:06:13 -04002792 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2793 return 0;
2794
2795out_err_nosb:
2796 nfs_free_server(server);
2797out_err_noserver:
2798 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2799 return error;
2800
2801error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002802 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002803 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2804 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002805}
2806
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002807/*
2808 * Create an NFS4 server record on referral traversal
2809 */
2810static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2811 int flags, const char *dev_name, void *raw_data,
2812 struct vfsmount *mnt)
2813{
2814 struct nfs_clone_mount *data = raw_data;
2815 char *export_path;
2816 struct vfsmount *root_mnt;
2817 int error;
2818
2819 dprintk("--> nfs4_referral_get_sb()\n");
2820
2821 export_path = data->mnt_path;
2822 data->mnt_path = "/";
2823
2824 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2825 flags, data, data->hostname);
2826 data->mnt_path = export_path;
2827
2828 error = PTR_ERR(root_mnt);
2829 if (IS_ERR(root_mnt))
2830 goto out;
2831
2832 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2833out:
2834 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2835 error != 0 ? " [error]" : "");
2836 return error;
2837}
2838
David Howells54ceac42006-08-22 20:06:13 -04002839#endif /* CONFIG_NFS_V4 */