blob: a2b2805caf9d998e55bfa453825236e87351d32b [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>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040050#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040051#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080052#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040053#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040054
55#include <asm/system.h>
56#include <asm/uaccess.h>
57
58#include "nfs4_fs.h"
59#include "callback.h"
60#include "delegation.h"
61#include "iostat.h"
62#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010063#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040064
65#define NFSDBG_FACILITY NFSDBG_VFS
66
Chuck Leverbf0fd762007-07-01 12:13:44 -040067enum {
68 /* Mount options that take no arguments */
69 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040070 Opt_posix, Opt_noposix,
71 Opt_cto, Opt_nocto,
72 Opt_ac, Opt_noac,
73 Opt_lock, Opt_nolock,
74 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040075 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040076 Opt_acl, Opt_noacl,
77 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040078 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050079 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010080 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040081
82 /* Mount options that take integer arguments */
83 Opt_port,
84 Opt_rsize, Opt_wsize, Opt_bsize,
85 Opt_timeo, Opt_retrans,
86 Opt_acregmin, Opt_acregmax,
87 Opt_acdirmin, Opt_acdirmax,
88 Opt_actimeo,
89 Opt_namelen,
90 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040091 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040092 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040093
94 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050095 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040096 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -040097 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +010098 Opt_fscache_uniq,
Chuck Leverbf0fd762007-07-01 12:13:44 -040099
Chuck Leverf45663c2008-06-24 19:28:02 -0400100 /* Special mount options */
101 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 Opt_err
104};
105
Steven Whitehousea447c092008-10-13 10:46:57 +0100106static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400107 { Opt_userspace, "bg" },
108 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400109 { Opt_userspace, "retry=%s" },
110
Chuck Leverf45663c2008-06-24 19:28:02 -0400111 { Opt_sloppy, "sloppy" },
112
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113 { Opt_soft, "soft" },
114 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400115 { Opt_deprecated, "intr" },
116 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_posix, "posix" },
118 { Opt_noposix, "noposix" },
119 { Opt_cto, "cto" },
120 { Opt_nocto, "nocto" },
121 { Opt_ac, "ac" },
122 { Opt_noac, "noac" },
123 { Opt_lock, "lock" },
124 { Opt_nolock, "nolock" },
125 { Opt_v2, "v2" },
126 { Opt_v3, "v3" },
127 { Opt_udp, "udp" },
128 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400129 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400130 { Opt_acl, "acl" },
131 { Opt_noacl, "noacl" },
132 { Opt_rdirplus, "rdirplus" },
133 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400134 { Opt_sharecache, "sharecache" },
135 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500136 { Opt_resvport, "resvport" },
137 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100138 { Opt_fscache, "fsc" },
139 { Opt_fscache_uniq, "fsc=%s" },
140 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141
142 { Opt_port, "port=%u" },
143 { Opt_rsize, "rsize=%u" },
144 { Opt_wsize, "wsize=%u" },
145 { Opt_bsize, "bsize=%u" },
146 { Opt_timeo, "timeo=%u" },
147 { Opt_retrans, "retrans=%u" },
148 { Opt_acregmin, "acregmin=%u" },
149 { Opt_acregmax, "acregmax=%u" },
150 { Opt_acdirmin, "acdirmin=%u" },
151 { Opt_acdirmax, "acdirmax=%u" },
152 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153 { Opt_namelen, "namlen=%u" },
154 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400155 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400156 { Opt_nfsvers, "nfsvers=%u" },
157 { Opt_nfsvers, "vers=%u" },
158
159 { Opt_sec, "sec=%s" },
160 { Opt_proto, "proto=%s" },
161 { Opt_mountproto, "mountproto=%s" },
162 { Opt_addr, "addr=%s" },
163 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500164 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400165 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400166
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400167 { Opt_lookupcache, "lookupcache=%s" },
168
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169 { Opt_err, NULL }
170};
171
172enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400173 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400174
175 Opt_xprt_err
176};
177
Steven Whitehousea447c092008-10-13 10:46:57 +0100178static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400179 { Opt_xprt_udp, "udp" },
180 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400181 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182
183 { Opt_xprt_err, NULL }
184};
185
186enum {
187 Opt_sec_none, Opt_sec_sys,
188 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
189 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
190 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
191
192 Opt_sec_err
193};
194
Steven Whitehousea447c092008-10-13 10:46:57 +0100195static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400196 { Opt_sec_none, "none" },
197 { Opt_sec_none, "null" },
198 { Opt_sec_sys, "sys" },
199
200 { Opt_sec_krb5, "krb5" },
201 { Opt_sec_krb5i, "krb5i" },
202 { Opt_sec_krb5p, "krb5p" },
203
204 { Opt_sec_lkey, "lkey" },
205 { Opt_sec_lkeyi, "lkeyi" },
206 { Opt_sec_lkeyp, "lkeyp" },
207
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500208 { Opt_sec_spkm, "spkm3" },
209 { Opt_sec_spkmi, "spkm3i" },
210 { Opt_sec_spkmp, "spkm3p" },
211
Chuck Leverbf0fd762007-07-01 12:13:44 -0400212 { Opt_sec_err, NULL }
213};
214
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400215enum {
216 Opt_lookupcache_all, Opt_lookupcache_positive,
217 Opt_lookupcache_none,
218
219 Opt_lookupcache_err
220};
221
222static match_table_t nfs_lookupcache_tokens = {
223 { Opt_lookupcache_all, "all" },
224 { Opt_lookupcache_positive, "pos" },
225 { Opt_lookupcache_positive, "positive" },
226 { Opt_lookupcache_none, "none" },
227
228 { Opt_lookupcache_err, NULL }
229};
230
Chuck Leverbf0fd762007-07-01 12:13:44 -0400231
Al Viro42faad92008-04-24 07:21:56 -0400232static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400233static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400234static int nfs_show_options(struct seq_file *, struct vfsmount *);
235static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400236static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400237static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400238 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400239static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400240static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400241
242static struct file_system_type nfs_fs_type = {
243 .owner = THIS_MODULE,
244 .name = "nfs",
245 .get_sb = nfs_get_sb,
246 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700247 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400248};
249
David Howells54ceac42006-08-22 20:06:13 -0400250struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400251 .owner = THIS_MODULE,
252 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400253 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400254 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400256};
257
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800258static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .alloc_inode = nfs_alloc_inode,
260 .destroy_inode = nfs_destroy_inode,
261 .write_inode = nfs_write_inode,
262 .statfs = nfs_statfs,
263 .clear_inode = nfs_clear_inode,
264 .umount_begin = nfs_umount_begin,
265 .show_options = nfs_show_options,
266 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400267 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400268};
269
270#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400271static int nfs4_get_sb(struct file_system_type *fs_type,
272 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400273static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
274 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
275static int nfs4_referral_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400277static void nfs4_kill_super(struct super_block *sb);
278
279static struct file_system_type nfs4_fs_type = {
280 .owner = THIS_MODULE,
281 .name = "nfs4",
282 .get_sb = nfs4_get_sb,
283 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700284 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400285};
286
David Howells54ceac42006-08-22 20:06:13 -0400287struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400288 .owner = THIS_MODULE,
289 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400290 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400291 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700292 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400293};
294
David Howells54ceac42006-08-22 20:06:13 -0400295struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400296 .owner = THIS_MODULE,
297 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400298 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400299 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700300 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400301};
302
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800303static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400304 .alloc_inode = nfs_alloc_inode,
305 .destroy_inode = nfs_destroy_inode,
306 .write_inode = nfs_write_inode,
307 .statfs = nfs_statfs,
308 .clear_inode = nfs4_clear_inode,
309 .umount_begin = nfs_umount_begin,
310 .show_options = nfs_show_options,
311 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400312 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400313};
314#endif
315
Rusty Russell8e1f9362007-07-17 04:03:17 -0700316static struct shrinker acl_shrinker = {
317 .shrink = nfs_access_cache_shrinker,
318 .seeks = DEFAULT_SEEKS,
319};
Trond Myklebust979df722006-07-25 11:28:19 -0400320
David Howellsf7b422b2006-06-09 09:34:33 -0400321/*
322 * Register the NFS filesystems
323 */
324int __init register_nfs_fs(void)
325{
326 int ret;
327
328 ret = register_filesystem(&nfs_fs_type);
329 if (ret < 0)
330 goto error_0;
331
David Howellsf7b422b2006-06-09 09:34:33 -0400332 ret = nfs_register_sysctl();
333 if (ret < 0)
334 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800335#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400336 ret = register_filesystem(&nfs4_fs_type);
337 if (ret < 0)
338 goto error_2;
339#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700340 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400341 return 0;
342
343#ifdef CONFIG_NFS_V4
344error_2:
345 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800346#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400347error_1:
348 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400349error_0:
350 return ret;
351}
352
353/*
354 * Unregister the NFS filesystems
355 */
356void __exit unregister_nfs_fs(void)
357{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700358 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400359#ifdef CONFIG_NFS_V4
360 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400361#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700362 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400363 unregister_filesystem(&nfs_fs_type);
364}
365
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400366void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500367{
368 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400369
370 if (atomic_inc_return(&server->active) == 1)
371 atomic_inc(&sb->s_active);
372}
373
374void nfs_sb_deactive(struct super_block *sb)
375{
376 struct nfs_server *server = NFS_SB(sb);
377
378 if (atomic_dec_and_test(&server->active))
379 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500380}
381
David Howellsf7b422b2006-06-09 09:34:33 -0400382/*
383 * Deliver file system statistics to userspace
384 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400385static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400386{
David Howells0c7d90c2006-08-22 20:06:10 -0400387 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400388 unsigned char blockbits;
389 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400390 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400391 struct nfs_fattr fattr;
392 struct nfs_fsstat res = {
393 .fattr = &fattr,
394 };
395 int error;
396
David Howells8fa5c002006-08-22 20:06:12 -0400397 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400398 if (error < 0)
399 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700400 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400401
402 /*
403 * Current versions of glibc do not correctly handle the
404 * case where f_frsize != f_bsize. Eventually we want to
405 * report the value of wtmult in this field.
406 */
David Howells0c7d90c2006-08-22 20:06:10 -0400407 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400408
409 /*
410 * On most *nix systems, f_blocks, f_bfree, and f_bavail
411 * are reported in units of f_frsize. Linux hasn't had
412 * an f_frsize field in its statfs struct until recently,
413 * thus historically Linux's sys_statfs reports these
414 * fields in units of f_bsize.
415 */
David Howells0c7d90c2006-08-22 20:06:10 -0400416 buf->f_bsize = dentry->d_sb->s_blocksize;
417 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400418 blockres = (1 << blockbits) - 1;
419 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
420 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
421 buf->f_bavail = (res.abytes + blockres) >> blockbits;
422
423 buf->f_files = res.tfiles;
424 buf->f_ffree = res.afiles;
425
426 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700427
David Howellsf7b422b2006-06-09 09:34:33 -0400428 return 0;
429
430 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700431 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700432 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400433}
434
David Howells7d4e2742006-08-22 20:06:07 -0400435/*
436 * Map the security flavour number to a name
437 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400438static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
439{
David Howells7d4e2742006-08-22 20:06:07 -0400440 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400441 rpc_authflavor_t flavour;
442 const char *str;
443 } sec_flavours[] = {
444 { RPC_AUTH_NULL, "null" },
445 { RPC_AUTH_UNIX, "sys" },
446 { RPC_AUTH_GSS_KRB5, "krb5" },
447 { RPC_AUTH_GSS_KRB5I, "krb5i" },
448 { RPC_AUTH_GSS_KRB5P, "krb5p" },
449 { RPC_AUTH_GSS_LKEY, "lkey" },
450 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
451 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
452 { RPC_AUTH_GSS_SPKM, "spkm" },
453 { RPC_AUTH_GSS_SPKMI, "spkmi" },
454 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400455 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400456 };
457 int i;
458
Chuck Lever4d81cd12007-07-01 12:12:40 -0400459 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400460 if (sec_flavours[i].flavour == flavour)
461 break;
462 }
463 return sec_flavours[i].str;
464}
465
Chuck Lever82d101d2008-03-14 14:10:37 -0400466static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
467 int showdefaults)
468{
469 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
470
471 switch (sap->sa_family) {
472 case AF_INET: {
473 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700474 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400475 break;
476 }
477 case AF_INET6: {
478 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700479 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400480 break;
481 }
482 default:
483 if (showdefaults)
484 seq_printf(m, ",mountaddr=unspecified");
485 }
486
487 if (nfss->mountd_version || showdefaults)
488 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
489 if (nfss->mountd_port || showdefaults)
490 seq_printf(m, ",mountport=%u", nfss->mountd_port);
491
492 switch (nfss->mountd_protocol) {
493 case IPPROTO_UDP:
494 seq_printf(m, ",mountproto=udp");
495 break;
496 case IPPROTO_TCP:
497 seq_printf(m, ",mountproto=tcp");
498 break;
499 default:
500 if (showdefaults)
501 seq_printf(m, ",mountproto=auto");
502 }
503}
504
David Howellsf7b422b2006-06-09 09:34:33 -0400505/*
506 * Describe the mount options in force on this server representation
507 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400508static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
509 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400510{
David Howells509de812006-08-22 20:06:11 -0400511 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400512 int flag;
David Howells509de812006-08-22 20:06:11 -0400513 const char *str;
514 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400515 } nfs_info[] = {
516 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400517 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400518 { NFS_MOUNT_NOCTO, ",nocto", "" },
519 { NFS_MOUNT_NOAC, ",noac", "" },
520 { NFS_MOUNT_NONLM, ",nolock", "" },
521 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400522 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500523 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
524 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400525 { 0, NULL, NULL }
526 };
David Howells509de812006-08-22 20:06:11 -0400527 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400528 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400529 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400530
Chuck Lever82d101d2008-03-14 14:10:37 -0400531 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400532 seq_printf(m, ",rsize=%u", nfss->rsize);
533 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400534 if (nfss->bsize != 0)
535 seq_printf(m, ",bsize=%u", nfss->bsize);
536 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400537 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400538 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400539 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400540 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400541 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400542 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400543 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400544 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400545 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
546 if (nfss->flags & nfs_infop->flag)
547 seq_puts(m, nfs_infop->str);
548 else
549 seq_puts(m, nfs_infop->nostr);
550 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400551 seq_printf(m, ",proto=%s",
552 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400553 if (version == 4) {
554 if (nfss->port != NFS_PORT)
555 seq_printf(m, ",port=%u", nfss->port);
556 } else
557 if (nfss->port)
558 seq_printf(m, ",port=%u", nfss->port);
559
Trond Myklebust33170232007-12-20 16:03:59 -0500560 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
561 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400562 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400563
564 if (version != 4)
565 nfs_show_mountd_options(m, nfss, showdefaults);
566
567#ifdef CONFIG_NFS_V4
568 if (clp->rpc_ops->version == 4)
569 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
570#endif
David Howellsb797cac2009-04-03 16:42:48 +0100571 if (nfss->options & NFS_OPTION_FSCACHE)
572 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400573}
574
575/*
576 * Describe the mount options on this VFS mountpoint
577 */
578static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
579{
580 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
581
582 nfs_show_mount_options(m, nfss, 0);
583
Chuck Lever5d8515c2007-12-10 14:57:16 -0500584 seq_printf(m, ",addr=%s",
585 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
586 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400587
588 return 0;
589}
590
591/*
592 * Present statistical information for this VFS mountpoint
593 */
594static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
595{
596 int i, cpu;
597 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
598 struct rpc_auth *auth = nfss->client->cl_auth;
599 struct nfs_iostats totals = { };
600
601 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
602
603 /*
604 * Display all mount option settings
605 */
606 seq_printf(m, "\n\topts:\t");
607 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
608 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
609 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
610 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
611 nfs_show_mount_options(m, nfss, 1);
612
613 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
614
615 seq_printf(m, "\n\tcaps:\t");
616 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400617 seq_printf(m, ",wtmult=%u", nfss->wtmult);
618 seq_printf(m, ",dtsize=%u", nfss->dtsize);
619 seq_printf(m, ",bsize=%u", nfss->bsize);
620 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400621
622#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500623 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400624 seq_printf(m, "\n\tnfsv4:\t");
625 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
626 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
627 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
628 }
629#endif
630
631 /*
632 * Display security flavor in effect for this mount
633 */
Chuck Lever2d767432008-03-14 14:10:08 -0400634 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400635 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400636 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400637
638 /*
639 * Display superblock I/O counters
640 */
641 for_each_possible_cpu(cpu) {
642 struct nfs_iostats *stats;
643
644 preempt_disable();
645 stats = per_cpu_ptr(nfss->io_stats, cpu);
646
647 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
648 totals.events[i] += stats->events[i];
649 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
650 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100651#ifdef CONFIG_NFS_FSCACHE
652 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
653 totals.fscache[i] += stats->fscache[i];
654#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400655
656 preempt_enable();
657 }
658
659 seq_printf(m, "\n\tevents:\t");
660 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
661 seq_printf(m, "%lu ", totals.events[i]);
662 seq_printf(m, "\n\tbytes:\t");
663 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
664 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100665#ifdef CONFIG_NFS_FSCACHE
666 if (nfss->options & NFS_OPTION_FSCACHE) {
667 seq_printf(m, "\n\tfsc:\t");
668 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
669 seq_printf(m, "%Lu ", totals.bytes[i]);
670 }
671#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400672 seq_printf(m, "\n");
673
674 rpc_print_iostats(m, nfss->client);
675
676 return 0;
677}
678
679/*
680 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400681 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400682 */
Al Viro42faad92008-04-24 07:21:56 -0400683static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400684{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200685 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400686 struct rpc_clnt *rpc;
687
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200688 lock_kernel();
689
690 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400691 /* -EIO all pending I/O */
692 rpc = server->client_acl;
693 if (!IS_ERR(rpc))
694 rpc_killall_tasks(rpc);
695 rpc = server->client;
696 if (!IS_ERR(rpc))
697 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200698
699 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400700}
701
702/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500703 * Sanity-check a server address provided by the mount command.
704 *
705 * Address family must be initialized, and address must not be
706 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400707 */
708static int nfs_verify_server_address(struct sockaddr *addr)
709{
710 switch (addr->sa_family) {
711 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500712 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700713 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500714 }
715 case AF_INET6: {
716 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
717 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400718 }
719 }
720
721 return 0;
722}
723
Chuck Leverce3b7e12008-06-23 12:36:53 -0400724static void nfs_parse_ipv4_address(char *string, size_t str_len,
725 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500726{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400727 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
728 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500729
Chuck Leverce3b7e12008-06-23 12:36:53 -0400730 if (str_len <= INET_ADDRSTRLEN) {
731 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
732 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500733
Chuck Leverce3b7e12008-06-23 12:36:53 -0400734 sin->sin_family = AF_INET;
735 *addr_len = sizeof(*sin);
736 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500737 return;
738 }
Chuck Lever9412b922007-12-10 14:59:21 -0500739
740 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400741 *addr_len = 0;
742}
743
744#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400745static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
746 const char *delim,
747 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400748{
749 char *p;
750 size_t len;
751
Chuck Lever5e2e7722008-10-08 15:38:10 -0400752 if ((string + str_len) == delim)
753 return 1;
754
Chuck Leverd8e77482008-06-23 12:37:01 -0400755 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400756 return 0;
757
758 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
759 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400760
761 len = (string + str_len) - delim - 1;
762 p = kstrndup(delim + 1, len, GFP_KERNEL);
763 if (p) {
764 unsigned long scope_id = 0;
765 struct net_device *dev;
766
767 dev = dev_get_by_name(&init_net, p);
768 if (dev != NULL) {
769 scope_id = dev->ifindex;
770 dev_put(dev);
771 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400772 if (strict_strtoul(p, 10, &scope_id) == 0) {
773 kfree(p);
774 return 0;
775 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400776 }
777
778 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400779
Chuck Leverd8e77482008-06-23 12:37:01 -0400780 sin6->sin6_scope_id = scope_id;
781 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400782 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400783 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400784
785 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400786}
787
Chuck Leverce3b7e12008-06-23 12:36:53 -0400788static void nfs_parse_ipv6_address(char *string, size_t str_len,
789 struct sockaddr *sap, size_t *addr_len)
790{
791 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
792 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400793 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400794
795 if (str_len <= INET6_ADDRSTRLEN) {
796 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
797 (int)str_len, string);
798
799 sin6->sin6_family = AF_INET6;
800 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400801 if (in6_pton(string, str_len, addr,
802 IPV6_SCOPE_DELIMITER, &delim) != 0) {
803 if (nfs_parse_ipv6_scope_id(string, str_len,
804 delim, sin6) != 0)
805 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400806 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400807 }
808
809 sap->sa_family = AF_UNSPEC;
810 *addr_len = 0;
811}
812#else
813static void nfs_parse_ipv6_address(char *string, size_t str_len,
814 struct sockaddr *sap, size_t *addr_len)
815{
816 sap->sa_family = AF_UNSPEC;
817 *addr_len = 0;
818}
819#endif
820
821/*
822 * Construct a sockaddr based on the contents of a string that contains
823 * an IP address in presentation format.
824 *
825 * If there is a problem constructing the new sockaddr, set the address
826 * family to AF_UNSPEC.
827 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400828void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400829 struct sockaddr *sap, size_t *addr_len)
830{
831 unsigned int i, colons;
832
833 colons = 0;
834 for (i = 0; i < str_len; i++)
835 if (string[i] == ':')
836 colons++;
837
838 if (colons >= 2)
839 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
840 else
841 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500842}
843
844/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400845 * Sanity check the NFS transport protocol.
846 *
847 */
848static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
849{
850 switch (mnt->nfs_server.protocol) {
851 case XPRT_TRANSPORT_UDP:
852 case XPRT_TRANSPORT_TCP:
853 case XPRT_TRANSPORT_RDMA:
854 break;
855 default:
856 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
857 }
858}
859
860/*
861 * For text based NFSv2/v3 mounts, the mount protocol transport default
862 * settings should depend upon the specified NFS transport.
863 */
864static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
865{
866 nfs_validate_transport_protocol(mnt);
867
868 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
869 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
870 return;
871 switch (mnt->nfs_server.protocol) {
872 case XPRT_TRANSPORT_UDP:
873 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
874 break;
875 case XPRT_TRANSPORT_TCP:
876 case XPRT_TRANSPORT_RDMA:
877 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
878 }
879}
880
881/*
Chuck Lever01060c82008-06-24 16:33:38 -0400882 * Parse the value of the 'sec=' option.
883 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400884 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400885 */
886static int nfs_parse_security_flavors(char *value,
887 struct nfs_parsed_mount_data *mnt)
888{
889 substring_t args[MAX_OPT_ARGS];
890
891 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
892
893 switch (match_token(value, nfs_secflavor_tokens, args)) {
894 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400895 mnt->auth_flavor_len = 0;
896 mnt->auth_flavors[0] = RPC_AUTH_NULL;
897 break;
898 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400899 mnt->auth_flavor_len = 0;
900 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
901 break;
902 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
905 break;
906 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400907 mnt->auth_flavor_len = 1;
908 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
909 break;
910 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400911 mnt->auth_flavor_len = 1;
912 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
913 break;
914 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400915 mnt->auth_flavor_len = 1;
916 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
917 break;
918 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400919 mnt->auth_flavor_len = 1;
920 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
921 break;
922 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400923 mnt->auth_flavor_len = 1;
924 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
925 break;
926 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400927 mnt->auth_flavor_len = 1;
928 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
929 break;
930 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400931 mnt->auth_flavor_len = 1;
932 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
933 break;
934 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400935 mnt->auth_flavor_len = 1;
936 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
937 break;
938 default:
939 return 0;
940 }
941
942 return 1;
943}
944
945/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400946 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400947 * a data structure. The whole mount string is processed; bad options are
948 * skipped as they are encountered. If there were no errors, return 1;
949 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950 */
951static int nfs_parse_mount_options(char *raw,
952 struct nfs_parsed_mount_data *mnt)
953{
Eric Parisf9c3a382008-03-05 14:20:18 -0500954 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700955 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400956
957 if (!raw) {
958 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
959 return 1;
960 }
961 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
962
Eric Parisf9c3a382008-03-05 14:20:18 -0500963 secdata = alloc_secdata();
964 if (!secdata)
965 goto out_nomem;
966
967 rc = security_sb_copy_data(raw, secdata);
968 if (rc)
969 goto out_security_failure;
970
971 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
972 if (rc)
973 goto out_security_failure;
974
975 free_secdata(secdata);
976
Chuck Leverbf0fd762007-07-01 12:13:44 -0400977 while ((p = strsep(&raw, ",")) != NULL) {
978 substring_t args[MAX_OPT_ARGS];
979 int option, token;
980
981 if (!*p)
982 continue;
983
984 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
985
986 token = match_token(p, nfs_mount_option_tokens, args);
987 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400988
989 /*
990 * boolean options: foo/nofoo
991 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400992 case Opt_soft:
993 mnt->flags |= NFS_MOUNT_SOFT;
994 break;
995 case Opt_hard:
996 mnt->flags &= ~NFS_MOUNT_SOFT;
997 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400998 case Opt_posix:
999 mnt->flags |= NFS_MOUNT_POSIX;
1000 break;
1001 case Opt_noposix:
1002 mnt->flags &= ~NFS_MOUNT_POSIX;
1003 break;
1004 case Opt_cto:
1005 mnt->flags &= ~NFS_MOUNT_NOCTO;
1006 break;
1007 case Opt_nocto:
1008 mnt->flags |= NFS_MOUNT_NOCTO;
1009 break;
1010 case Opt_ac:
1011 mnt->flags &= ~NFS_MOUNT_NOAC;
1012 break;
1013 case Opt_noac:
1014 mnt->flags |= NFS_MOUNT_NOAC;
1015 break;
1016 case Opt_lock:
1017 mnt->flags &= ~NFS_MOUNT_NONLM;
1018 break;
1019 case Opt_nolock:
1020 mnt->flags |= NFS_MOUNT_NONLM;
1021 break;
1022 case Opt_v2:
1023 mnt->flags &= ~NFS_MOUNT_VER3;
1024 break;
1025 case Opt_v3:
1026 mnt->flags |= NFS_MOUNT_VER3;
1027 break;
1028 case Opt_udp:
1029 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001030 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001031 break;
1032 case Opt_tcp:
1033 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001034 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001035 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001036 case Opt_rdma:
1037 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1038 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001039 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001040 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001041 case Opt_acl:
1042 mnt->flags &= ~NFS_MOUNT_NOACL;
1043 break;
1044 case Opt_noacl:
1045 mnt->flags |= NFS_MOUNT_NOACL;
1046 break;
1047 case Opt_rdirplus:
1048 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1049 break;
1050 case Opt_nordirplus:
1051 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1052 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001053 case Opt_sharecache:
1054 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1055 break;
1056 case Opt_nosharecache:
1057 mnt->flags |= NFS_MOUNT_UNSHARED;
1058 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001059 case Opt_resvport:
1060 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1061 break;
1062 case Opt_noresvport:
1063 mnt->flags |= NFS_MOUNT_NORESVPORT;
1064 break;
David Howellsb797cac2009-04-03 16:42:48 +01001065 case Opt_fscache:
1066 mnt->options |= NFS_OPTION_FSCACHE;
1067 kfree(mnt->fscache_uniq);
1068 mnt->fscache_uniq = NULL;
1069 break;
1070 case Opt_nofscache:
1071 mnt->options &= ~NFS_OPTION_FSCACHE;
1072 kfree(mnt->fscache_uniq);
1073 mnt->fscache_uniq = NULL;
1074 break;
1075 case Opt_fscache_uniq:
1076 string = match_strdup(args);
1077 if (!string)
1078 goto out_nomem;
1079 kfree(mnt->fscache_uniq);
1080 mnt->fscache_uniq = string;
1081 mnt->options |= NFS_OPTION_FSCACHE;
1082 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001083
Chuck Leverf45663c2008-06-24 19:28:02 -04001084 /*
1085 * options that take numeric values
1086 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001087 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001088 if (match_int(args, &option) ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001089 option < 0 || option > USHORT_MAX)
1090 goto out_invalid_value;
1091 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001092 break;
1093 case Opt_rsize:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001094 if (match_int(args, &option) || option < 0)
1095 goto out_invalid_value;
1096 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001097 break;
1098 case Opt_wsize:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001099 if (match_int(args, &option) || option < 0)
1100 goto out_invalid_value;
1101 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001102 break;
1103 case Opt_bsize:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001104 if (match_int(args, &option) || option < 0)
1105 goto out_invalid_value;
1106 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001107 break;
1108 case Opt_timeo:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001109 if (match_int(args, &option) || option <= 0)
1110 goto out_invalid_value;
1111 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001112 break;
1113 case Opt_retrans:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001114 if (match_int(args, &option) || option <= 0)
1115 goto out_invalid_value;
1116 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001117 break;
1118 case Opt_acregmin:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001119 if (match_int(args, &option) || option < 0)
1120 goto out_invalid_value;
1121 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 break;
1123 case Opt_acregmax:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001124 if (match_int(args, &option) || option < 0)
1125 goto out_invalid_value;
1126 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001127 break;
1128 case Opt_acdirmin:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001129 if (match_int(args, &option) || option < 0)
1130 goto out_invalid_value;
1131 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001132 break;
1133 case Opt_acdirmax:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001134 if (match_int(args, &option) || option < 0)
1135 goto out_invalid_value;
1136 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001137 break;
1138 case Opt_actimeo:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001139 if (match_int(args, &option) || option < 0)
1140 goto out_invalid_value;
1141 mnt->acregmin = mnt->acregmax =
1142 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001143 break;
1144 case Opt_namelen:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001145 if (match_int(args, &option) || option < 0)
1146 goto out_invalid_value;
1147 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001148 break;
1149 case Opt_mountport:
Chuck Leverf45663c2008-06-24 19:28:02 -04001150 if (match_int(args, &option) ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001151 option < 0 || option > USHORT_MAX)
1152 goto out_invalid_value;
1153 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001154 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001155 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001156 if (match_int(args, &option) ||
1157 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001158 option > NFS_MNT3_VERSION)
1159 goto out_invalid_value;
1160 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001161 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001162 case Opt_nfsvers:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001163 if (match_int(args, &option))
1164 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001166 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001167 mnt->flags &= ~NFS_MOUNT_VER3;
1168 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001169 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 mnt->flags |= NFS_MOUNT_VER3;
1171 break;
1172 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001173 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001174 }
1175 break;
1176
Chuck Leverf45663c2008-06-24 19:28:02 -04001177 /*
1178 * options that take text values
1179 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 case Opt_sec:
1181 string = match_strdup(args);
1182 if (string == NULL)
1183 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001184 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001185 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001186 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001187 dfprintk(MOUNT, "NFS: unrecognized "
1188 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001189 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001190 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001191 break;
1192 case Opt_proto:
1193 string = match_strdup(args);
1194 if (string == NULL)
1195 goto out_nomem;
1196 token = match_token(string,
1197 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001198
1199 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001200 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001202 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001203 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001205 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001207 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001208 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001210 case Opt_xprt_rdma:
1211 /* vector side protocols to TCP */
1212 mnt->flags |= NFS_MOUNT_TCP;
1213 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001214 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001215 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001216 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001217 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001218 dfprintk(MOUNT, "NFS: unrecognized "
1219 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001220 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001221 }
1222 break;
1223 case Opt_mountproto:
1224 string = match_strdup(args);
1225 if (string == NULL)
1226 goto out_nomem;
1227 token = match_token(string,
1228 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001229 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230
1231 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001232 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001233 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001235 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001236 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001237 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001238 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001239 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001240 dfprintk(MOUNT, "NFS: unrecognized "
1241 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001242 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001243 }
1244 break;
1245 case Opt_addr:
1246 string = match_strdup(args);
1247 if (string == NULL)
1248 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001249 nfs_parse_ip_address(string, strlen(string),
1250 (struct sockaddr *)
1251 &mnt->nfs_server.address,
1252 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001253 kfree(string);
1254 break;
1255 case Opt_clientaddr:
1256 string = match_strdup(args);
1257 if (string == NULL)
1258 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001259 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 mnt->client_address = string;
1261 break;
Chuck Lever33832032007-12-10 14:59:13 -05001262 case Opt_mounthost:
1263 string = match_strdup(args);
1264 if (string == NULL)
1265 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001266 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001267 mnt->mount_server.hostname = string;
1268 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001269 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 string = match_strdup(args);
1271 if (string == NULL)
1272 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001273 nfs_parse_ip_address(string, strlen(string),
1274 (struct sockaddr *)
1275 &mnt->mount_server.address,
1276 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 kfree(string);
1278 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001279 case Opt_lookupcache:
1280 string = match_strdup(args);
1281 if (string == NULL)
1282 goto out_nomem;
1283 token = match_token(string,
1284 nfs_lookupcache_tokens, args);
1285 kfree(string);
1286 switch (token) {
1287 case Opt_lookupcache_all:
1288 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1289 break;
1290 case Opt_lookupcache_positive:
1291 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1292 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1293 break;
1294 case Opt_lookupcache_none:
1295 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1296 break;
1297 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001298 dfprintk(MOUNT, "NFS: invalid "
1299 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001300 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001301 };
1302 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001303
Chuck Leverf45663c2008-06-24 19:28:02 -04001304 /*
1305 * Special options
1306 */
1307 case Opt_sloppy:
1308 sloppy = 1;
1309 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1310 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 case Opt_userspace:
1312 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001313 dfprintk(MOUNT, "NFS: ignoring mount option "
1314 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 break;
1316
1317 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001318 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001319 dfprintk(MOUNT, "NFS: unrecognized mount option "
1320 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 }
1322 }
1323
Chuck Leverd23c45f2009-06-17 18:02:13 -07001324 if (!sloppy && invalid_option)
1325 return 0;
1326
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 return 1;
1328
Chuck Leverd23c45f2009-06-17 18:02:13 -07001329out_invalid_value:
1330 printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p);
1331 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332out_nomem:
1333 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1334 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001335out_security_failure:
1336 free_secdata(secdata);
1337 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1338 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339}
1340
1341/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001342 * Use the remote server's MOUNT service to request the NFS file handle
1343 * corresponding to the provided path.
1344 */
1345static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1346 struct nfs_fh *root_fh)
1347{
Chuck Lever8e02f6b2009-06-17 18:02:13 -07001348 unsigned int auth_flavor_len = 0;
Chuck Leverc5d120f2008-12-23 15:21:35 -05001349 struct nfs_mount_request request = {
1350 .sap = (struct sockaddr *)
1351 &args->mount_server.address,
1352 .dirpath = args->nfs_server.export_path,
1353 .protocol = args->mount_server.protocol,
1354 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001355 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Lever8e02f6b2009-06-17 18:02:13 -07001356 .auth_flav_len = &auth_flavor_len,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001357 };
Chuck Lever4c568012007-12-10 14:59:28 -05001358 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001359
1360 if (args->mount_server.version == 0) {
1361 if (args->flags & NFS_MOUNT_VER3)
1362 args->mount_server.version = NFS_MNT3_VERSION;
1363 else
1364 args->mount_server.version = NFS_MNT_VERSION;
1365 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001366 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001367
Chuck Lever33832032007-12-10 14:59:13 -05001368 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001369 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001370 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001371 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001372
Chuck Lever0076d7b2007-07-01 12:13:49 -04001373 /*
1374 * Construct the mount server's address.
1375 */
Chuck Lever4c568012007-12-10 14:59:28 -05001376 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001377 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001378 args->nfs_server.addrlen);
1379 args->mount_server.addrlen = args->nfs_server.addrlen;
1380 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001381 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001382
James Lentiniaad70002007-09-24 17:32:49 -04001383 /*
1384 * autobind will be used if mount_server.port == 0
1385 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001386 nfs_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001387
1388 /*
1389 * Now ask the mount server to map our export path
1390 * to a file handle.
1391 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001392 status = nfs_mount(&request);
Chuck Leverefd83402007-09-11 18:00:58 -04001393 if (status == 0)
1394 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001395
Chuck Lever396cee972008-06-12 12:37:49 -04001396 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Leverc5d120f2008-12-23 15:21:35 -05001397 request.hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001398 return status;
1399}
1400
Chuck Leverd1aa0822008-06-23 12:36:45 -04001401static int nfs_parse_simple_hostname(const char *dev_name,
1402 char **hostname, size_t maxnamlen,
1403 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001404{
1405 size_t len;
1406 char *colon, *comma;
1407
1408 colon = strchr(dev_name, ':');
1409 if (colon == NULL)
1410 goto out_bad_devname;
1411
1412 len = colon - dev_name;
1413 if (len > maxnamlen)
1414 goto out_hostname;
1415
1416 /* N.B. caller will free nfs_server.hostname in all cases */
1417 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1418 if (!*hostname)
1419 goto out_nomem;
1420
1421 /* kill possible hostname list: not supported */
1422 comma = strchr(*hostname, ',');
1423 if (comma != NULL) {
1424 if (comma == *hostname)
1425 goto out_bad_devname;
1426 *comma = '\0';
1427 }
1428
1429 colon++;
1430 len = strlen(colon);
1431 if (len > maxpathlen)
1432 goto out_path;
1433 *export_path = kstrndup(colon, len, GFP_KERNEL);
1434 if (!*export_path)
1435 goto out_nomem;
1436
1437 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1438 return 0;
1439
1440out_bad_devname:
1441 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1442 return -EINVAL;
1443
1444out_nomem:
1445 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1446 return -ENOMEM;
1447
1448out_hostname:
1449 dfprintk(MOUNT, "NFS: server hostname too long\n");
1450 return -ENAMETOOLONG;
1451
1452out_path:
1453 dfprintk(MOUNT, "NFS: export pathname too long\n");
1454 return -ENAMETOOLONG;
1455}
1456
1457/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001458 * Hostname has square brackets around it because it contains one or
1459 * more colons. We look for the first closing square bracket, and a
1460 * colon must follow it.
1461 */
1462static int nfs_parse_protected_hostname(const char *dev_name,
1463 char **hostname, size_t maxnamlen,
1464 char **export_path, size_t maxpathlen)
1465{
1466 size_t len;
1467 char *start, *end;
1468
1469 start = (char *)(dev_name + 1);
1470
1471 end = strchr(start, ']');
1472 if (end == NULL)
1473 goto out_bad_devname;
1474 if (*(end + 1) != ':')
1475 goto out_bad_devname;
1476
1477 len = end - start;
1478 if (len > maxnamlen)
1479 goto out_hostname;
1480
1481 /* N.B. caller will free nfs_server.hostname in all cases */
1482 *hostname = kstrndup(start, len, GFP_KERNEL);
1483 if (*hostname == NULL)
1484 goto out_nomem;
1485
1486 end += 2;
1487 len = strlen(end);
1488 if (len > maxpathlen)
1489 goto out_path;
1490 *export_path = kstrndup(end, len, GFP_KERNEL);
1491 if (!*export_path)
1492 goto out_nomem;
1493
1494 return 0;
1495
1496out_bad_devname:
1497 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1498 return -EINVAL;
1499
1500out_nomem:
1501 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1502 return -ENOMEM;
1503
1504out_hostname:
1505 dfprintk(MOUNT, "NFS: server hostname too long\n");
1506 return -ENAMETOOLONG;
1507
1508out_path:
1509 dfprintk(MOUNT, "NFS: export pathname too long\n");
1510 return -ENAMETOOLONG;
1511}
1512
1513/*
1514 * Split "dev_name" into "hostname:export_path".
1515 *
1516 * The leftmost colon demarks the split between the server's hostname
1517 * and the export path. If the hostname starts with a left square
1518 * bracket, then it may contain colons.
1519 *
1520 * Note: caller frees hostname and export path, even on error.
1521 */
1522static int nfs_parse_devname(const char *dev_name,
1523 char **hostname, size_t maxnamlen,
1524 char **export_path, size_t maxpathlen)
1525{
1526 if (*dev_name == '[')
1527 return nfs_parse_protected_hostname(dev_name,
1528 hostname, maxnamlen,
1529 export_path, maxpathlen);
1530
1531 return nfs_parse_simple_hostname(dev_name,
1532 hostname, maxnamlen,
1533 export_path, maxpathlen);
1534}
1535
1536/*
David Howells54ceac42006-08-22 20:06:13 -04001537 * Validate the NFS2/NFS3 mount data
1538 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001539 *
1540 * For option strings, user space handles the following behaviors:
1541 *
1542 * + DNS: mapping server host name to IP address ("addr=" option)
1543 *
1544 * + failure mode: how to behave if a mount request can't be handled
1545 * immediately ("fg/bg" option)
1546 *
1547 * + retry: how often to retry a mount request ("retry=" option)
1548 *
1549 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1550 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001551 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001552static int nfs_validate_mount_data(void *options,
1553 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001554 struct nfs_fh *mntfh,
1555 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001556{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001557 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001558
Chuck Lever5df36e72007-07-01 12:12:56 -04001559 if (data == NULL)
1560 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001561
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001562 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1563 args->rsize = NFS_MAX_FILE_IO_SIZE;
1564 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001565 args->acregmin = NFS_DEF_ACREGMIN;
1566 args->acregmax = NFS_DEF_ACREGMAX;
1567 args->acdirmin = NFS_DEF_ACDIRMIN;
1568 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001569 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001570 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001571 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001572 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001573
David Howellsf7b422b2006-06-09 09:34:33 -04001574 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001575 case 1:
1576 data->namlen = 0;
1577 case 2:
1578 data->bsize = 0;
1579 case 3:
1580 if (data->flags & NFS_MOUNT_VER3)
1581 goto out_no_v3;
1582 data->root.size = NFS2_FHSIZE;
1583 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1584 case 4:
1585 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1586 goto out_no_sec;
1587 case 5:
1588 memset(data->context, 0, sizeof(data->context));
1589 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001590 if (data->flags & NFS_MOUNT_VER3) {
1591 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1592 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001593 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001594 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001595 mntfh->size = NFS2_FHSIZE;
1596
Chuck Lever5df36e72007-07-01 12:12:56 -04001597
1598 memcpy(mntfh->data, data->root.data, mntfh->size);
1599 if (mntfh->size < sizeof(mntfh->data))
1600 memset(mntfh->data + mntfh->size, 0,
1601 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001602
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001603 /*
1604 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1605 * can deal with.
1606 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001607 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001608 args->rsize = data->rsize;
1609 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001610 args->timeo = data->timeo;
1611 args->retrans = data->retrans;
1612 args->acregmin = data->acregmin;
1613 args->acregmax = data->acregmax;
1614 args->acdirmin = data->acdirmin;
1615 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001616
1617 memcpy(&args->nfs_server.address, &data->addr,
1618 sizeof(data->addr));
1619 args->nfs_server.addrlen = sizeof(data->addr);
1620 if (!nfs_verify_server_address((struct sockaddr *)
1621 &args->nfs_server.address))
1622 goto out_no_address;
1623
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001624 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001625 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001626 /* N.B. caller will free nfs_server.hostname in all cases */
1627 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1628 args->namlen = data->namlen;
1629 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001630
1631 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1632 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001633 if (!args->nfs_server.hostname)
1634 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001635
1636 /*
1637 * The legacy version 6 binary mount data from userspace has a
1638 * field used only to transport selinux information into the
1639 * the kernel. To continue to support that functionality we
1640 * have a touch of selinux knowledge here in the NFS code. The
1641 * userspace code converted context=blah to just blah so we are
1642 * converting back to the full string selinux understands.
1643 */
1644 if (data->context[0]){
1645#ifdef CONFIG_SECURITY_SELINUX
1646 int rc;
1647 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1648 if (!opts_str)
1649 return -ENOMEM;
1650 strcpy(opts_str, "context=");
1651 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1652 strcat(opts_str, &data->context[0]);
1653 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1654 kfree(opts_str);
1655 if (rc)
1656 return rc;
1657#else
1658 return -EINVAL;
1659#endif
1660 }
1661
Chuck Lever5df36e72007-07-01 12:12:56 -04001662 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001663 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001664 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001665
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001666 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001667 return -EINVAL;
1668
Chuck Lever6e88e062007-09-24 15:39:50 -04001669 if (!nfs_verify_server_address((struct sockaddr *)
1670 &args->nfs_server.address))
1671 goto out_no_address;
1672
Chuck Levered596a82008-06-26 17:47:05 -04001673 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1674 args->nfs_server.port);
1675
Trond Myklebust259875e2008-07-02 14:43:47 -04001676 nfs_set_mount_transport_protocol(args);
1677
Chuck Leverdc045892008-06-23 12:36:37 -04001678 status = nfs_parse_devname(dev_name,
1679 &args->nfs_server.hostname,
1680 PAGE_SIZE,
1681 &args->nfs_server.export_path,
1682 NFS_MAXPATHLEN);
1683 if (!status)
1684 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001685
Chuck Leverdc045892008-06-23 12:36:37 -04001686 kfree(args->nfs_server.export_path);
1687 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001688
Chuck Lever136d5582007-07-01 12:13:54 -04001689 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001690 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001691
Chuck Lever136d5582007-07-01 12:13:54 -04001692 break;
1693 }
David Howellsf7b422b2006-06-09 09:34:33 -04001694 }
David Howells54ceac42006-08-22 20:06:13 -04001695
David Howellsf7b422b2006-06-09 09:34:33 -04001696#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001697 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001698 goto out_v3_not_compiled;
1699#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001700
David Howells54ceac42006-08-22 20:06:13 -04001701 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001702
1703out_no_data:
1704 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1705 return -EINVAL;
1706
1707out_no_v3:
1708 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1709 data->version);
1710 return -EINVAL;
1711
1712out_no_sec:
1713 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1714 return -EINVAL;
1715
Chuck Lever5df36e72007-07-01 12:12:56 -04001716#ifndef CONFIG_NFS_V3
1717out_v3_not_compiled:
1718 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1719 return -EPROTONOSUPPORT;
1720#endif /* !CONFIG_NFS_V3 */
1721
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001722out_nomem:
1723 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1724 return -ENOMEM;
1725
Chuck Lever5df36e72007-07-01 12:12:56 -04001726out_no_address:
1727 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1728 return -EINVAL;
1729
1730out_invalid_fh:
1731 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1732 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001733}
1734
Jeff Layton48b605f2008-06-10 15:38:39 -04001735static int
1736nfs_compare_remount_data(struct nfs_server *nfss,
1737 struct nfs_parsed_mount_data *data)
1738{
1739 if (data->flags != nfss->flags ||
1740 data->rsize != nfss->rsize ||
1741 data->wsize != nfss->wsize ||
1742 data->retrans != nfss->client->cl_timeout->to_retries ||
1743 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1744 data->acregmin != nfss->acregmin / HZ ||
1745 data->acregmax != nfss->acregmax / HZ ||
1746 data->acdirmin != nfss->acdirmin / HZ ||
1747 data->acdirmax != nfss->acdirmax / HZ ||
1748 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1749 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1750 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1751 data->nfs_server.addrlen) != 0)
1752 return -EINVAL;
1753
1754 return 0;
1755}
1756
1757static int
1758nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1759{
1760 int error;
1761 struct nfs_server *nfss = sb->s_fs_info;
1762 struct nfs_parsed_mount_data *data;
1763 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1764 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001765 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001766
1767 /*
1768 * Userspace mount programs that send binary options generally send
1769 * them populated with default values. We have no way to know which
1770 * ones were explicitly specified. Fall back to legacy behavior and
1771 * just return success.
1772 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001773 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1774 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1775 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001776 return 0;
1777
1778 data = kzalloc(sizeof(*data), GFP_KERNEL);
1779 if (data == NULL)
1780 return -ENOMEM;
1781
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001782 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001783 /* fill out struct with values from existing mount */
1784 data->flags = nfss->flags;
1785 data->rsize = nfss->rsize;
1786 data->wsize = nfss->wsize;
1787 data->retrans = nfss->client->cl_timeout->to_retries;
1788 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1789 data->acregmin = nfss->acregmin / HZ;
1790 data->acregmax = nfss->acregmax / HZ;
1791 data->acdirmin = nfss->acdirmin / HZ;
1792 data->acdirmax = nfss->acdirmax / HZ;
1793 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1794 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1795 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1796 data->nfs_server.addrlen);
1797
1798 /* overwrite those values with any that were specified */
1799 error = nfs_parse_mount_options((char *)options, data);
1800 if (error < 0)
1801 goto out;
1802
1803 /* compare new mount options with old ones */
1804 error = nfs_compare_remount_data(nfss, data);
1805out:
1806 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001807 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001808 return error;
1809}
1810
David Howells54ceac42006-08-22 20:06:13 -04001811/*
1812 * Initialise the common bits of the superblock
1813 */
1814static inline void nfs_initialise_sb(struct super_block *sb)
1815{
1816 struct nfs_server *server = NFS_SB(sb);
1817
1818 sb->s_magic = NFS_SUPER_MAGIC;
1819
1820 /* We probably want something more informative here */
1821 snprintf(sb->s_id, sizeof(sb->s_id),
1822 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1823
1824 if (sb->s_blocksize == 0)
1825 sb->s_blocksize = nfs_block_bits(server->wsize,
1826 &sb->s_blocksize_bits);
1827
1828 if (server->flags & NFS_MOUNT_NOAC)
1829 sb->s_flags |= MS_SYNCHRONOUS;
1830
1831 nfs_super_set_maxbytes(sb, server->maxfilesize);
1832}
1833
1834/*
1835 * Finish setting up an NFS2/3 superblock
1836 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001837static void nfs_fill_super(struct super_block *sb,
1838 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001839{
1840 struct nfs_server *server = NFS_SB(sb);
1841
1842 sb->s_blocksize_bits = 0;
1843 sb->s_blocksize = 0;
1844 if (data->bsize)
1845 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1846
1847 if (server->flags & NFS_MOUNT_VER3) {
1848 /* The VFS shouldn't apply the umask to mode bits. We will do
1849 * so ourselves when necessary.
1850 */
1851 sb->s_flags |= MS_POSIXACL;
1852 sb->s_time_gran = 1;
1853 }
1854
1855 sb->s_op = &nfs_sops;
1856 nfs_initialise_sb(sb);
1857}
1858
1859/*
1860 * Finish setting up a cloned NFS2/3 superblock
1861 */
1862static void nfs_clone_super(struct super_block *sb,
1863 const struct super_block *old_sb)
1864{
1865 struct nfs_server *server = NFS_SB(sb);
1866
1867 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1868 sb->s_blocksize = old_sb->s_blocksize;
1869 sb->s_maxbytes = old_sb->s_maxbytes;
1870
1871 if (server->flags & NFS_MOUNT_VER3) {
1872 /* The VFS shouldn't apply the umask to mode bits. We will do
1873 * so ourselves when necessary.
1874 */
1875 sb->s_flags |= MS_POSIXACL;
1876 sb->s_time_gran = 1;
1877 }
1878
1879 sb->s_op = old_sb->s_op;
1880 nfs_initialise_sb(sb);
1881}
1882
Trond Myklebust275a5d22007-05-16 16:53:28 -04001883static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1884{
1885 const struct nfs_server *a = s->s_fs_info;
1886 const struct rpc_clnt *clnt_a = a->client;
1887 const struct rpc_clnt *clnt_b = b->client;
1888
1889 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1890 goto Ebusy;
1891 if (a->nfs_client != b->nfs_client)
1892 goto Ebusy;
1893 if (a->flags != b->flags)
1894 goto Ebusy;
1895 if (a->wsize != b->wsize)
1896 goto Ebusy;
1897 if (a->rsize != b->rsize)
1898 goto Ebusy;
1899 if (a->acregmin != b->acregmin)
1900 goto Ebusy;
1901 if (a->acregmax != b->acregmax)
1902 goto Ebusy;
1903 if (a->acdirmin != b->acdirmin)
1904 goto Ebusy;
1905 if (a->acdirmax != b->acdirmax)
1906 goto Ebusy;
1907 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1908 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001909 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001910Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001911 return 0;
1912}
1913
1914struct nfs_sb_mountdata {
1915 struct nfs_server *server;
1916 int mntflags;
1917};
1918
1919static int nfs_set_super(struct super_block *s, void *data)
1920{
1921 struct nfs_sb_mountdata *sb_mntdata = data;
1922 struct nfs_server *server = sb_mntdata->server;
1923 int ret;
1924
1925 s->s_flags = sb_mntdata->mntflags;
1926 s->s_fs_info = server;
1927 ret = set_anon_super(s, server);
1928 if (ret == 0)
1929 server->s_dev = s->s_dev;
1930 return ret;
1931}
1932
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001933static int nfs_compare_super_address(struct nfs_server *server1,
1934 struct nfs_server *server2)
1935{
1936 struct sockaddr *sap1, *sap2;
1937
1938 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1939 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1940
1941 if (sap1->sa_family != sap2->sa_family)
1942 return 0;
1943
1944 switch (sap1->sa_family) {
1945 case AF_INET: {
1946 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1947 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1948 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1949 return 0;
1950 if (sin1->sin_port != sin2->sin_port)
1951 return 0;
1952 break;
1953 }
1954 case AF_INET6: {
1955 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1956 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1957 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1958 return 0;
1959 if (sin1->sin6_port != sin2->sin6_port)
1960 return 0;
1961 break;
1962 }
1963 default:
1964 return 0;
1965 }
1966
1967 return 1;
1968}
1969
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001970static int nfs_compare_super(struct super_block *sb, void *data)
1971{
1972 struct nfs_sb_mountdata *sb_mntdata = data;
1973 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1974 int mntflags = sb_mntdata->mntflags;
1975
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001976 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001977 return 0;
1978 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1979 if (old->flags & NFS_MOUNT_UNSHARED)
1980 return 0;
1981 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1982 return 0;
1983 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001984}
1985
Miklos Szeredifa799752008-04-30 00:54:33 -07001986static int nfs_bdi_register(struct nfs_server *server)
1987{
1988 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1989}
1990
David Howells54ceac42006-08-22 20:06:13 -04001991static int nfs_get_sb(struct file_system_type *fs_type,
1992 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1993{
1994 struct nfs_server *server = NULL;
1995 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001996 struct nfs_parsed_mount_data *data;
1997 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001998 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001999 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002000 struct nfs_sb_mountdata sb_mntdata = {
2001 .mntflags = flags,
2002 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002003 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002004
Trond Myklebust33852a12008-06-19 14:20:11 -04002005 data = kzalloc(sizeof(*data), GFP_KERNEL);
2006 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2007 if (data == NULL || mntfh == NULL)
2008 goto out_free_fh;
2009
2010 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002011
David Howells54ceac42006-08-22 20:06:13 -04002012 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002013 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002014 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002015 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002016
2017 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002018 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002019 if (IS_ERR(server)) {
2020 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002021 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002022 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002023 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002024
Trond Myklebust75180df2007-05-16 16:53:28 -04002025 if (server->flags & NFS_MOUNT_UNSHARED)
2026 compare_super = NULL;
2027
David Howells54ceac42006-08-22 20:06:13 -04002028 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002029 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002030 if (IS_ERR(s)) {
2031 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002032 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002033 }
2034
David Howells54ceac42006-08-22 20:06:13 -04002035 if (s->s_fs_info != server) {
2036 nfs_free_server(server);
2037 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002038 } else {
2039 error = nfs_bdi_register(server);
2040 if (error)
2041 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002042 }
David Howells54ceac42006-08-22 20:06:13 -04002043
2044 if (!s->s_root) {
2045 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002046 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002047 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002048 }
2049
Trond Myklebust33852a12008-06-19 14:20:11 -04002050 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002051 if (IS_ERR(mntroot)) {
2052 error = PTR_ERR(mntroot);
2053 goto error_splat_super;
2054 }
2055
Trond Myklebust33852a12008-06-19 14:20:11 -04002056 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002057 if (error)
2058 goto error_splat_root;
2059
David Howellsf7b422b2006-06-09 09:34:33 -04002060 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002061 mnt->mnt_sb = s;
2062 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002063 error = 0;
2064
2065out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002066 kfree(data->nfs_server.hostname);
2067 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002068 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002069 security_free_mnt_opts(&data->lsm_opts);
2070out_free_fh:
2071 kfree(mntfh);
2072 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002073 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002074
David Howells54ceac42006-08-22 20:06:13 -04002075out_err_nosb:
2076 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002077 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002078
Eric Parisf9c3a382008-03-05 14:20:18 -05002079error_splat_root:
2080 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002081error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002082 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002083 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002084}
2085
David Howells54ceac42006-08-22 20:06:13 -04002086/*
2087 * Destroy an NFS2/3 superblock
2088 */
David Howellsf7b422b2006-06-09 09:34:33 -04002089static void nfs_kill_super(struct super_block *s)
2090{
2091 struct nfs_server *server = NFS_SB(s);
2092
Miklos Szeredifa799752008-04-30 00:54:33 -07002093 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002094 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002095 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002096 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002097}
2098
David Howells54ceac42006-08-22 20:06:13 -04002099/*
2100 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2101 */
2102static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2103 const char *dev_name, void *raw_data,
2104 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002105{
2106 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002107 struct super_block *s;
2108 struct nfs_server *server;
2109 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002110 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002111 struct nfs_sb_mountdata sb_mntdata = {
2112 .mntflags = flags,
2113 };
David Howells54ceac42006-08-22 20:06:13 -04002114 int error;
2115
2116 dprintk("--> nfs_xdev_get_sb()\n");
2117
2118 /* create a new volume representation */
2119 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2120 if (IS_ERR(server)) {
2121 error = PTR_ERR(server);
2122 goto out_err_noserver;
2123 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002124 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002125
Trond Myklebust75180df2007-05-16 16:53:28 -04002126 if (server->flags & NFS_MOUNT_UNSHARED)
2127 compare_super = NULL;
2128
David Howells54ceac42006-08-22 20:06:13 -04002129 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002130 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002131 if (IS_ERR(s)) {
2132 error = PTR_ERR(s);
2133 goto out_err_nosb;
2134 }
2135
2136 if (s->s_fs_info != server) {
2137 nfs_free_server(server);
2138 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002139 } else {
2140 error = nfs_bdi_register(server);
2141 if (error)
2142 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002143 }
2144
2145 if (!s->s_root) {
2146 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002147 nfs_clone_super(s, data->sb);
2148 }
2149
2150 mntroot = nfs_get_root(s, data->fh);
2151 if (IS_ERR(mntroot)) {
2152 error = PTR_ERR(mntroot);
2153 goto error_splat_super;
2154 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002155 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002156 dput(mntroot);
2157 error = -ESTALE;
2158 goto error_splat_super;
2159 }
David Howells54ceac42006-08-22 20:06:13 -04002160
2161 s->s_flags |= MS_ACTIVE;
2162 mnt->mnt_sb = s;
2163 mnt->mnt_root = mntroot;
2164
Eric Parisf9c3a382008-03-05 14:20:18 -05002165 /* clone any lsm security options from the parent to the new sb */
2166 security_sb_clone_mnt_opts(data->sb, s);
2167
David Howells54ceac42006-08-22 20:06:13 -04002168 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2169 return 0;
2170
2171out_err_nosb:
2172 nfs_free_server(server);
2173out_err_noserver:
2174 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2175 return error;
2176
2177error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002178 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002179 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2180 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002181}
2182
2183#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002184
2185/*
2186 * Finish setting up a cloned NFS4 superblock
2187 */
2188static void nfs4_clone_super(struct super_block *sb,
2189 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002190{
David Howells54ceac42006-08-22 20:06:13 -04002191 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2192 sb->s_blocksize = old_sb->s_blocksize;
2193 sb->s_maxbytes = old_sb->s_maxbytes;
2194 sb->s_time_gran = 1;
2195 sb->s_op = old_sb->s_op;
2196 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002197}
2198
2199/*
2200 * Set up an NFS4 superblock
2201 */
David Howells54ceac42006-08-22 20:06:13 -04002202static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002203{
David Howellsf7b422b2006-06-09 09:34:33 -04002204 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002205 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002206 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002207}
2208
Trond Myklebust01c3f052009-06-17 13:22:58 -07002209static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2210{
2211 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2212}
2213
David Howells54ceac42006-08-22 20:06:13 -04002214/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002215 * Validate NFSv4 mount options
2216 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002217static int nfs4_validate_mount_data(void *options,
2218 struct nfs_parsed_mount_data *args,
2219 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002220{
Chuck Lever4c568012007-12-10 14:59:28 -05002221 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002222 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002223 char *c;
2224
2225 if (data == NULL)
2226 goto out_no_data;
2227
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002228 args->rsize = NFS_MAX_FILE_IO_SIZE;
2229 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002230 args->acregmin = NFS_DEF_ACREGMIN;
2231 args->acregmax = NFS_DEF_ACREGMAX;
2232 args->acdirmin = NFS_DEF_ACDIRMIN;
2233 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002234 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002235 args->auth_flavors[0] = RPC_AUTH_UNIX;
2236 args->auth_flavor_len = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002237
Chuck Leverf0768eb2007-07-01 12:13:01 -04002238 switch (data->version) {
2239 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002240 ap = (struct sockaddr_in *)&args->nfs_server.address;
2241 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002242 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002243 if (data->host_addrlen == 0)
2244 goto out_no_address;
2245 args->nfs_server.addrlen = data->host_addrlen;
2246 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002247 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002248 if (!nfs_verify_server_address((struct sockaddr *)
2249 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002250 goto out_no_address;
2251
Chuck Lever6738b252008-06-24 16:33:54 -04002252 if (data->auth_flavourlen) {
2253 if (data->auth_flavourlen > 1)
2254 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002255 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002256 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002257 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002258 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002259 }
2260
2261 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2262 if (IS_ERR(c))
2263 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002264 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002265
2266 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2267 if (IS_ERR(c))
2268 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002269 args->nfs_server.export_path = c;
2270 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002271
2272 c = strndup_user(data->client_addr.data, 16);
2273 if (IS_ERR(c))
2274 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002275 args->client_address = c;
2276
2277 /*
2278 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2279 * can deal with.
2280 */
2281
2282 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2283 args->rsize = data->rsize;
2284 args->wsize = data->wsize;
2285 args->timeo = data->timeo;
2286 args->retrans = data->retrans;
2287 args->acregmin = data->acregmin;
2288 args->acregmax = data->acregmax;
2289 args->acdirmin = data->acdirmin;
2290 args->acdirmax = data->acdirmax;
2291 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002292 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002293
2294 break;
Chuck Lever80071222007-07-01 12:13:59 -04002295 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002296 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002297
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002298 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002299 return -EINVAL;
2300
2301 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002302 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002303 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002304
Chuck Levered596a82008-06-26 17:47:05 -04002305 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2306 args->nfs_server.port);
2307
Trond Myklebust259875e2008-07-02 14:43:47 -04002308 nfs_validate_transport_protocol(args);
2309
Trond Myklebust01c3f052009-06-17 13:22:58 -07002310 nfs4_validate_mount_flags(args);
2311
Chuck Lever6738b252008-06-24 16:33:54 -04002312 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002313 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002314
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002315 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002316 goto out_no_client_address;
2317
Chuck Leverdc045892008-06-23 12:36:37 -04002318 status = nfs_parse_devname(dev_name,
2319 &args->nfs_server.hostname,
2320 NFS4_MAXNAMLEN,
2321 &args->nfs_server.export_path,
2322 NFS4_MAXPATHLEN);
2323 if (status < 0)
2324 return status;
2325
Chuck Lever80071222007-07-01 12:13:59 -04002326 break;
2327 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002328 }
2329
2330 return 0;
2331
2332out_no_data:
2333 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2334 return -EINVAL;
2335
2336out_inval_auth:
2337 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2338 data->auth_flavourlen);
2339 return -EINVAL;
2340
2341out_no_address:
2342 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2343 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002344
2345out_no_client_address:
2346 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2347 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002348}
2349
2350/*
David Howells54ceac42006-08-22 20:06:13 -04002351 * Get the superblock for an NFS4 mountpoint
2352 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002353static int nfs4_get_sb(struct file_system_type *fs_type,
2354 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002355{
Trond Myklebust33852a12008-06-19 14:20:11 -04002356 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002357 struct super_block *s;
2358 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002359 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002360 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002361 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002362 struct nfs_sb_mountdata sb_mntdata = {
2363 .mntflags = flags,
2364 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002365 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002366
Trond Myklebust33852a12008-06-19 14:20:11 -04002367 data = kzalloc(sizeof(*data), GFP_KERNEL);
2368 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2369 if (data == NULL || mntfh == NULL)
2370 goto out_free_fh;
2371
2372 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002373
Chuck Leverf0768eb2007-07-01 12:13:01 -04002374 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002375 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002376 if (error < 0)
2377 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002378
David Howells54ceac42006-08-22 20:06:13 -04002379 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002380 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002381 if (IS_ERR(server)) {
2382 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002383 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002384 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002385 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002386
Trond Myklebust75180df2007-05-16 16:53:28 -04002387 if (server->flags & NFS4_MOUNT_UNSHARED)
2388 compare_super = NULL;
2389
David Howells54ceac42006-08-22 20:06:13 -04002390 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002391 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002392 if (IS_ERR(s)) {
2393 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002394 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002395 }
2396
Trond Myklebust5dd31772006-08-24 01:03:05 -04002397 if (s->s_fs_info != server) {
2398 nfs_free_server(server);
2399 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002400 } else {
2401 error = nfs_bdi_register(server);
2402 if (error)
2403 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002404 }
2405
David Howells54ceac42006-08-22 20:06:13 -04002406 if (!s->s_root) {
2407 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002408 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002409 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002410 }
David Howellsf7b422b2006-06-09 09:34:33 -04002411
Trond Myklebust33852a12008-06-19 14:20:11 -04002412 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002413 if (IS_ERR(mntroot)) {
2414 error = PTR_ERR(mntroot);
2415 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002416 }
David Howells54ceac42006-08-22 20:06:13 -04002417
Trond Myklebust33852a12008-06-19 14:20:11 -04002418 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002419 if (error)
2420 goto error_splat_root;
2421
David Howellsf7b422b2006-06-09 09:34:33 -04002422 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002423 mnt->mnt_sb = s;
2424 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002425 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002426
Chuck Lever29eb9812007-07-01 12:12:30 -04002427out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002428 kfree(data->client_address);
2429 kfree(data->nfs_server.export_path);
2430 kfree(data->nfs_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002431 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002432 security_free_mnt_opts(&data->lsm_opts);
2433out_free_fh:
2434 kfree(mntfh);
2435 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002436 return error;
David Howells54ceac42006-08-22 20:06:13 -04002437
Chuck Lever29eb9812007-07-01 12:12:30 -04002438out_free:
2439 nfs_free_server(server);
2440 goto out;
2441
Eric Paris46c8ac72008-05-02 13:42:42 -07002442error_splat_root:
2443 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002444error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002445 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002446 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002447}
2448
2449static void nfs4_kill_super(struct super_block *sb)
2450{
2451 struct nfs_server *server = NFS_SB(sb);
2452
Trond Myklebust515d8612008-12-23 15:21:46 -05002453 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002454 kill_anon_super(sb);
2455
2456 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002457 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002458 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002459}
2460
2461/*
David Howells54ceac42006-08-22 20:06:13 -04002462 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002463 */
David Howells54ceac42006-08-22 20:06:13 -04002464static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2465 const char *dev_name, void *raw_data,
2466 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002467{
2468 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002469 struct super_block *s;
2470 struct nfs_server *server;
2471 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002472 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002473 struct nfs_sb_mountdata sb_mntdata = {
2474 .mntflags = flags,
2475 };
David Howells54ceac42006-08-22 20:06:13 -04002476 int error;
2477
2478 dprintk("--> nfs4_xdev_get_sb()\n");
2479
2480 /* create a new volume representation */
2481 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2482 if (IS_ERR(server)) {
2483 error = PTR_ERR(server);
2484 goto out_err_noserver;
2485 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002486 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002487
Trond Myklebust75180df2007-05-16 16:53:28 -04002488 if (server->flags & NFS4_MOUNT_UNSHARED)
2489 compare_super = NULL;
2490
David Howells54ceac42006-08-22 20:06:13 -04002491 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002492 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002493 if (IS_ERR(s)) {
2494 error = PTR_ERR(s);
2495 goto out_err_nosb;
2496 }
2497
2498 if (s->s_fs_info != server) {
2499 nfs_free_server(server);
2500 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002501 } else {
2502 error = nfs_bdi_register(server);
2503 if (error)
2504 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002505 }
2506
2507 if (!s->s_root) {
2508 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002509 nfs4_clone_super(s, data->sb);
2510 }
2511
2512 mntroot = nfs4_get_root(s, data->fh);
2513 if (IS_ERR(mntroot)) {
2514 error = PTR_ERR(mntroot);
2515 goto error_splat_super;
2516 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002517 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2518 dput(mntroot);
2519 error = -ESTALE;
2520 goto error_splat_super;
2521 }
David Howells54ceac42006-08-22 20:06:13 -04002522
2523 s->s_flags |= MS_ACTIVE;
2524 mnt->mnt_sb = s;
2525 mnt->mnt_root = mntroot;
2526
Eric Paris46c8ac72008-05-02 13:42:42 -07002527 security_sb_clone_mnt_opts(data->sb, s);
2528
David Howells54ceac42006-08-22 20:06:13 -04002529 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2530 return 0;
2531
2532out_err_nosb:
2533 nfs_free_server(server);
2534out_err_noserver:
2535 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2536 return error;
2537
2538error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002539 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002540 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2541 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002542}
2543
David Howells54ceac42006-08-22 20:06:13 -04002544/*
2545 * Create an NFS4 server record on referral traversal
2546 */
2547static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2548 const char *dev_name, void *raw_data,
2549 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002550{
2551 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002552 struct super_block *s;
2553 struct nfs_server *server;
2554 struct dentry *mntroot;
2555 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002556 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002557 struct nfs_sb_mountdata sb_mntdata = {
2558 .mntflags = flags,
2559 };
David Howells54ceac42006-08-22 20:06:13 -04002560 int error;
2561
2562 dprintk("--> nfs4_referral_get_sb()\n");
2563
2564 /* create a new volume representation */
2565 server = nfs4_create_referral_server(data, &mntfh);
2566 if (IS_ERR(server)) {
2567 error = PTR_ERR(server);
2568 goto out_err_noserver;
2569 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002570 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002571
Trond Myklebust75180df2007-05-16 16:53:28 -04002572 if (server->flags & NFS4_MOUNT_UNSHARED)
2573 compare_super = NULL;
2574
David Howells54ceac42006-08-22 20:06:13 -04002575 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002576 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002577 if (IS_ERR(s)) {
2578 error = PTR_ERR(s);
2579 goto out_err_nosb;
2580 }
2581
2582 if (s->s_fs_info != server) {
2583 nfs_free_server(server);
2584 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002585 } else {
2586 error = nfs_bdi_register(server);
2587 if (error)
2588 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002589 }
2590
2591 if (!s->s_root) {
2592 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002593 nfs4_fill_super(s);
2594 }
2595
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002596 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002597 if (IS_ERR(mntroot)) {
2598 error = PTR_ERR(mntroot);
2599 goto error_splat_super;
2600 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002601 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2602 dput(mntroot);
2603 error = -ESTALE;
2604 goto error_splat_super;
2605 }
David Howells54ceac42006-08-22 20:06:13 -04002606
2607 s->s_flags |= MS_ACTIVE;
2608 mnt->mnt_sb = s;
2609 mnt->mnt_root = mntroot;
2610
Eric Paris46c8ac72008-05-02 13:42:42 -07002611 security_sb_clone_mnt_opts(data->sb, s);
2612
David Howells54ceac42006-08-22 20:06:13 -04002613 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2614 return 0;
2615
2616out_err_nosb:
2617 nfs_free_server(server);
2618out_err_noserver:
2619 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2620 return error;
2621
2622error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002623 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002624 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2625 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002626}
2627
David Howells54ceac42006-08-22 20:06:13 -04002628#endif /* CONFIG_NFS_V4 */