blob: b5fea776a0dce371a0a50c3b60102eb303cec7b7 [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,
Chuck Leverbf0fd762007-07-01 12:13:44 -040080
81 /* Mount options that take integer arguments */
82 Opt_port,
83 Opt_rsize, Opt_wsize, Opt_bsize,
84 Opt_timeo, Opt_retrans,
85 Opt_acregmin, Opt_acregmax,
86 Opt_acdirmin, Opt_acdirmax,
87 Opt_actimeo,
88 Opt_namelen,
89 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040090 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040091 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040092
93 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050094 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040095 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -040096 Opt_lookupcache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040097
Chuck Leverf45663c2008-06-24 19:28:02 -040098 /* Special mount options */
99 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400100
101 Opt_err
102};
103
Steven Whitehousea447c092008-10-13 10:46:57 +0100104static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400105 { Opt_userspace, "bg" },
106 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400107 { Opt_userspace, "retry=%s" },
108
Chuck Leverf45663c2008-06-24 19:28:02 -0400109 { Opt_sloppy, "sloppy" },
110
Chuck Leverbf0fd762007-07-01 12:13:44 -0400111 { Opt_soft, "soft" },
112 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400113 { Opt_deprecated, "intr" },
114 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400115 { Opt_posix, "posix" },
116 { Opt_noposix, "noposix" },
117 { Opt_cto, "cto" },
118 { Opt_nocto, "nocto" },
119 { Opt_ac, "ac" },
120 { Opt_noac, "noac" },
121 { Opt_lock, "lock" },
122 { Opt_nolock, "nolock" },
123 { Opt_v2, "v2" },
124 { Opt_v3, "v3" },
125 { Opt_udp, "udp" },
126 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400127 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128 { Opt_acl, "acl" },
129 { Opt_noacl, "noacl" },
130 { Opt_rdirplus, "rdirplus" },
131 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400132 { Opt_sharecache, "sharecache" },
133 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500134 { Opt_resvport, "resvport" },
135 { Opt_noresvport, "noresvport" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400136
137 { Opt_port, "port=%u" },
138 { Opt_rsize, "rsize=%u" },
139 { Opt_wsize, "wsize=%u" },
140 { Opt_bsize, "bsize=%u" },
141 { Opt_timeo, "timeo=%u" },
142 { Opt_retrans, "retrans=%u" },
143 { Opt_acregmin, "acregmin=%u" },
144 { Opt_acregmax, "acregmax=%u" },
145 { Opt_acdirmin, "acdirmin=%u" },
146 { Opt_acdirmax, "acdirmax=%u" },
147 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400148 { Opt_namelen, "namlen=%u" },
149 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400150 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151 { Opt_nfsvers, "nfsvers=%u" },
152 { Opt_nfsvers, "vers=%u" },
153
154 { Opt_sec, "sec=%s" },
155 { Opt_proto, "proto=%s" },
156 { Opt_mountproto, "mountproto=%s" },
157 { Opt_addr, "addr=%s" },
158 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500159 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400160 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400161
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400162 { Opt_lookupcache, "lookupcache=%s" },
163
Chuck Leverbf0fd762007-07-01 12:13:44 -0400164 { Opt_err, NULL }
165};
166
167enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400168 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
170 Opt_xprt_err
171};
172
Steven Whitehousea447c092008-10-13 10:46:57 +0100173static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400174 { Opt_xprt_udp, "udp" },
175 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400176 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
178 { Opt_xprt_err, NULL }
179};
180
181enum {
182 Opt_sec_none, Opt_sec_sys,
183 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
184 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
185 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
186
187 Opt_sec_err
188};
189
Steven Whitehousea447c092008-10-13 10:46:57 +0100190static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400191 { Opt_sec_none, "none" },
192 { Opt_sec_none, "null" },
193 { Opt_sec_sys, "sys" },
194
195 { Opt_sec_krb5, "krb5" },
196 { Opt_sec_krb5i, "krb5i" },
197 { Opt_sec_krb5p, "krb5p" },
198
199 { Opt_sec_lkey, "lkey" },
200 { Opt_sec_lkeyi, "lkeyi" },
201 { Opt_sec_lkeyp, "lkeyp" },
202
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500203 { Opt_sec_spkm, "spkm3" },
204 { Opt_sec_spkmi, "spkm3i" },
205 { Opt_sec_spkmp, "spkm3p" },
206
Chuck Leverbf0fd762007-07-01 12:13:44 -0400207 { Opt_sec_err, NULL }
208};
209
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400210enum {
211 Opt_lookupcache_all, Opt_lookupcache_positive,
212 Opt_lookupcache_none,
213
214 Opt_lookupcache_err
215};
216
217static match_table_t nfs_lookupcache_tokens = {
218 { Opt_lookupcache_all, "all" },
219 { Opt_lookupcache_positive, "pos" },
220 { Opt_lookupcache_positive, "positive" },
221 { Opt_lookupcache_none, "none" },
222
223 { Opt_lookupcache_err, NULL }
224};
225
Chuck Leverbf0fd762007-07-01 12:13:44 -0400226
Al Viro42faad92008-04-24 07:21:56 -0400227static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400228static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400229static int nfs_show_options(struct seq_file *, struct vfsmount *);
230static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400231static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400232static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400233 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400234static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400235static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400236
237static struct file_system_type nfs_fs_type = {
238 .owner = THIS_MODULE,
239 .name = "nfs",
240 .get_sb = nfs_get_sb,
241 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700242 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400243};
244
David Howells54ceac42006-08-22 20:06:13 -0400245struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400246 .owner = THIS_MODULE,
247 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400248 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400249 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700250 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400251};
252
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800253static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400254 .alloc_inode = nfs_alloc_inode,
255 .destroy_inode = nfs_destroy_inode,
256 .write_inode = nfs_write_inode,
257 .statfs = nfs_statfs,
258 .clear_inode = nfs_clear_inode,
259 .umount_begin = nfs_umount_begin,
260 .show_options = nfs_show_options,
261 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400262 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400263};
264
265#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400266static int nfs4_get_sb(struct file_system_type *fs_type,
267 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400268static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
269 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
270static int nfs4_referral_get_sb(struct file_system_type *fs_type,
271 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400272static void nfs4_kill_super(struct super_block *sb);
273
274static struct file_system_type nfs4_fs_type = {
275 .owner = THIS_MODULE,
276 .name = "nfs4",
277 .get_sb = nfs4_get_sb,
278 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700279 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400280};
281
David Howells54ceac42006-08-22 20:06:13 -0400282struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400283 .owner = THIS_MODULE,
284 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400285 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400286 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700287 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400288};
289
David Howells54ceac42006-08-22 20:06:13 -0400290struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400291 .owner = THIS_MODULE,
292 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400293 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400294 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700295 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400296};
297
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800298static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400299 .alloc_inode = nfs_alloc_inode,
300 .destroy_inode = nfs_destroy_inode,
301 .write_inode = nfs_write_inode,
302 .statfs = nfs_statfs,
303 .clear_inode = nfs4_clear_inode,
304 .umount_begin = nfs_umount_begin,
305 .show_options = nfs_show_options,
306 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400307 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400308};
309#endif
310
Rusty Russell8e1f9362007-07-17 04:03:17 -0700311static struct shrinker acl_shrinker = {
312 .shrink = nfs_access_cache_shrinker,
313 .seeks = DEFAULT_SEEKS,
314};
Trond Myklebust979df722006-07-25 11:28:19 -0400315
David Howellsf7b422b2006-06-09 09:34:33 -0400316/*
317 * Register the NFS filesystems
318 */
319int __init register_nfs_fs(void)
320{
321 int ret;
322
323 ret = register_filesystem(&nfs_fs_type);
324 if (ret < 0)
325 goto error_0;
326
David Howellsf7b422b2006-06-09 09:34:33 -0400327 ret = nfs_register_sysctl();
328 if (ret < 0)
329 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800330#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400331 ret = register_filesystem(&nfs4_fs_type);
332 if (ret < 0)
333 goto error_2;
334#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700335 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400336 return 0;
337
338#ifdef CONFIG_NFS_V4
339error_2:
340 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800341#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400342error_1:
343 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400344error_0:
345 return ret;
346}
347
348/*
349 * Unregister the NFS filesystems
350 */
351void __exit unregister_nfs_fs(void)
352{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700353 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400354#ifdef CONFIG_NFS_V4
355 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400356#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700357 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400358 unregister_filesystem(&nfs_fs_type);
359}
360
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400361void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500362{
363 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400364
365 if (atomic_inc_return(&server->active) == 1)
366 atomic_inc(&sb->s_active);
367}
368
369void nfs_sb_deactive(struct super_block *sb)
370{
371 struct nfs_server *server = NFS_SB(sb);
372
373 if (atomic_dec_and_test(&server->active))
374 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500375}
376
David Howellsf7b422b2006-06-09 09:34:33 -0400377/*
378 * Deliver file system statistics to userspace
379 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400380static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400381{
David Howells0c7d90c2006-08-22 20:06:10 -0400382 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400383 unsigned char blockbits;
384 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400385 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400386 struct nfs_fattr fattr;
387 struct nfs_fsstat res = {
388 .fattr = &fattr,
389 };
390 int error;
391
David Howells8fa5c002006-08-22 20:06:12 -0400392 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400393 if (error < 0)
394 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700395 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400396
397 /*
398 * Current versions of glibc do not correctly handle the
399 * case where f_frsize != f_bsize. Eventually we want to
400 * report the value of wtmult in this field.
401 */
David Howells0c7d90c2006-08-22 20:06:10 -0400402 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400403
404 /*
405 * On most *nix systems, f_blocks, f_bfree, and f_bavail
406 * are reported in units of f_frsize. Linux hasn't had
407 * an f_frsize field in its statfs struct until recently,
408 * thus historically Linux's sys_statfs reports these
409 * fields in units of f_bsize.
410 */
David Howells0c7d90c2006-08-22 20:06:10 -0400411 buf->f_bsize = dentry->d_sb->s_blocksize;
412 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400413 blockres = (1 << blockbits) - 1;
414 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
415 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
416 buf->f_bavail = (res.abytes + blockres) >> blockbits;
417
418 buf->f_files = res.tfiles;
419 buf->f_ffree = res.afiles;
420
421 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700422
David Howellsf7b422b2006-06-09 09:34:33 -0400423 return 0;
424
425 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700426 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700427 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400428}
429
David Howells7d4e2742006-08-22 20:06:07 -0400430/*
431 * Map the security flavour number to a name
432 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400433static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
434{
David Howells7d4e2742006-08-22 20:06:07 -0400435 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400436 rpc_authflavor_t flavour;
437 const char *str;
438 } sec_flavours[] = {
439 { RPC_AUTH_NULL, "null" },
440 { RPC_AUTH_UNIX, "sys" },
441 { RPC_AUTH_GSS_KRB5, "krb5" },
442 { RPC_AUTH_GSS_KRB5I, "krb5i" },
443 { RPC_AUTH_GSS_KRB5P, "krb5p" },
444 { RPC_AUTH_GSS_LKEY, "lkey" },
445 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
446 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
447 { RPC_AUTH_GSS_SPKM, "spkm" },
448 { RPC_AUTH_GSS_SPKMI, "spkmi" },
449 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400450 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400451 };
452 int i;
453
Chuck Lever4d81cd12007-07-01 12:12:40 -0400454 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400455 if (sec_flavours[i].flavour == flavour)
456 break;
457 }
458 return sec_flavours[i].str;
459}
460
Chuck Lever82d101d2008-03-14 14:10:37 -0400461static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
462 int showdefaults)
463{
464 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
465
466 switch (sap->sa_family) {
467 case AF_INET: {
468 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700469 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400470 break;
471 }
472 case AF_INET6: {
473 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700474 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400475 break;
476 }
477 default:
478 if (showdefaults)
479 seq_printf(m, ",mountaddr=unspecified");
480 }
481
482 if (nfss->mountd_version || showdefaults)
483 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
484 if (nfss->mountd_port || showdefaults)
485 seq_printf(m, ",mountport=%u", nfss->mountd_port);
486
487 switch (nfss->mountd_protocol) {
488 case IPPROTO_UDP:
489 seq_printf(m, ",mountproto=udp");
490 break;
491 case IPPROTO_TCP:
492 seq_printf(m, ",mountproto=tcp");
493 break;
494 default:
495 if (showdefaults)
496 seq_printf(m, ",mountproto=auto");
497 }
498}
499
David Howellsf7b422b2006-06-09 09:34:33 -0400500/*
501 * Describe the mount options in force on this server representation
502 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400503static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
504 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400505{
David Howells509de812006-08-22 20:06:11 -0400506 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400507 int flag;
David Howells509de812006-08-22 20:06:11 -0400508 const char *str;
509 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400510 } nfs_info[] = {
511 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400512 { NFS_MOUNT_INTR, ",intr", ",nointr" },
513 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400514 { NFS_MOUNT_NOCTO, ",nocto", "" },
515 { NFS_MOUNT_NOAC, ",noac", "" },
516 { NFS_MOUNT_NONLM, ",nolock", "" },
517 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400518 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500519 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
520 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400521 { 0, NULL, NULL }
522 };
David Howells509de812006-08-22 20:06:11 -0400523 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400524 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400525 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400526
Chuck Lever82d101d2008-03-14 14:10:37 -0400527 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400528 seq_printf(m, ",rsize=%u", nfss->rsize);
529 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400530 if (nfss->bsize != 0)
531 seq_printf(m, ",bsize=%u", nfss->bsize);
532 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400533 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400534 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400535 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400536 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400537 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400538 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400539 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400540 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400541 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
542 if (nfss->flags & nfs_infop->flag)
543 seq_puts(m, nfs_infop->str);
544 else
545 seq_puts(m, nfs_infop->nostr);
546 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400547 seq_printf(m, ",proto=%s",
548 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400549 if (version == 4) {
550 if (nfss->port != NFS_PORT)
551 seq_printf(m, ",port=%u", nfss->port);
552 } else
553 if (nfss->port)
554 seq_printf(m, ",port=%u", nfss->port);
555
Trond Myklebust33170232007-12-20 16:03:59 -0500556 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
557 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400558 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400559
560 if (version != 4)
561 nfs_show_mountd_options(m, nfss, showdefaults);
562
563#ifdef CONFIG_NFS_V4
564 if (clp->rpc_ops->version == 4)
565 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
566#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400567}
568
569/*
570 * Describe the mount options on this VFS mountpoint
571 */
572static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
573{
574 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
575
576 nfs_show_mount_options(m, nfss, 0);
577
Chuck Lever5d8515c2007-12-10 14:57:16 -0500578 seq_printf(m, ",addr=%s",
579 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
580 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400581
582 return 0;
583}
584
585/*
586 * Present statistical information for this VFS mountpoint
587 */
588static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
589{
590 int i, cpu;
591 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
592 struct rpc_auth *auth = nfss->client->cl_auth;
593 struct nfs_iostats totals = { };
594
595 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
596
597 /*
598 * Display all mount option settings
599 */
600 seq_printf(m, "\n\topts:\t");
601 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
602 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
603 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
604 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
605 nfs_show_mount_options(m, nfss, 1);
606
607 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
608
609 seq_printf(m, "\n\tcaps:\t");
610 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400611 seq_printf(m, ",wtmult=%u", nfss->wtmult);
612 seq_printf(m, ",dtsize=%u", nfss->dtsize);
613 seq_printf(m, ",bsize=%u", nfss->bsize);
614 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400615
616#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500617 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400618 seq_printf(m, "\n\tnfsv4:\t");
619 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
620 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
621 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
622 }
623#endif
624
625 /*
626 * Display security flavor in effect for this mount
627 */
Chuck Lever2d767432008-03-14 14:10:08 -0400628 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400629 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400630 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400631
632 /*
633 * Display superblock I/O counters
634 */
635 for_each_possible_cpu(cpu) {
636 struct nfs_iostats *stats;
637
638 preempt_disable();
639 stats = per_cpu_ptr(nfss->io_stats, cpu);
640
641 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
642 totals.events[i] += stats->events[i];
643 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
644 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100645#ifdef CONFIG_NFS_FSCACHE
646 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
647 totals.fscache[i] += stats->fscache[i];
648#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400649
650 preempt_enable();
651 }
652
653 seq_printf(m, "\n\tevents:\t");
654 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
655 seq_printf(m, "%lu ", totals.events[i]);
656 seq_printf(m, "\n\tbytes:\t");
657 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
658 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100659#ifdef CONFIG_NFS_FSCACHE
660 if (nfss->options & NFS_OPTION_FSCACHE) {
661 seq_printf(m, "\n\tfsc:\t");
662 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
663 seq_printf(m, "%Lu ", totals.bytes[i]);
664 }
665#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400666 seq_printf(m, "\n");
667
668 rpc_print_iostats(m, nfss->client);
669
670 return 0;
671}
672
673/*
674 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400675 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400676 */
Al Viro42faad92008-04-24 07:21:56 -0400677static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400678{
Al Viro42faad92008-04-24 07:21:56 -0400679 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400680 struct rpc_clnt *rpc;
681
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400682 /* -EIO all pending I/O */
683 rpc = server->client_acl;
684 if (!IS_ERR(rpc))
685 rpc_killall_tasks(rpc);
686 rpc = server->client;
687 if (!IS_ERR(rpc))
688 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400689}
690
691/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500692 * Sanity-check a server address provided by the mount command.
693 *
694 * Address family must be initialized, and address must not be
695 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400696 */
697static int nfs_verify_server_address(struct sockaddr *addr)
698{
699 switch (addr->sa_family) {
700 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500701 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700702 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500703 }
704 case AF_INET6: {
705 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
706 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400707 }
708 }
709
710 return 0;
711}
712
Chuck Leverce3b7e12008-06-23 12:36:53 -0400713static void nfs_parse_ipv4_address(char *string, size_t str_len,
714 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500715{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400716 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
717 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500718
Chuck Leverce3b7e12008-06-23 12:36:53 -0400719 if (str_len <= INET_ADDRSTRLEN) {
720 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
721 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500722
Chuck Leverce3b7e12008-06-23 12:36:53 -0400723 sin->sin_family = AF_INET;
724 *addr_len = sizeof(*sin);
725 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500726 return;
727 }
Chuck Lever9412b922007-12-10 14:59:21 -0500728
729 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400730 *addr_len = 0;
731}
732
733#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400734static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
735 const char *delim,
736 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400737{
738 char *p;
739 size_t len;
740
Chuck Lever5e2e7722008-10-08 15:38:10 -0400741 if ((string + str_len) == delim)
742 return 1;
743
Chuck Leverd8e77482008-06-23 12:37:01 -0400744 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400745 return 0;
746
747 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
748 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400749
750 len = (string + str_len) - delim - 1;
751 p = kstrndup(delim + 1, len, GFP_KERNEL);
752 if (p) {
753 unsigned long scope_id = 0;
754 struct net_device *dev;
755
756 dev = dev_get_by_name(&init_net, p);
757 if (dev != NULL) {
758 scope_id = dev->ifindex;
759 dev_put(dev);
760 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400761 if (strict_strtoul(p, 10, &scope_id) == 0) {
762 kfree(p);
763 return 0;
764 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400765 }
766
767 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400768
Chuck Leverd8e77482008-06-23 12:37:01 -0400769 sin6->sin6_scope_id = scope_id;
770 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400771 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400772 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400773
774 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400775}
776
Chuck Leverce3b7e12008-06-23 12:36:53 -0400777static void nfs_parse_ipv6_address(char *string, size_t str_len,
778 struct sockaddr *sap, size_t *addr_len)
779{
780 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
781 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400782 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400783
784 if (str_len <= INET6_ADDRSTRLEN) {
785 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
786 (int)str_len, string);
787
788 sin6->sin6_family = AF_INET6;
789 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400790 if (in6_pton(string, str_len, addr,
791 IPV6_SCOPE_DELIMITER, &delim) != 0) {
792 if (nfs_parse_ipv6_scope_id(string, str_len,
793 delim, sin6) != 0)
794 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400795 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400796 }
797
798 sap->sa_family = AF_UNSPEC;
799 *addr_len = 0;
800}
801#else
802static void nfs_parse_ipv6_address(char *string, size_t str_len,
803 struct sockaddr *sap, size_t *addr_len)
804{
805 sap->sa_family = AF_UNSPEC;
806 *addr_len = 0;
807}
808#endif
809
810/*
811 * Construct a sockaddr based on the contents of a string that contains
812 * an IP address in presentation format.
813 *
814 * If there is a problem constructing the new sockaddr, set the address
815 * family to AF_UNSPEC.
816 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400817void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400818 struct sockaddr *sap, size_t *addr_len)
819{
820 unsigned int i, colons;
821
822 colons = 0;
823 for (i = 0; i < str_len; i++)
824 if (string[i] == ':')
825 colons++;
826
827 if (colons >= 2)
828 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
829 else
830 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500831}
832
833/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400834 * Sanity check the NFS transport protocol.
835 *
836 */
837static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
838{
839 switch (mnt->nfs_server.protocol) {
840 case XPRT_TRANSPORT_UDP:
841 case XPRT_TRANSPORT_TCP:
842 case XPRT_TRANSPORT_RDMA:
843 break;
844 default:
845 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
846 }
847}
848
849/*
850 * For text based NFSv2/v3 mounts, the mount protocol transport default
851 * settings should depend upon the specified NFS transport.
852 */
853static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
854{
855 nfs_validate_transport_protocol(mnt);
856
857 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
858 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
859 return;
860 switch (mnt->nfs_server.protocol) {
861 case XPRT_TRANSPORT_UDP:
862 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
863 break;
864 case XPRT_TRANSPORT_TCP:
865 case XPRT_TRANSPORT_RDMA:
866 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
867 }
868}
869
870/*
Chuck Lever01060c82008-06-24 16:33:38 -0400871 * Parse the value of the 'sec=' option.
872 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400873 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400874 */
875static int nfs_parse_security_flavors(char *value,
876 struct nfs_parsed_mount_data *mnt)
877{
878 substring_t args[MAX_OPT_ARGS];
879
880 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
881
882 switch (match_token(value, nfs_secflavor_tokens, args)) {
883 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400884 mnt->auth_flavor_len = 0;
885 mnt->auth_flavors[0] = RPC_AUTH_NULL;
886 break;
887 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400888 mnt->auth_flavor_len = 0;
889 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
890 break;
891 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400892 mnt->auth_flavor_len = 1;
893 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
894 break;
895 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400896 mnt->auth_flavor_len = 1;
897 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
898 break;
899 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400900 mnt->auth_flavor_len = 1;
901 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
902 break;
903 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400904 mnt->auth_flavor_len = 1;
905 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
906 break;
907 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400908 mnt->auth_flavor_len = 1;
909 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
910 break;
911 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400912 mnt->auth_flavor_len = 1;
913 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
914 break;
915 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400916 mnt->auth_flavor_len = 1;
917 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
918 break;
919 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400920 mnt->auth_flavor_len = 1;
921 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
922 break;
923 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400924 mnt->auth_flavor_len = 1;
925 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
926 break;
927 default:
928 return 0;
929 }
930
931 return 1;
932}
933
Chuck Leverf45663c2008-06-24 19:28:02 -0400934static void nfs_parse_invalid_value(const char *option)
935{
936 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
937}
938
Chuck Lever01060c82008-06-24 16:33:38 -0400939/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400940 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400941 * a data structure. The whole mount string is processed; bad options are
942 * skipped as they are encountered. If there were no errors, return 1;
943 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400944 */
945static int nfs_parse_mount_options(char *raw,
946 struct nfs_parsed_mount_data *mnt)
947{
Eric Parisf9c3a382008-03-05 14:20:18 -0500948 char *p, *string, *secdata;
Chuck Leverf45663c2008-06-24 19:28:02 -0400949 int rc, sloppy = 0, errors = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950
951 if (!raw) {
952 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
953 return 1;
954 }
955 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
956
Eric Parisf9c3a382008-03-05 14:20:18 -0500957 secdata = alloc_secdata();
958 if (!secdata)
959 goto out_nomem;
960
961 rc = security_sb_copy_data(raw, secdata);
962 if (rc)
963 goto out_security_failure;
964
965 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
966 if (rc)
967 goto out_security_failure;
968
969 free_secdata(secdata);
970
Chuck Leverbf0fd762007-07-01 12:13:44 -0400971 while ((p = strsep(&raw, ",")) != NULL) {
972 substring_t args[MAX_OPT_ARGS];
973 int option, token;
974
975 if (!*p)
976 continue;
977
978 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
979
980 token = match_token(p, nfs_mount_option_tokens, args);
981 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400982
983 /*
984 * boolean options: foo/nofoo
985 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400986 case Opt_soft:
987 mnt->flags |= NFS_MOUNT_SOFT;
988 break;
989 case Opt_hard:
990 mnt->flags &= ~NFS_MOUNT_SOFT;
991 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400992 case Opt_posix:
993 mnt->flags |= NFS_MOUNT_POSIX;
994 break;
995 case Opt_noposix:
996 mnt->flags &= ~NFS_MOUNT_POSIX;
997 break;
998 case Opt_cto:
999 mnt->flags &= ~NFS_MOUNT_NOCTO;
1000 break;
1001 case Opt_nocto:
1002 mnt->flags |= NFS_MOUNT_NOCTO;
1003 break;
1004 case Opt_ac:
1005 mnt->flags &= ~NFS_MOUNT_NOAC;
1006 break;
1007 case Opt_noac:
1008 mnt->flags |= NFS_MOUNT_NOAC;
1009 break;
1010 case Opt_lock:
1011 mnt->flags &= ~NFS_MOUNT_NONLM;
1012 break;
1013 case Opt_nolock:
1014 mnt->flags |= NFS_MOUNT_NONLM;
1015 break;
1016 case Opt_v2:
1017 mnt->flags &= ~NFS_MOUNT_VER3;
1018 break;
1019 case Opt_v3:
1020 mnt->flags |= NFS_MOUNT_VER3;
1021 break;
1022 case Opt_udp:
1023 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001024 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001025 break;
1026 case Opt_tcp:
1027 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001028 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001029 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001030 case Opt_rdma:
1031 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1032 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001033 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001034 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001035 case Opt_acl:
1036 mnt->flags &= ~NFS_MOUNT_NOACL;
1037 break;
1038 case Opt_noacl:
1039 mnt->flags |= NFS_MOUNT_NOACL;
1040 break;
1041 case Opt_rdirplus:
1042 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1043 break;
1044 case Opt_nordirplus:
1045 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1046 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001047 case Opt_sharecache:
1048 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1049 break;
1050 case Opt_nosharecache:
1051 mnt->flags |= NFS_MOUNT_UNSHARED;
1052 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001053 case Opt_resvport:
1054 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1055 break;
1056 case Opt_noresvport:
1057 mnt->flags |= NFS_MOUNT_NORESVPORT;
1058 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001059
Chuck Leverf45663c2008-06-24 19:28:02 -04001060 /*
1061 * options that take numeric values
1062 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001063 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001064 if (match_int(args, &option) ||
1065 option < 0 || option > USHORT_MAX) {
1066 errors++;
1067 nfs_parse_invalid_value("port");
1068 } else
1069 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001070 break;
1071 case Opt_rsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001072 if (match_int(args, &option) || option < 0) {
1073 errors++;
1074 nfs_parse_invalid_value("rsize");
1075 } else
1076 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001077 break;
1078 case Opt_wsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001079 if (match_int(args, &option) || option < 0) {
1080 errors++;
1081 nfs_parse_invalid_value("wsize");
1082 } else
1083 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001084 break;
1085 case Opt_bsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001086 if (match_int(args, &option) || option < 0) {
1087 errors++;
1088 nfs_parse_invalid_value("bsize");
1089 } else
1090 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001091 break;
1092 case Opt_timeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001093 if (match_int(args, &option) || option <= 0) {
1094 errors++;
1095 nfs_parse_invalid_value("timeo");
1096 } else
1097 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001098 break;
1099 case Opt_retrans:
Chuck Leverf45663c2008-06-24 19:28:02 -04001100 if (match_int(args, &option) || option <= 0) {
1101 errors++;
1102 nfs_parse_invalid_value("retrans");
1103 } else
1104 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001105 break;
1106 case Opt_acregmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001107 if (match_int(args, &option) || option < 0) {
1108 errors++;
1109 nfs_parse_invalid_value("acregmin");
1110 } else
1111 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001112 break;
1113 case Opt_acregmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001114 if (match_int(args, &option) || option < 0) {
1115 errors++;
1116 nfs_parse_invalid_value("acregmax");
1117 } else
1118 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001119 break;
1120 case Opt_acdirmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001121 if (match_int(args, &option) || option < 0) {
1122 errors++;
1123 nfs_parse_invalid_value("acdirmin");
1124 } else
1125 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126 break;
1127 case Opt_acdirmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001128 if (match_int(args, &option) || option < 0) {
1129 errors++;
1130 nfs_parse_invalid_value("acdirmax");
1131 } else
1132 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001133 break;
1134 case Opt_actimeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001135 if (match_int(args, &option) || option < 0) {
1136 errors++;
1137 nfs_parse_invalid_value("actimeo");
1138 } else
1139 mnt->acregmin = mnt->acregmax =
1140 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001141 break;
1142 case Opt_namelen:
Chuck Leverf45663c2008-06-24 19:28:02 -04001143 if (match_int(args, &option) || option < 0) {
1144 errors++;
1145 nfs_parse_invalid_value("namlen");
1146 } else
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) ||
1151 option < 0 || option > USHORT_MAX) {
1152 errors++;
1153 nfs_parse_invalid_value("mountport");
1154 } else
1155 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001156 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001157 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001158 if (match_int(args, &option) ||
1159 option < NFS_MNT_VERSION ||
1160 option > NFS_MNT3_VERSION) {
1161 errors++;
1162 nfs_parse_invalid_value("mountvers");
1163 } else
1164 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 case Opt_nfsvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001167 if (match_int(args, &option)) {
1168 errors++;
1169 nfs_parse_invalid_value("nfsvers");
1170 break;
1171 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001172 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001173 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001174 mnt->flags &= ~NFS_MOUNT_VER3;
1175 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001176 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 mnt->flags |= NFS_MOUNT_VER3;
1178 break;
1179 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001180 errors++;
1181 nfs_parse_invalid_value("nfsvers");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001182 }
1183 break;
1184
Chuck Leverf45663c2008-06-24 19:28:02 -04001185 /*
1186 * options that take text values
1187 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 case Opt_sec:
1189 string = match_strdup(args);
1190 if (string == NULL)
1191 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001192 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001193 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001194 if (!rc) {
1195 errors++;
1196 dfprintk(MOUNT, "NFS: unrecognized "
1197 "security flavor\n");
1198 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
1200 case Opt_proto:
1201 string = match_strdup(args);
1202 if (string == NULL)
1203 goto out_nomem;
1204 token = match_token(string,
1205 nfs_xprt_protocol_tokens, args);
1206 kfree(string);
1207
1208 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001209 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001210 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001211 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001212 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001213 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001215 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001217 case Opt_xprt_rdma:
1218 /* vector side protocols to TCP */
1219 mnt->flags |= NFS_MOUNT_TCP;
1220 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001221 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001222 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001223 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001224 errors++;
1225 dfprintk(MOUNT, "NFS: unrecognized "
1226 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227 }
Tom Talpeya67d18f2009-03-11 14:37:56 -04001228 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
1230 case Opt_mountproto:
1231 string = match_strdup(args);
1232 if (string == NULL)
1233 goto out_nomem;
1234 token = match_token(string,
1235 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236
1237 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001238 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001239 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001241 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001242 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001243 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001244 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001246 errors++;
1247 dfprintk(MOUNT, "NFS: unrecognized "
1248 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001249 }
1250 break;
1251 case Opt_addr:
1252 string = match_strdup(args);
1253 if (string == NULL)
1254 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001255 nfs_parse_ip_address(string, strlen(string),
1256 (struct sockaddr *)
1257 &mnt->nfs_server.address,
1258 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 kfree(string);
1260 break;
1261 case Opt_clientaddr:
1262 string = match_strdup(args);
1263 if (string == NULL)
1264 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001265 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001266 mnt->client_address = string;
1267 break;
Chuck Lever33832032007-12-10 14:59:13 -05001268 case Opt_mounthost:
1269 string = match_strdup(args);
1270 if (string == NULL)
1271 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001272 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001273 mnt->mount_server.hostname = string;
1274 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001275 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001276 string = match_strdup(args);
1277 if (string == NULL)
1278 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001279 nfs_parse_ip_address(string, strlen(string),
1280 (struct sockaddr *)
1281 &mnt->mount_server.address,
1282 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001283 kfree(string);
1284 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001285 case Opt_lookupcache:
1286 string = match_strdup(args);
1287 if (string == NULL)
1288 goto out_nomem;
1289 token = match_token(string,
1290 nfs_lookupcache_tokens, args);
1291 kfree(string);
1292 switch (token) {
1293 case Opt_lookupcache_all:
1294 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1295 break;
1296 case Opt_lookupcache_positive:
1297 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1298 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1299 break;
1300 case Opt_lookupcache_none:
1301 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1302 break;
1303 default:
1304 errors++;
1305 dfprintk(MOUNT, "NFS: invalid "
1306 "lookupcache argument\n");
1307 };
1308 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309
Chuck Leverf45663c2008-06-24 19:28:02 -04001310 /*
1311 * Special options
1312 */
1313 case Opt_sloppy:
1314 sloppy = 1;
1315 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1316 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 case Opt_userspace:
1318 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001319 dfprintk(MOUNT, "NFS: ignoring mount option "
1320 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 break;
1322
1323 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001324 errors++;
1325 dfprintk(MOUNT, "NFS: unrecognized mount option "
1326 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 }
1328 }
1329
Chuck Leveraf904de2008-09-08 11:58:13 -04001330 if (errors > 0) {
1331 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1332 errors, (errors == 1 ? "" : "s"));
1333 if (!sloppy)
1334 return 0;
1335 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 return 1;
1337
1338out_nomem:
1339 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1340 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001341out_security_failure:
1342 free_secdata(secdata);
1343 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1344 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001345}
1346
1347/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001348 * Use the remote server's MOUNT service to request the NFS file handle
1349 * corresponding to the provided path.
1350 */
1351static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1352 struct nfs_fh *root_fh)
1353{
Chuck Leverc5d120f2008-12-23 15:21:35 -05001354 struct nfs_mount_request request = {
1355 .sap = (struct sockaddr *)
1356 &args->mount_server.address,
1357 .dirpath = args->nfs_server.export_path,
1358 .protocol = args->mount_server.protocol,
1359 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001360 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001361 };
Chuck Lever4c568012007-12-10 14:59:28 -05001362 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001363
1364 if (args->mount_server.version == 0) {
1365 if (args->flags & NFS_MOUNT_VER3)
1366 args->mount_server.version = NFS_MNT3_VERSION;
1367 else
1368 args->mount_server.version = NFS_MNT_VERSION;
1369 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001370 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001371
Chuck Lever33832032007-12-10 14:59:13 -05001372 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001373 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001374 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001375 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001376
Chuck Lever0076d7b2007-07-01 12:13:49 -04001377 /*
1378 * Construct the mount server's address.
1379 */
Chuck Lever4c568012007-12-10 14:59:28 -05001380 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001381 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001382 args->nfs_server.addrlen);
1383 args->mount_server.addrlen = args->nfs_server.addrlen;
1384 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001385 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001386
James Lentiniaad70002007-09-24 17:32:49 -04001387 /*
1388 * autobind will be used if mount_server.port == 0
1389 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001390 nfs_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001391
1392 /*
1393 * Now ask the mount server to map our export path
1394 * to a file handle.
1395 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001396 status = nfs_mount(&request);
Chuck Leverefd83402007-09-11 18:00:58 -04001397 if (status == 0)
1398 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001399
Chuck Lever396cee972008-06-12 12:37:49 -04001400 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Leverc5d120f2008-12-23 15:21:35 -05001401 request.hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001402 return status;
1403}
1404
Chuck Leverd1aa0822008-06-23 12:36:45 -04001405static int nfs_parse_simple_hostname(const char *dev_name,
1406 char **hostname, size_t maxnamlen,
1407 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001408{
1409 size_t len;
1410 char *colon, *comma;
1411
1412 colon = strchr(dev_name, ':');
1413 if (colon == NULL)
1414 goto out_bad_devname;
1415
1416 len = colon - dev_name;
1417 if (len > maxnamlen)
1418 goto out_hostname;
1419
1420 /* N.B. caller will free nfs_server.hostname in all cases */
1421 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1422 if (!*hostname)
1423 goto out_nomem;
1424
1425 /* kill possible hostname list: not supported */
1426 comma = strchr(*hostname, ',');
1427 if (comma != NULL) {
1428 if (comma == *hostname)
1429 goto out_bad_devname;
1430 *comma = '\0';
1431 }
1432
1433 colon++;
1434 len = strlen(colon);
1435 if (len > maxpathlen)
1436 goto out_path;
1437 *export_path = kstrndup(colon, len, GFP_KERNEL);
1438 if (!*export_path)
1439 goto out_nomem;
1440
1441 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1442 return 0;
1443
1444out_bad_devname:
1445 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1446 return -EINVAL;
1447
1448out_nomem:
1449 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1450 return -ENOMEM;
1451
1452out_hostname:
1453 dfprintk(MOUNT, "NFS: server hostname too long\n");
1454 return -ENAMETOOLONG;
1455
1456out_path:
1457 dfprintk(MOUNT, "NFS: export pathname too long\n");
1458 return -ENAMETOOLONG;
1459}
1460
1461/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001462 * Hostname has square brackets around it because it contains one or
1463 * more colons. We look for the first closing square bracket, and a
1464 * colon must follow it.
1465 */
1466static int nfs_parse_protected_hostname(const char *dev_name,
1467 char **hostname, size_t maxnamlen,
1468 char **export_path, size_t maxpathlen)
1469{
1470 size_t len;
1471 char *start, *end;
1472
1473 start = (char *)(dev_name + 1);
1474
1475 end = strchr(start, ']');
1476 if (end == NULL)
1477 goto out_bad_devname;
1478 if (*(end + 1) != ':')
1479 goto out_bad_devname;
1480
1481 len = end - start;
1482 if (len > maxnamlen)
1483 goto out_hostname;
1484
1485 /* N.B. caller will free nfs_server.hostname in all cases */
1486 *hostname = kstrndup(start, len, GFP_KERNEL);
1487 if (*hostname == NULL)
1488 goto out_nomem;
1489
1490 end += 2;
1491 len = strlen(end);
1492 if (len > maxpathlen)
1493 goto out_path;
1494 *export_path = kstrndup(end, len, GFP_KERNEL);
1495 if (!*export_path)
1496 goto out_nomem;
1497
1498 return 0;
1499
1500out_bad_devname:
1501 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1502 return -EINVAL;
1503
1504out_nomem:
1505 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1506 return -ENOMEM;
1507
1508out_hostname:
1509 dfprintk(MOUNT, "NFS: server hostname too long\n");
1510 return -ENAMETOOLONG;
1511
1512out_path:
1513 dfprintk(MOUNT, "NFS: export pathname too long\n");
1514 return -ENAMETOOLONG;
1515}
1516
1517/*
1518 * Split "dev_name" into "hostname:export_path".
1519 *
1520 * The leftmost colon demarks the split between the server's hostname
1521 * and the export path. If the hostname starts with a left square
1522 * bracket, then it may contain colons.
1523 *
1524 * Note: caller frees hostname and export path, even on error.
1525 */
1526static int nfs_parse_devname(const char *dev_name,
1527 char **hostname, size_t maxnamlen,
1528 char **export_path, size_t maxpathlen)
1529{
1530 if (*dev_name == '[')
1531 return nfs_parse_protected_hostname(dev_name,
1532 hostname, maxnamlen,
1533 export_path, maxpathlen);
1534
1535 return nfs_parse_simple_hostname(dev_name,
1536 hostname, maxnamlen,
1537 export_path, maxpathlen);
1538}
1539
1540/*
David Howells54ceac42006-08-22 20:06:13 -04001541 * Validate the NFS2/NFS3 mount data
1542 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001543 *
1544 * For option strings, user space handles the following behaviors:
1545 *
1546 * + DNS: mapping server host name to IP address ("addr=" option)
1547 *
1548 * + failure mode: how to behave if a mount request can't be handled
1549 * immediately ("fg/bg" option)
1550 *
1551 * + retry: how often to retry a mount request ("retry=" option)
1552 *
1553 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1554 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001555 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001556static int nfs_validate_mount_data(void *options,
1557 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001558 struct nfs_fh *mntfh,
1559 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001560{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001561 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001562
Chuck Lever5df36e72007-07-01 12:12:56 -04001563 if (data == NULL)
1564 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001565
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001566 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1567 args->rsize = NFS_MAX_FILE_IO_SIZE;
1568 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001569 args->acregmin = NFS_DEF_ACREGMIN;
1570 args->acregmax = NFS_DEF_ACREGMAX;
1571 args->acdirmin = NFS_DEF_ACDIRMIN;
1572 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001573 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001574 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001575 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001576 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001577
David Howellsf7b422b2006-06-09 09:34:33 -04001578 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001579 case 1:
1580 data->namlen = 0;
1581 case 2:
1582 data->bsize = 0;
1583 case 3:
1584 if (data->flags & NFS_MOUNT_VER3)
1585 goto out_no_v3;
1586 data->root.size = NFS2_FHSIZE;
1587 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1588 case 4:
1589 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1590 goto out_no_sec;
1591 case 5:
1592 memset(data->context, 0, sizeof(data->context));
1593 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001594 if (data->flags & NFS_MOUNT_VER3) {
1595 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1596 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001597 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001598 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001599 mntfh->size = NFS2_FHSIZE;
1600
Chuck Lever5df36e72007-07-01 12:12:56 -04001601
1602 memcpy(mntfh->data, data->root.data, mntfh->size);
1603 if (mntfh->size < sizeof(mntfh->data))
1604 memset(mntfh->data + mntfh->size, 0,
1605 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001606
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001607 /*
1608 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1609 * can deal with.
1610 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001611 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001612 args->rsize = data->rsize;
1613 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001614 args->timeo = data->timeo;
1615 args->retrans = data->retrans;
1616 args->acregmin = data->acregmin;
1617 args->acregmax = data->acregmax;
1618 args->acdirmin = data->acdirmin;
1619 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001620
1621 memcpy(&args->nfs_server.address, &data->addr,
1622 sizeof(data->addr));
1623 args->nfs_server.addrlen = sizeof(data->addr);
1624 if (!nfs_verify_server_address((struct sockaddr *)
1625 &args->nfs_server.address))
1626 goto out_no_address;
1627
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001628 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001629 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001630 /* N.B. caller will free nfs_server.hostname in all cases */
1631 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1632 args->namlen = data->namlen;
1633 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001634
1635 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1636 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001637 if (!args->nfs_server.hostname)
1638 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001639
1640 /*
1641 * The legacy version 6 binary mount data from userspace has a
1642 * field used only to transport selinux information into the
1643 * the kernel. To continue to support that functionality we
1644 * have a touch of selinux knowledge here in the NFS code. The
1645 * userspace code converted context=blah to just blah so we are
1646 * converting back to the full string selinux understands.
1647 */
1648 if (data->context[0]){
1649#ifdef CONFIG_SECURITY_SELINUX
1650 int rc;
1651 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1652 if (!opts_str)
1653 return -ENOMEM;
1654 strcpy(opts_str, "context=");
1655 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1656 strcat(opts_str, &data->context[0]);
1657 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1658 kfree(opts_str);
1659 if (rc)
1660 return rc;
1661#else
1662 return -EINVAL;
1663#endif
1664 }
1665
Chuck Lever5df36e72007-07-01 12:12:56 -04001666 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001667 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001668 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001669
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001670 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001671 return -EINVAL;
1672
Chuck Lever6e88e062007-09-24 15:39:50 -04001673 if (!nfs_verify_server_address((struct sockaddr *)
1674 &args->nfs_server.address))
1675 goto out_no_address;
1676
Chuck Levered596a82008-06-26 17:47:05 -04001677 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1678 args->nfs_server.port);
1679
Trond Myklebust259875e2008-07-02 14:43:47 -04001680 nfs_set_mount_transport_protocol(args);
1681
Chuck Leverdc045892008-06-23 12:36:37 -04001682 status = nfs_parse_devname(dev_name,
1683 &args->nfs_server.hostname,
1684 PAGE_SIZE,
1685 &args->nfs_server.export_path,
1686 NFS_MAXPATHLEN);
1687 if (!status)
1688 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001689
Chuck Leverdc045892008-06-23 12:36:37 -04001690 kfree(args->nfs_server.export_path);
1691 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001692
Chuck Lever136d5582007-07-01 12:13:54 -04001693 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001694 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001695
Chuck Lever136d5582007-07-01 12:13:54 -04001696 break;
1697 }
David Howellsf7b422b2006-06-09 09:34:33 -04001698 }
David Howells54ceac42006-08-22 20:06:13 -04001699
David Howellsf7b422b2006-06-09 09:34:33 -04001700#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001701 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001702 goto out_v3_not_compiled;
1703#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001704
David Howells54ceac42006-08-22 20:06:13 -04001705 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001706
1707out_no_data:
1708 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1709 return -EINVAL;
1710
1711out_no_v3:
1712 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1713 data->version);
1714 return -EINVAL;
1715
1716out_no_sec:
1717 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1718 return -EINVAL;
1719
Chuck Lever5df36e72007-07-01 12:12:56 -04001720#ifndef CONFIG_NFS_V3
1721out_v3_not_compiled:
1722 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1723 return -EPROTONOSUPPORT;
1724#endif /* !CONFIG_NFS_V3 */
1725
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001726out_nomem:
1727 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1728 return -ENOMEM;
1729
Chuck Lever5df36e72007-07-01 12:12:56 -04001730out_no_address:
1731 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1732 return -EINVAL;
1733
1734out_invalid_fh:
1735 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1736 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001737}
1738
Jeff Layton48b605f2008-06-10 15:38:39 -04001739static int
1740nfs_compare_remount_data(struct nfs_server *nfss,
1741 struct nfs_parsed_mount_data *data)
1742{
1743 if (data->flags != nfss->flags ||
1744 data->rsize != nfss->rsize ||
1745 data->wsize != nfss->wsize ||
1746 data->retrans != nfss->client->cl_timeout->to_retries ||
1747 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1748 data->acregmin != nfss->acregmin / HZ ||
1749 data->acregmax != nfss->acregmax / HZ ||
1750 data->acdirmin != nfss->acdirmin / HZ ||
1751 data->acdirmax != nfss->acdirmax / HZ ||
1752 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1753 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1754 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1755 data->nfs_server.addrlen) != 0)
1756 return -EINVAL;
1757
1758 return 0;
1759}
1760
1761static int
1762nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1763{
1764 int error;
1765 struct nfs_server *nfss = sb->s_fs_info;
1766 struct nfs_parsed_mount_data *data;
1767 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1768 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001769 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001770
1771 /*
1772 * Userspace mount programs that send binary options generally send
1773 * them populated with default values. We have no way to know which
1774 * ones were explicitly specified. Fall back to legacy behavior and
1775 * just return success.
1776 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001777 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1778 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1779 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001780 return 0;
1781
1782 data = kzalloc(sizeof(*data), GFP_KERNEL);
1783 if (data == NULL)
1784 return -ENOMEM;
1785
1786 /* fill out struct with values from existing mount */
1787 data->flags = nfss->flags;
1788 data->rsize = nfss->rsize;
1789 data->wsize = nfss->wsize;
1790 data->retrans = nfss->client->cl_timeout->to_retries;
1791 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1792 data->acregmin = nfss->acregmin / HZ;
1793 data->acregmax = nfss->acregmax / HZ;
1794 data->acdirmin = nfss->acdirmin / HZ;
1795 data->acdirmax = nfss->acdirmax / HZ;
1796 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1797 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1798 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1799 data->nfs_server.addrlen);
1800
1801 /* overwrite those values with any that were specified */
1802 error = nfs_parse_mount_options((char *)options, data);
1803 if (error < 0)
1804 goto out;
1805
1806 /* compare new mount options with old ones */
1807 error = nfs_compare_remount_data(nfss, data);
1808out:
1809 kfree(data);
1810 return error;
1811}
1812
David Howells54ceac42006-08-22 20:06:13 -04001813/*
1814 * Initialise the common bits of the superblock
1815 */
1816static inline void nfs_initialise_sb(struct super_block *sb)
1817{
1818 struct nfs_server *server = NFS_SB(sb);
1819
1820 sb->s_magic = NFS_SUPER_MAGIC;
1821
1822 /* We probably want something more informative here */
1823 snprintf(sb->s_id, sizeof(sb->s_id),
1824 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1825
1826 if (sb->s_blocksize == 0)
1827 sb->s_blocksize = nfs_block_bits(server->wsize,
1828 &sb->s_blocksize_bits);
1829
1830 if (server->flags & NFS_MOUNT_NOAC)
1831 sb->s_flags |= MS_SYNCHRONOUS;
1832
1833 nfs_super_set_maxbytes(sb, server->maxfilesize);
1834}
1835
1836/*
1837 * Finish setting up an NFS2/3 superblock
1838 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001839static void nfs_fill_super(struct super_block *sb,
1840 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001841{
1842 struct nfs_server *server = NFS_SB(sb);
1843
1844 sb->s_blocksize_bits = 0;
1845 sb->s_blocksize = 0;
1846 if (data->bsize)
1847 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1848
1849 if (server->flags & NFS_MOUNT_VER3) {
1850 /* The VFS shouldn't apply the umask to mode bits. We will do
1851 * so ourselves when necessary.
1852 */
1853 sb->s_flags |= MS_POSIXACL;
1854 sb->s_time_gran = 1;
1855 }
1856
1857 sb->s_op = &nfs_sops;
1858 nfs_initialise_sb(sb);
1859}
1860
1861/*
1862 * Finish setting up a cloned NFS2/3 superblock
1863 */
1864static void nfs_clone_super(struct super_block *sb,
1865 const struct super_block *old_sb)
1866{
1867 struct nfs_server *server = NFS_SB(sb);
1868
1869 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1870 sb->s_blocksize = old_sb->s_blocksize;
1871 sb->s_maxbytes = old_sb->s_maxbytes;
1872
1873 if (server->flags & NFS_MOUNT_VER3) {
1874 /* The VFS shouldn't apply the umask to mode bits. We will do
1875 * so ourselves when necessary.
1876 */
1877 sb->s_flags |= MS_POSIXACL;
1878 sb->s_time_gran = 1;
1879 }
1880
1881 sb->s_op = old_sb->s_op;
1882 nfs_initialise_sb(sb);
1883}
1884
Trond Myklebust275a5d22007-05-16 16:53:28 -04001885static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1886{
1887 const struct nfs_server *a = s->s_fs_info;
1888 const struct rpc_clnt *clnt_a = a->client;
1889 const struct rpc_clnt *clnt_b = b->client;
1890
1891 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1892 goto Ebusy;
1893 if (a->nfs_client != b->nfs_client)
1894 goto Ebusy;
1895 if (a->flags != b->flags)
1896 goto Ebusy;
1897 if (a->wsize != b->wsize)
1898 goto Ebusy;
1899 if (a->rsize != b->rsize)
1900 goto Ebusy;
1901 if (a->acregmin != b->acregmin)
1902 goto Ebusy;
1903 if (a->acregmax != b->acregmax)
1904 goto Ebusy;
1905 if (a->acdirmin != b->acdirmin)
1906 goto Ebusy;
1907 if (a->acdirmax != b->acdirmax)
1908 goto Ebusy;
1909 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1910 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001911 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001912Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001913 return 0;
1914}
1915
1916struct nfs_sb_mountdata {
1917 struct nfs_server *server;
1918 int mntflags;
1919};
1920
1921static int nfs_set_super(struct super_block *s, void *data)
1922{
1923 struct nfs_sb_mountdata *sb_mntdata = data;
1924 struct nfs_server *server = sb_mntdata->server;
1925 int ret;
1926
1927 s->s_flags = sb_mntdata->mntflags;
1928 s->s_fs_info = server;
1929 ret = set_anon_super(s, server);
1930 if (ret == 0)
1931 server->s_dev = s->s_dev;
1932 return ret;
1933}
1934
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001935static int nfs_compare_super_address(struct nfs_server *server1,
1936 struct nfs_server *server2)
1937{
1938 struct sockaddr *sap1, *sap2;
1939
1940 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1941 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1942
1943 if (sap1->sa_family != sap2->sa_family)
1944 return 0;
1945
1946 switch (sap1->sa_family) {
1947 case AF_INET: {
1948 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1949 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1950 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1951 return 0;
1952 if (sin1->sin_port != sin2->sin_port)
1953 return 0;
1954 break;
1955 }
1956 case AF_INET6: {
1957 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1958 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1959 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1960 return 0;
1961 if (sin1->sin6_port != sin2->sin6_port)
1962 return 0;
1963 break;
1964 }
1965 default:
1966 return 0;
1967 }
1968
1969 return 1;
1970}
1971
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001972static int nfs_compare_super(struct super_block *sb, void *data)
1973{
1974 struct nfs_sb_mountdata *sb_mntdata = data;
1975 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1976 int mntflags = sb_mntdata->mntflags;
1977
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001978 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001979 return 0;
1980 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1981 if (old->flags & NFS_MOUNT_UNSHARED)
1982 return 0;
1983 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1984 return 0;
1985 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001986}
1987
Miklos Szeredifa799752008-04-30 00:54:33 -07001988static int nfs_bdi_register(struct nfs_server *server)
1989{
1990 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1991}
1992
David Howells54ceac42006-08-22 20:06:13 -04001993static int nfs_get_sb(struct file_system_type *fs_type,
1994 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1995{
1996 struct nfs_server *server = NULL;
1997 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001998 struct nfs_parsed_mount_data *data;
1999 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002000 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002001 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002002 struct nfs_sb_mountdata sb_mntdata = {
2003 .mntflags = flags,
2004 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002005 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002006
Trond Myklebust33852a12008-06-19 14:20:11 -04002007 data = kzalloc(sizeof(*data), GFP_KERNEL);
2008 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2009 if (data == NULL || mntfh == NULL)
2010 goto out_free_fh;
2011
2012 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002013
David Howells54ceac42006-08-22 20:06:13 -04002014 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002015 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002016 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002017 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002018
2019 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002020 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002021 if (IS_ERR(server)) {
2022 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002023 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002024 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002025 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002026
Trond Myklebust75180df2007-05-16 16:53:28 -04002027 if (server->flags & NFS_MOUNT_UNSHARED)
2028 compare_super = NULL;
2029
David Howells54ceac42006-08-22 20:06:13 -04002030 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002031 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002032 if (IS_ERR(s)) {
2033 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002034 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002035 }
2036
David Howells54ceac42006-08-22 20:06:13 -04002037 if (s->s_fs_info != server) {
2038 nfs_free_server(server);
2039 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002040 } else {
2041 error = nfs_bdi_register(server);
2042 if (error)
2043 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002044 }
David Howells54ceac42006-08-22 20:06:13 -04002045
2046 if (!s->s_root) {
2047 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002048 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002049 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002050 }
2051
Trond Myklebust33852a12008-06-19 14:20:11 -04002052 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002053 if (IS_ERR(mntroot)) {
2054 error = PTR_ERR(mntroot);
2055 goto error_splat_super;
2056 }
2057
Trond Myklebust33852a12008-06-19 14:20:11 -04002058 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002059 if (error)
2060 goto error_splat_root;
2061
David Howellsf7b422b2006-06-09 09:34:33 -04002062 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002063 mnt->mnt_sb = s;
2064 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002065 error = 0;
2066
2067out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002068 kfree(data->nfs_server.hostname);
2069 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002070 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002071 security_free_mnt_opts(&data->lsm_opts);
2072out_free_fh:
2073 kfree(mntfh);
2074 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002075 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002076
David Howells54ceac42006-08-22 20:06:13 -04002077out_err_nosb:
2078 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002079 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002080
Eric Parisf9c3a382008-03-05 14:20:18 -05002081error_splat_root:
2082 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002083error_splat_super:
2084 up_write(&s->s_umount);
2085 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002086 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002087}
2088
David Howells54ceac42006-08-22 20:06:13 -04002089/*
2090 * Destroy an NFS2/3 superblock
2091 */
David Howellsf7b422b2006-06-09 09:34:33 -04002092static void nfs_kill_super(struct super_block *s)
2093{
2094 struct nfs_server *server = NFS_SB(s);
2095
Miklos Szeredifa799752008-04-30 00:54:33 -07002096 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002097 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002098 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002099 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002100}
2101
David Howells54ceac42006-08-22 20:06:13 -04002102/*
2103 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2104 */
2105static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2106 const char *dev_name, void *raw_data,
2107 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002108{
2109 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002110 struct super_block *s;
2111 struct nfs_server *server;
2112 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002113 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002114 struct nfs_sb_mountdata sb_mntdata = {
2115 .mntflags = flags,
2116 };
David Howells54ceac42006-08-22 20:06:13 -04002117 int error;
2118
2119 dprintk("--> nfs_xdev_get_sb()\n");
2120
2121 /* create a new volume representation */
2122 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2123 if (IS_ERR(server)) {
2124 error = PTR_ERR(server);
2125 goto out_err_noserver;
2126 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002127 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002128
Trond Myklebust75180df2007-05-16 16:53:28 -04002129 if (server->flags & NFS_MOUNT_UNSHARED)
2130 compare_super = NULL;
2131
David Howells54ceac42006-08-22 20:06:13 -04002132 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002133 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002134 if (IS_ERR(s)) {
2135 error = PTR_ERR(s);
2136 goto out_err_nosb;
2137 }
2138
2139 if (s->s_fs_info != server) {
2140 nfs_free_server(server);
2141 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002142 } else {
2143 error = nfs_bdi_register(server);
2144 if (error)
2145 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002146 }
2147
2148 if (!s->s_root) {
2149 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002150 nfs_clone_super(s, data->sb);
2151 }
2152
2153 mntroot = nfs_get_root(s, data->fh);
2154 if (IS_ERR(mntroot)) {
2155 error = PTR_ERR(mntroot);
2156 goto error_splat_super;
2157 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002158 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002159 dput(mntroot);
2160 error = -ESTALE;
2161 goto error_splat_super;
2162 }
David Howells54ceac42006-08-22 20:06:13 -04002163
2164 s->s_flags |= MS_ACTIVE;
2165 mnt->mnt_sb = s;
2166 mnt->mnt_root = mntroot;
2167
Eric Parisf9c3a382008-03-05 14:20:18 -05002168 /* clone any lsm security options from the parent to the new sb */
2169 security_sb_clone_mnt_opts(data->sb, s);
2170
David Howells54ceac42006-08-22 20:06:13 -04002171 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2172 return 0;
2173
2174out_err_nosb:
2175 nfs_free_server(server);
2176out_err_noserver:
2177 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2178 return error;
2179
2180error_splat_super:
2181 up_write(&s->s_umount);
2182 deactivate_super(s);
2183 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2184 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002185}
2186
2187#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002188
2189/*
2190 * Finish setting up a cloned NFS4 superblock
2191 */
2192static void nfs4_clone_super(struct super_block *sb,
2193 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002194{
David Howells54ceac42006-08-22 20:06:13 -04002195 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2196 sb->s_blocksize = old_sb->s_blocksize;
2197 sb->s_maxbytes = old_sb->s_maxbytes;
2198 sb->s_time_gran = 1;
2199 sb->s_op = old_sb->s_op;
2200 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002201}
2202
2203/*
2204 * Set up an NFS4 superblock
2205 */
David Howells54ceac42006-08-22 20:06:13 -04002206static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002207{
David Howellsf7b422b2006-06-09 09:34:33 -04002208 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002209 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002210 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002211}
2212
David Howells54ceac42006-08-22 20:06:13 -04002213/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002214 * Validate NFSv4 mount options
2215 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002216static int nfs4_validate_mount_data(void *options,
2217 struct nfs_parsed_mount_data *args,
2218 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002219{
Chuck Lever4c568012007-12-10 14:59:28 -05002220 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002221 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002222 char *c;
2223
2224 if (data == NULL)
2225 goto out_no_data;
2226
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002227 args->rsize = NFS_MAX_FILE_IO_SIZE;
2228 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002229 args->acregmin = NFS_DEF_ACREGMIN;
2230 args->acregmax = NFS_DEF_ACREGMAX;
2231 args->acdirmin = NFS_DEF_ACDIRMIN;
2232 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002233 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002234 args->auth_flavors[0] = RPC_AUTH_UNIX;
2235 args->auth_flavor_len = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002236
Chuck Leverf0768eb2007-07-01 12:13:01 -04002237 switch (data->version) {
2238 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002239 ap = (struct sockaddr_in *)&args->nfs_server.address;
2240 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002241 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002242 if (data->host_addrlen == 0)
2243 goto out_no_address;
2244 args->nfs_server.addrlen = data->host_addrlen;
2245 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002246 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002247 if (!nfs_verify_server_address((struct sockaddr *)
2248 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002249 goto out_no_address;
2250
Chuck Lever6738b252008-06-24 16:33:54 -04002251 if (data->auth_flavourlen) {
2252 if (data->auth_flavourlen > 1)
2253 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002254 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002255 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002256 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002257 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002258 }
2259
2260 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2261 if (IS_ERR(c))
2262 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002263 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002264
2265 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2266 if (IS_ERR(c))
2267 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002268 args->nfs_server.export_path = c;
2269 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002270
2271 c = strndup_user(data->client_addr.data, 16);
2272 if (IS_ERR(c))
2273 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002274 args->client_address = c;
2275
2276 /*
2277 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2278 * can deal with.
2279 */
2280
2281 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2282 args->rsize = data->rsize;
2283 args->wsize = data->wsize;
2284 args->timeo = data->timeo;
2285 args->retrans = data->retrans;
2286 args->acregmin = data->acregmin;
2287 args->acregmax = data->acregmax;
2288 args->acdirmin = data->acdirmin;
2289 args->acdirmax = data->acdirmax;
2290 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002291 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002292
2293 break;
Chuck Lever80071222007-07-01 12:13:59 -04002294 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002295 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002296
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002297 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002298 return -EINVAL;
2299
2300 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002301 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002302 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002303
Chuck Levered596a82008-06-26 17:47:05 -04002304 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2305 args->nfs_server.port);
2306
Trond Myklebust259875e2008-07-02 14:43:47 -04002307 nfs_validate_transport_protocol(args);
2308
Chuck Lever6738b252008-06-24 16:33:54 -04002309 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002310 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002311
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002312 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002313 goto out_no_client_address;
2314
Chuck Leverdc045892008-06-23 12:36:37 -04002315 status = nfs_parse_devname(dev_name,
2316 &args->nfs_server.hostname,
2317 NFS4_MAXNAMLEN,
2318 &args->nfs_server.export_path,
2319 NFS4_MAXPATHLEN);
2320 if (status < 0)
2321 return status;
2322
Chuck Lever80071222007-07-01 12:13:59 -04002323 break;
2324 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002325 }
2326
2327 return 0;
2328
2329out_no_data:
2330 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2331 return -EINVAL;
2332
2333out_inval_auth:
2334 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2335 data->auth_flavourlen);
2336 return -EINVAL;
2337
2338out_no_address:
2339 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2340 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002341
2342out_no_client_address:
2343 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2344 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002345}
2346
2347/*
David Howells54ceac42006-08-22 20:06:13 -04002348 * Get the superblock for an NFS4 mountpoint
2349 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002350static int nfs4_get_sb(struct file_system_type *fs_type,
2351 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002352{
Trond Myklebust33852a12008-06-19 14:20:11 -04002353 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002354 struct super_block *s;
2355 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002356 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002357 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002358 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002359 struct nfs_sb_mountdata sb_mntdata = {
2360 .mntflags = flags,
2361 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002362 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002363
Trond Myklebust33852a12008-06-19 14:20:11 -04002364 data = kzalloc(sizeof(*data), GFP_KERNEL);
2365 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2366 if (data == NULL || mntfh == NULL)
2367 goto out_free_fh;
2368
2369 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002370
Chuck Leverf0768eb2007-07-01 12:13:01 -04002371 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002372 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002373 if (error < 0)
2374 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002375
David Howells54ceac42006-08-22 20:06:13 -04002376 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002377 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002378 if (IS_ERR(server)) {
2379 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002380 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002381 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002382 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002383
Trond Myklebust75180df2007-05-16 16:53:28 -04002384 if (server->flags & NFS4_MOUNT_UNSHARED)
2385 compare_super = NULL;
2386
David Howells54ceac42006-08-22 20:06:13 -04002387 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002388 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002389 if (IS_ERR(s)) {
2390 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002391 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002392 }
2393
Trond Myklebust5dd31772006-08-24 01:03:05 -04002394 if (s->s_fs_info != server) {
2395 nfs_free_server(server);
2396 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002397 } else {
2398 error = nfs_bdi_register(server);
2399 if (error)
2400 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002401 }
2402
David Howells54ceac42006-08-22 20:06:13 -04002403 if (!s->s_root) {
2404 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002405 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002406 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002407 }
David Howellsf7b422b2006-06-09 09:34:33 -04002408
Trond Myklebust33852a12008-06-19 14:20:11 -04002409 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002410 if (IS_ERR(mntroot)) {
2411 error = PTR_ERR(mntroot);
2412 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002413 }
David Howells54ceac42006-08-22 20:06:13 -04002414
Trond Myklebust33852a12008-06-19 14:20:11 -04002415 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002416 if (error)
2417 goto error_splat_root;
2418
David Howellsf7b422b2006-06-09 09:34:33 -04002419 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002420 mnt->mnt_sb = s;
2421 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002422 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002423
Chuck Lever29eb9812007-07-01 12:12:30 -04002424out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002425 kfree(data->client_address);
2426 kfree(data->nfs_server.export_path);
2427 kfree(data->nfs_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002428 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002429 security_free_mnt_opts(&data->lsm_opts);
2430out_free_fh:
2431 kfree(mntfh);
2432 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002433 return error;
David Howells54ceac42006-08-22 20:06:13 -04002434
Chuck Lever29eb9812007-07-01 12:12:30 -04002435out_free:
2436 nfs_free_server(server);
2437 goto out;
2438
Eric Paris46c8ac72008-05-02 13:42:42 -07002439error_splat_root:
2440 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002441error_splat_super:
2442 up_write(&s->s_umount);
2443 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002444 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002445}
2446
2447static void nfs4_kill_super(struct super_block *sb)
2448{
2449 struct nfs_server *server = NFS_SB(sb);
2450
Trond Myklebust515d8612008-12-23 15:21:46 -05002451 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002452 kill_anon_super(sb);
2453
2454 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002455 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002456 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002457}
2458
2459/*
David Howells54ceac42006-08-22 20:06:13 -04002460 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002461 */
David Howells54ceac42006-08-22 20:06:13 -04002462static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2463 const char *dev_name, void *raw_data,
2464 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002465{
2466 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002467 struct super_block *s;
2468 struct nfs_server *server;
2469 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002470 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002471 struct nfs_sb_mountdata sb_mntdata = {
2472 .mntflags = flags,
2473 };
David Howells54ceac42006-08-22 20:06:13 -04002474 int error;
2475
2476 dprintk("--> nfs4_xdev_get_sb()\n");
2477
2478 /* create a new volume representation */
2479 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2480 if (IS_ERR(server)) {
2481 error = PTR_ERR(server);
2482 goto out_err_noserver;
2483 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002484 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002485
Trond Myklebust75180df2007-05-16 16:53:28 -04002486 if (server->flags & NFS4_MOUNT_UNSHARED)
2487 compare_super = NULL;
2488
David Howells54ceac42006-08-22 20:06:13 -04002489 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002490 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002491 if (IS_ERR(s)) {
2492 error = PTR_ERR(s);
2493 goto out_err_nosb;
2494 }
2495
2496 if (s->s_fs_info != server) {
2497 nfs_free_server(server);
2498 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002499 } else {
2500 error = nfs_bdi_register(server);
2501 if (error)
2502 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002503 }
2504
2505 if (!s->s_root) {
2506 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002507 nfs4_clone_super(s, data->sb);
2508 }
2509
2510 mntroot = nfs4_get_root(s, data->fh);
2511 if (IS_ERR(mntroot)) {
2512 error = PTR_ERR(mntroot);
2513 goto error_splat_super;
2514 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002515 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2516 dput(mntroot);
2517 error = -ESTALE;
2518 goto error_splat_super;
2519 }
David Howells54ceac42006-08-22 20:06:13 -04002520
2521 s->s_flags |= MS_ACTIVE;
2522 mnt->mnt_sb = s;
2523 mnt->mnt_root = mntroot;
2524
Eric Paris46c8ac72008-05-02 13:42:42 -07002525 security_sb_clone_mnt_opts(data->sb, s);
2526
David Howells54ceac42006-08-22 20:06:13 -04002527 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2528 return 0;
2529
2530out_err_nosb:
2531 nfs_free_server(server);
2532out_err_noserver:
2533 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2534 return error;
2535
2536error_splat_super:
2537 up_write(&s->s_umount);
2538 deactivate_super(s);
2539 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2540 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002541}
2542
David Howells54ceac42006-08-22 20:06:13 -04002543/*
2544 * Create an NFS4 server record on referral traversal
2545 */
2546static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2547 const char *dev_name, void *raw_data,
2548 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002549{
2550 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002551 struct super_block *s;
2552 struct nfs_server *server;
2553 struct dentry *mntroot;
2554 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002555 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002556 struct nfs_sb_mountdata sb_mntdata = {
2557 .mntflags = flags,
2558 };
David Howells54ceac42006-08-22 20:06:13 -04002559 int error;
2560
2561 dprintk("--> nfs4_referral_get_sb()\n");
2562
2563 /* create a new volume representation */
2564 server = nfs4_create_referral_server(data, &mntfh);
2565 if (IS_ERR(server)) {
2566 error = PTR_ERR(server);
2567 goto out_err_noserver;
2568 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002569 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002570
Trond Myklebust75180df2007-05-16 16:53:28 -04002571 if (server->flags & NFS4_MOUNT_UNSHARED)
2572 compare_super = NULL;
2573
David Howells54ceac42006-08-22 20:06:13 -04002574 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002575 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002576 if (IS_ERR(s)) {
2577 error = PTR_ERR(s);
2578 goto out_err_nosb;
2579 }
2580
2581 if (s->s_fs_info != server) {
2582 nfs_free_server(server);
2583 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002584 } else {
2585 error = nfs_bdi_register(server);
2586 if (error)
2587 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002588 }
2589
2590 if (!s->s_root) {
2591 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002592 nfs4_fill_super(s);
2593 }
2594
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002595 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002596 if (IS_ERR(mntroot)) {
2597 error = PTR_ERR(mntroot);
2598 goto error_splat_super;
2599 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002600 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2601 dput(mntroot);
2602 error = -ESTALE;
2603 goto error_splat_super;
2604 }
David Howells54ceac42006-08-22 20:06:13 -04002605
2606 s->s_flags |= MS_ACTIVE;
2607 mnt->mnt_sb = s;
2608 mnt->mnt_root = mntroot;
2609
Eric Paris46c8ac72008-05-02 13:42:42 -07002610 security_sb_clone_mnt_opts(data->sb, s);
2611
David Howells54ceac42006-08-22 20:06:13 -04002612 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2613 return 0;
2614
2615out_err_nosb:
2616 nfs_free_server(server);
2617out_err_noserver:
2618 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2619 return error;
2620
2621error_splat_super:
2622 up_write(&s->s_umount);
2623 deactivate_super(s);
2624 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 */