blob: 87f65ae07f323ab8998fa103ec0e1e165a242777 [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];
645
646 preempt_enable();
647 }
648
649 seq_printf(m, "\n\tevents:\t");
650 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
651 seq_printf(m, "%lu ", totals.events[i]);
652 seq_printf(m, "\n\tbytes:\t");
653 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
654 seq_printf(m, "%Lu ", totals.bytes[i]);
655 seq_printf(m, "\n");
656
657 rpc_print_iostats(m, nfss->client);
658
659 return 0;
660}
661
662/*
663 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400664 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400665 */
Al Viro42faad92008-04-24 07:21:56 -0400666static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400667{
Al Viro42faad92008-04-24 07:21:56 -0400668 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400669 struct rpc_clnt *rpc;
670
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400671 /* -EIO all pending I/O */
672 rpc = server->client_acl;
673 if (!IS_ERR(rpc))
674 rpc_killall_tasks(rpc);
675 rpc = server->client;
676 if (!IS_ERR(rpc))
677 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400678}
679
680/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500681 * Sanity-check a server address provided by the mount command.
682 *
683 * Address family must be initialized, and address must not be
684 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400685 */
686static int nfs_verify_server_address(struct sockaddr *addr)
687{
688 switch (addr->sa_family) {
689 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500690 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700691 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500692 }
693 case AF_INET6: {
694 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
695 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400696 }
697 }
698
699 return 0;
700}
701
Chuck Leverce3b7e12008-06-23 12:36:53 -0400702static void nfs_parse_ipv4_address(char *string, size_t str_len,
703 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500704{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400705 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
706 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500707
Chuck Leverce3b7e12008-06-23 12:36:53 -0400708 if (str_len <= INET_ADDRSTRLEN) {
709 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
710 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500711
Chuck Leverce3b7e12008-06-23 12:36:53 -0400712 sin->sin_family = AF_INET;
713 *addr_len = sizeof(*sin);
714 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500715 return;
716 }
Chuck Lever9412b922007-12-10 14:59:21 -0500717
718 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400719 *addr_len = 0;
720}
721
722#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400723static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
724 const char *delim,
725 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400726{
727 char *p;
728 size_t len;
729
Chuck Lever5e2e7722008-10-08 15:38:10 -0400730 if ((string + str_len) == delim)
731 return 1;
732
Chuck Leverd8e77482008-06-23 12:37:01 -0400733 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400734 return 0;
735
736 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
737 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400738
739 len = (string + str_len) - delim - 1;
740 p = kstrndup(delim + 1, len, GFP_KERNEL);
741 if (p) {
742 unsigned long scope_id = 0;
743 struct net_device *dev;
744
745 dev = dev_get_by_name(&init_net, p);
746 if (dev != NULL) {
747 scope_id = dev->ifindex;
748 dev_put(dev);
749 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400750 if (strict_strtoul(p, 10, &scope_id) == 0) {
751 kfree(p);
752 return 0;
753 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400754 }
755
756 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400757
Chuck Leverd8e77482008-06-23 12:37:01 -0400758 sin6->sin6_scope_id = scope_id;
759 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400760 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400761 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400762
763 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400764}
765
Chuck Leverce3b7e12008-06-23 12:36:53 -0400766static void nfs_parse_ipv6_address(char *string, size_t str_len,
767 struct sockaddr *sap, size_t *addr_len)
768{
769 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
770 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400771 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400772
773 if (str_len <= INET6_ADDRSTRLEN) {
774 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
775 (int)str_len, string);
776
777 sin6->sin6_family = AF_INET6;
778 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400779 if (in6_pton(string, str_len, addr,
780 IPV6_SCOPE_DELIMITER, &delim) != 0) {
781 if (nfs_parse_ipv6_scope_id(string, str_len,
782 delim, sin6) != 0)
783 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400784 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400785 }
786
787 sap->sa_family = AF_UNSPEC;
788 *addr_len = 0;
789}
790#else
791static void nfs_parse_ipv6_address(char *string, size_t str_len,
792 struct sockaddr *sap, size_t *addr_len)
793{
794 sap->sa_family = AF_UNSPEC;
795 *addr_len = 0;
796}
797#endif
798
799/*
800 * Construct a sockaddr based on the contents of a string that contains
801 * an IP address in presentation format.
802 *
803 * If there is a problem constructing the new sockaddr, set the address
804 * family to AF_UNSPEC.
805 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400806void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400807 struct sockaddr *sap, size_t *addr_len)
808{
809 unsigned int i, colons;
810
811 colons = 0;
812 for (i = 0; i < str_len; i++)
813 if (string[i] == ':')
814 colons++;
815
816 if (colons >= 2)
817 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
818 else
819 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500820}
821
822/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400823 * Sanity check the NFS transport protocol.
824 *
825 */
826static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
827{
828 switch (mnt->nfs_server.protocol) {
829 case XPRT_TRANSPORT_UDP:
830 case XPRT_TRANSPORT_TCP:
831 case XPRT_TRANSPORT_RDMA:
832 break;
833 default:
834 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
835 }
836}
837
838/*
839 * For text based NFSv2/v3 mounts, the mount protocol transport default
840 * settings should depend upon the specified NFS transport.
841 */
842static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
843{
844 nfs_validate_transport_protocol(mnt);
845
846 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
847 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
848 return;
849 switch (mnt->nfs_server.protocol) {
850 case XPRT_TRANSPORT_UDP:
851 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
852 break;
853 case XPRT_TRANSPORT_TCP:
854 case XPRT_TRANSPORT_RDMA:
855 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
856 }
857}
858
859/*
Chuck Lever01060c82008-06-24 16:33:38 -0400860 * Parse the value of the 'sec=' option.
861 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400862 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400863 */
864static int nfs_parse_security_flavors(char *value,
865 struct nfs_parsed_mount_data *mnt)
866{
867 substring_t args[MAX_OPT_ARGS];
868
869 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
870
871 switch (match_token(value, nfs_secflavor_tokens, args)) {
872 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400873 mnt->auth_flavor_len = 0;
874 mnt->auth_flavors[0] = RPC_AUTH_NULL;
875 break;
876 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400877 mnt->auth_flavor_len = 0;
878 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
879 break;
880 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400881 mnt->auth_flavor_len = 1;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
883 break;
884 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400885 mnt->auth_flavor_len = 1;
886 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
887 break;
888 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400889 mnt->auth_flavor_len = 1;
890 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
891 break;
892 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400893 mnt->auth_flavor_len = 1;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
895 break;
896 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400897 mnt->auth_flavor_len = 1;
898 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
899 break;
900 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400901 mnt->auth_flavor_len = 1;
902 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
903 break;
904 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400905 mnt->auth_flavor_len = 1;
906 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
907 break;
908 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400909 mnt->auth_flavor_len = 1;
910 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
911 break;
912 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400913 mnt->auth_flavor_len = 1;
914 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
915 break;
916 default:
917 return 0;
918 }
919
920 return 1;
921}
922
Chuck Leverf45663c2008-06-24 19:28:02 -0400923static void nfs_parse_invalid_value(const char *option)
924{
925 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
926}
927
Chuck Lever01060c82008-06-24 16:33:38 -0400928/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400929 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400930 * a data structure. The whole mount string is processed; bad options are
931 * skipped as they are encountered. If there were no errors, return 1;
932 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400933 */
934static int nfs_parse_mount_options(char *raw,
935 struct nfs_parsed_mount_data *mnt)
936{
Eric Parisf9c3a382008-03-05 14:20:18 -0500937 char *p, *string, *secdata;
Chuck Leverf45663c2008-06-24 19:28:02 -0400938 int rc, sloppy = 0, errors = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400939
940 if (!raw) {
941 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
942 return 1;
943 }
944 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
945
Eric Parisf9c3a382008-03-05 14:20:18 -0500946 secdata = alloc_secdata();
947 if (!secdata)
948 goto out_nomem;
949
950 rc = security_sb_copy_data(raw, secdata);
951 if (rc)
952 goto out_security_failure;
953
954 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
955 if (rc)
956 goto out_security_failure;
957
958 free_secdata(secdata);
959
Chuck Leverbf0fd762007-07-01 12:13:44 -0400960 while ((p = strsep(&raw, ",")) != NULL) {
961 substring_t args[MAX_OPT_ARGS];
962 int option, token;
963
964 if (!*p)
965 continue;
966
967 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
968
969 token = match_token(p, nfs_mount_option_tokens, args);
970 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400971
972 /*
973 * boolean options: foo/nofoo
974 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400975 case Opt_soft:
976 mnt->flags |= NFS_MOUNT_SOFT;
977 break;
978 case Opt_hard:
979 mnt->flags &= ~NFS_MOUNT_SOFT;
980 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400981 case Opt_posix:
982 mnt->flags |= NFS_MOUNT_POSIX;
983 break;
984 case Opt_noposix:
985 mnt->flags &= ~NFS_MOUNT_POSIX;
986 break;
987 case Opt_cto:
988 mnt->flags &= ~NFS_MOUNT_NOCTO;
989 break;
990 case Opt_nocto:
991 mnt->flags |= NFS_MOUNT_NOCTO;
992 break;
993 case Opt_ac:
994 mnt->flags &= ~NFS_MOUNT_NOAC;
995 break;
996 case Opt_noac:
997 mnt->flags |= NFS_MOUNT_NOAC;
998 break;
999 case Opt_lock:
1000 mnt->flags &= ~NFS_MOUNT_NONLM;
1001 break;
1002 case Opt_nolock:
1003 mnt->flags |= NFS_MOUNT_NONLM;
1004 break;
1005 case Opt_v2:
1006 mnt->flags &= ~NFS_MOUNT_VER3;
1007 break;
1008 case Opt_v3:
1009 mnt->flags |= NFS_MOUNT_VER3;
1010 break;
1011 case Opt_udp:
1012 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001013 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001014 break;
1015 case Opt_tcp:
1016 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001017 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001018 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001019 case Opt_rdma:
1020 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1021 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001022 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001023 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001024 case Opt_acl:
1025 mnt->flags &= ~NFS_MOUNT_NOACL;
1026 break;
1027 case Opt_noacl:
1028 mnt->flags |= NFS_MOUNT_NOACL;
1029 break;
1030 case Opt_rdirplus:
1031 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1032 break;
1033 case Opt_nordirplus:
1034 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1035 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001036 case Opt_sharecache:
1037 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1038 break;
1039 case Opt_nosharecache:
1040 mnt->flags |= NFS_MOUNT_UNSHARED;
1041 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001042 case Opt_resvport:
1043 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1044 break;
1045 case Opt_noresvport:
1046 mnt->flags |= NFS_MOUNT_NORESVPORT;
1047 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001048
Chuck Leverf45663c2008-06-24 19:28:02 -04001049 /*
1050 * options that take numeric values
1051 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001052 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001053 if (match_int(args, &option) ||
1054 option < 0 || option > USHORT_MAX) {
1055 errors++;
1056 nfs_parse_invalid_value("port");
1057 } else
1058 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001059 break;
1060 case Opt_rsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001061 if (match_int(args, &option) || option < 0) {
1062 errors++;
1063 nfs_parse_invalid_value("rsize");
1064 } else
1065 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001066 break;
1067 case Opt_wsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001068 if (match_int(args, &option) || option < 0) {
1069 errors++;
1070 nfs_parse_invalid_value("wsize");
1071 } else
1072 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001073 break;
1074 case Opt_bsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001075 if (match_int(args, &option) || option < 0) {
1076 errors++;
1077 nfs_parse_invalid_value("bsize");
1078 } else
1079 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001080 break;
1081 case Opt_timeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001082 if (match_int(args, &option) || option <= 0) {
1083 errors++;
1084 nfs_parse_invalid_value("timeo");
1085 } else
1086 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001087 break;
1088 case Opt_retrans:
Chuck Leverf45663c2008-06-24 19:28:02 -04001089 if (match_int(args, &option) || option <= 0) {
1090 errors++;
1091 nfs_parse_invalid_value("retrans");
1092 } else
1093 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001094 break;
1095 case Opt_acregmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001096 if (match_int(args, &option) || option < 0) {
1097 errors++;
1098 nfs_parse_invalid_value("acregmin");
1099 } else
1100 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 break;
1102 case Opt_acregmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001103 if (match_int(args, &option) || option < 0) {
1104 errors++;
1105 nfs_parse_invalid_value("acregmax");
1106 } else
1107 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001108 break;
1109 case Opt_acdirmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001110 if (match_int(args, &option) || option < 0) {
1111 errors++;
1112 nfs_parse_invalid_value("acdirmin");
1113 } else
1114 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001115 break;
1116 case Opt_acdirmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001117 if (match_int(args, &option) || option < 0) {
1118 errors++;
1119 nfs_parse_invalid_value("acdirmax");
1120 } else
1121 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 break;
1123 case Opt_actimeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001124 if (match_int(args, &option) || option < 0) {
1125 errors++;
1126 nfs_parse_invalid_value("actimeo");
1127 } else
1128 mnt->acregmin = mnt->acregmax =
1129 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 break;
1131 case Opt_namelen:
Chuck Leverf45663c2008-06-24 19:28:02 -04001132 if (match_int(args, &option) || option < 0) {
1133 errors++;
1134 nfs_parse_invalid_value("namlen");
1135 } else
1136 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001137 break;
1138 case Opt_mountport:
Chuck Leverf45663c2008-06-24 19:28:02 -04001139 if (match_int(args, &option) ||
1140 option < 0 || option > USHORT_MAX) {
1141 errors++;
1142 nfs_parse_invalid_value("mountport");
1143 } else
1144 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001145 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001146 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001147 if (match_int(args, &option) ||
1148 option < NFS_MNT_VERSION ||
1149 option > NFS_MNT3_VERSION) {
1150 errors++;
1151 nfs_parse_invalid_value("mountvers");
1152 } else
1153 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001154 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001155 case Opt_nfsvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001156 if (match_int(args, &option)) {
1157 errors++;
1158 nfs_parse_invalid_value("nfsvers");
1159 break;
1160 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001161 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001162 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001163 mnt->flags &= ~NFS_MOUNT_VER3;
1164 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001165 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 mnt->flags |= NFS_MOUNT_VER3;
1167 break;
1168 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001169 errors++;
1170 nfs_parse_invalid_value("nfsvers");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001171 }
1172 break;
1173
Chuck Leverf45663c2008-06-24 19:28:02 -04001174 /*
1175 * options that take text values
1176 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 case Opt_sec:
1178 string = match_strdup(args);
1179 if (string == NULL)
1180 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001181 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001182 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001183 if (!rc) {
1184 errors++;
1185 dfprintk(MOUNT, "NFS: unrecognized "
1186 "security flavor\n");
1187 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 break;
1189 case Opt_proto:
1190 string = match_strdup(args);
1191 if (string == NULL)
1192 goto out_nomem;
1193 token = match_token(string,
1194 nfs_xprt_protocol_tokens, args);
1195 kfree(string);
1196
1197 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001198 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001200 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001202 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001203 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001204 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001205 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001206 case Opt_xprt_rdma:
1207 /* vector side protocols to TCP */
1208 mnt->flags |= NFS_MOUNT_TCP;
1209 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001210 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001211 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001212 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001213 errors++;
1214 dfprintk(MOUNT, "NFS: unrecognized "
1215 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 }
Tom Talpeya67d18f2009-03-11 14:37:56 -04001217 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 break;
1219 case Opt_mountproto:
1220 string = match_strdup(args);
1221 if (string == NULL)
1222 goto out_nomem;
1223 token = match_token(string,
1224 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225
1226 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001227 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001228 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001230 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001231 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001233 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001235 errors++;
1236 dfprintk(MOUNT, "NFS: unrecognized "
1237 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001238 }
1239 break;
1240 case Opt_addr:
1241 string = match_strdup(args);
1242 if (string == NULL)
1243 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001244 nfs_parse_ip_address(string, strlen(string),
1245 (struct sockaddr *)
1246 &mnt->nfs_server.address,
1247 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 kfree(string);
1249 break;
1250 case Opt_clientaddr:
1251 string = match_strdup(args);
1252 if (string == NULL)
1253 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001254 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 mnt->client_address = string;
1256 break;
Chuck Lever33832032007-12-10 14:59:13 -05001257 case Opt_mounthost:
1258 string = match_strdup(args);
1259 if (string == NULL)
1260 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001261 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001262 mnt->mount_server.hostname = string;
1263 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001264 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 string = match_strdup(args);
1266 if (string == NULL)
1267 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001268 nfs_parse_ip_address(string, strlen(string),
1269 (struct sockaddr *)
1270 &mnt->mount_server.address,
1271 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 kfree(string);
1273 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001274 case Opt_lookupcache:
1275 string = match_strdup(args);
1276 if (string == NULL)
1277 goto out_nomem;
1278 token = match_token(string,
1279 nfs_lookupcache_tokens, args);
1280 kfree(string);
1281 switch (token) {
1282 case Opt_lookupcache_all:
1283 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1284 break;
1285 case Opt_lookupcache_positive:
1286 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1287 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1288 break;
1289 case Opt_lookupcache_none:
1290 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1291 break;
1292 default:
1293 errors++;
1294 dfprintk(MOUNT, "NFS: invalid "
1295 "lookupcache argument\n");
1296 };
1297 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001298
Chuck Leverf45663c2008-06-24 19:28:02 -04001299 /*
1300 * Special options
1301 */
1302 case Opt_sloppy:
1303 sloppy = 1;
1304 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1305 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 case Opt_userspace:
1307 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001308 dfprintk(MOUNT, "NFS: ignoring mount option "
1309 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001310 break;
1311
1312 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001313 errors++;
1314 dfprintk(MOUNT, "NFS: unrecognized mount option "
1315 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 }
1317 }
1318
Chuck Leveraf904de2008-09-08 11:58:13 -04001319 if (errors > 0) {
1320 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1321 errors, (errors == 1 ? "" : "s"));
1322 if (!sloppy)
1323 return 0;
1324 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001325 return 1;
1326
1327out_nomem:
1328 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1329 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001330out_security_failure:
1331 free_secdata(secdata);
1332 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1333 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001334}
1335
1336/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001337 * Use the remote server's MOUNT service to request the NFS file handle
1338 * corresponding to the provided path.
1339 */
1340static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1341 struct nfs_fh *root_fh)
1342{
Chuck Leverc5d120f2008-12-23 15:21:35 -05001343 struct nfs_mount_request request = {
1344 .sap = (struct sockaddr *)
1345 &args->mount_server.address,
1346 .dirpath = args->nfs_server.export_path,
1347 .protocol = args->mount_server.protocol,
1348 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001349 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001350 };
Chuck Lever4c568012007-12-10 14:59:28 -05001351 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001352
1353 if (args->mount_server.version == 0) {
1354 if (args->flags & NFS_MOUNT_VER3)
1355 args->mount_server.version = NFS_MNT3_VERSION;
1356 else
1357 args->mount_server.version = NFS_MNT_VERSION;
1358 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001359 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001360
Chuck Lever33832032007-12-10 14:59:13 -05001361 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001362 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001363 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001364 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001365
Chuck Lever0076d7b2007-07-01 12:13:49 -04001366 /*
1367 * Construct the mount server's address.
1368 */
Chuck Lever4c568012007-12-10 14:59:28 -05001369 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001370 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001371 args->nfs_server.addrlen);
1372 args->mount_server.addrlen = args->nfs_server.addrlen;
1373 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001374 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001375
James Lentiniaad70002007-09-24 17:32:49 -04001376 /*
1377 * autobind will be used if mount_server.port == 0
1378 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001379 nfs_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001380
1381 /*
1382 * Now ask the mount server to map our export path
1383 * to a file handle.
1384 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001385 status = nfs_mount(&request);
Chuck Leverefd83402007-09-11 18:00:58 -04001386 if (status == 0)
1387 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001388
Chuck Lever396cee972008-06-12 12:37:49 -04001389 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Leverc5d120f2008-12-23 15:21:35 -05001390 request.hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001391 return status;
1392}
1393
Chuck Leverd1aa0822008-06-23 12:36:45 -04001394static int nfs_parse_simple_hostname(const char *dev_name,
1395 char **hostname, size_t maxnamlen,
1396 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001397{
1398 size_t len;
1399 char *colon, *comma;
1400
1401 colon = strchr(dev_name, ':');
1402 if (colon == NULL)
1403 goto out_bad_devname;
1404
1405 len = colon - dev_name;
1406 if (len > maxnamlen)
1407 goto out_hostname;
1408
1409 /* N.B. caller will free nfs_server.hostname in all cases */
1410 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1411 if (!*hostname)
1412 goto out_nomem;
1413
1414 /* kill possible hostname list: not supported */
1415 comma = strchr(*hostname, ',');
1416 if (comma != NULL) {
1417 if (comma == *hostname)
1418 goto out_bad_devname;
1419 *comma = '\0';
1420 }
1421
1422 colon++;
1423 len = strlen(colon);
1424 if (len > maxpathlen)
1425 goto out_path;
1426 *export_path = kstrndup(colon, len, GFP_KERNEL);
1427 if (!*export_path)
1428 goto out_nomem;
1429
1430 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1431 return 0;
1432
1433out_bad_devname:
1434 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1435 return -EINVAL;
1436
1437out_nomem:
1438 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1439 return -ENOMEM;
1440
1441out_hostname:
1442 dfprintk(MOUNT, "NFS: server hostname too long\n");
1443 return -ENAMETOOLONG;
1444
1445out_path:
1446 dfprintk(MOUNT, "NFS: export pathname too long\n");
1447 return -ENAMETOOLONG;
1448}
1449
1450/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001451 * Hostname has square brackets around it because it contains one or
1452 * more colons. We look for the first closing square bracket, and a
1453 * colon must follow it.
1454 */
1455static int nfs_parse_protected_hostname(const char *dev_name,
1456 char **hostname, size_t maxnamlen,
1457 char **export_path, size_t maxpathlen)
1458{
1459 size_t len;
1460 char *start, *end;
1461
1462 start = (char *)(dev_name + 1);
1463
1464 end = strchr(start, ']');
1465 if (end == NULL)
1466 goto out_bad_devname;
1467 if (*(end + 1) != ':')
1468 goto out_bad_devname;
1469
1470 len = end - start;
1471 if (len > maxnamlen)
1472 goto out_hostname;
1473
1474 /* N.B. caller will free nfs_server.hostname in all cases */
1475 *hostname = kstrndup(start, len, GFP_KERNEL);
1476 if (*hostname == NULL)
1477 goto out_nomem;
1478
1479 end += 2;
1480 len = strlen(end);
1481 if (len > maxpathlen)
1482 goto out_path;
1483 *export_path = kstrndup(end, len, GFP_KERNEL);
1484 if (!*export_path)
1485 goto out_nomem;
1486
1487 return 0;
1488
1489out_bad_devname:
1490 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1491 return -EINVAL;
1492
1493out_nomem:
1494 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1495 return -ENOMEM;
1496
1497out_hostname:
1498 dfprintk(MOUNT, "NFS: server hostname too long\n");
1499 return -ENAMETOOLONG;
1500
1501out_path:
1502 dfprintk(MOUNT, "NFS: export pathname too long\n");
1503 return -ENAMETOOLONG;
1504}
1505
1506/*
1507 * Split "dev_name" into "hostname:export_path".
1508 *
1509 * The leftmost colon demarks the split between the server's hostname
1510 * and the export path. If the hostname starts with a left square
1511 * bracket, then it may contain colons.
1512 *
1513 * Note: caller frees hostname and export path, even on error.
1514 */
1515static int nfs_parse_devname(const char *dev_name,
1516 char **hostname, size_t maxnamlen,
1517 char **export_path, size_t maxpathlen)
1518{
1519 if (*dev_name == '[')
1520 return nfs_parse_protected_hostname(dev_name,
1521 hostname, maxnamlen,
1522 export_path, maxpathlen);
1523
1524 return nfs_parse_simple_hostname(dev_name,
1525 hostname, maxnamlen,
1526 export_path, maxpathlen);
1527}
1528
1529/*
David Howells54ceac42006-08-22 20:06:13 -04001530 * Validate the NFS2/NFS3 mount data
1531 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001532 *
1533 * For option strings, user space handles the following behaviors:
1534 *
1535 * + DNS: mapping server host name to IP address ("addr=" option)
1536 *
1537 * + failure mode: how to behave if a mount request can't be handled
1538 * immediately ("fg/bg" option)
1539 *
1540 * + retry: how often to retry a mount request ("retry=" option)
1541 *
1542 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1543 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001544 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001545static int nfs_validate_mount_data(void *options,
1546 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001547 struct nfs_fh *mntfh,
1548 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001549{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001550 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001551
Chuck Lever5df36e72007-07-01 12:12:56 -04001552 if (data == NULL)
1553 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001554
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001555 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1556 args->rsize = NFS_MAX_FILE_IO_SIZE;
1557 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001558 args->acregmin = NFS_DEF_ACREGMIN;
1559 args->acregmax = NFS_DEF_ACREGMAX;
1560 args->acdirmin = NFS_DEF_ACDIRMIN;
1561 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001562 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001563 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001564 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001565 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001566
David Howellsf7b422b2006-06-09 09:34:33 -04001567 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001568 case 1:
1569 data->namlen = 0;
1570 case 2:
1571 data->bsize = 0;
1572 case 3:
1573 if (data->flags & NFS_MOUNT_VER3)
1574 goto out_no_v3;
1575 data->root.size = NFS2_FHSIZE;
1576 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1577 case 4:
1578 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1579 goto out_no_sec;
1580 case 5:
1581 memset(data->context, 0, sizeof(data->context));
1582 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001583 if (data->flags & NFS_MOUNT_VER3) {
1584 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1585 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001586 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001587 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001588 mntfh->size = NFS2_FHSIZE;
1589
Chuck Lever5df36e72007-07-01 12:12:56 -04001590
1591 memcpy(mntfh->data, data->root.data, mntfh->size);
1592 if (mntfh->size < sizeof(mntfh->data))
1593 memset(mntfh->data + mntfh->size, 0,
1594 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001595
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001596 /*
1597 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1598 * can deal with.
1599 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001600 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001601 args->rsize = data->rsize;
1602 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001603 args->timeo = data->timeo;
1604 args->retrans = data->retrans;
1605 args->acregmin = data->acregmin;
1606 args->acregmax = data->acregmax;
1607 args->acdirmin = data->acdirmin;
1608 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001609
1610 memcpy(&args->nfs_server.address, &data->addr,
1611 sizeof(data->addr));
1612 args->nfs_server.addrlen = sizeof(data->addr);
1613 if (!nfs_verify_server_address((struct sockaddr *)
1614 &args->nfs_server.address))
1615 goto out_no_address;
1616
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001617 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001618 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001619 /* N.B. caller will free nfs_server.hostname in all cases */
1620 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1621 args->namlen = data->namlen;
1622 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001623
1624 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1625 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001626 if (!args->nfs_server.hostname)
1627 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001628
1629 /*
1630 * The legacy version 6 binary mount data from userspace has a
1631 * field used only to transport selinux information into the
1632 * the kernel. To continue to support that functionality we
1633 * have a touch of selinux knowledge here in the NFS code. The
1634 * userspace code converted context=blah to just blah so we are
1635 * converting back to the full string selinux understands.
1636 */
1637 if (data->context[0]){
1638#ifdef CONFIG_SECURITY_SELINUX
1639 int rc;
1640 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1641 if (!opts_str)
1642 return -ENOMEM;
1643 strcpy(opts_str, "context=");
1644 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1645 strcat(opts_str, &data->context[0]);
1646 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1647 kfree(opts_str);
1648 if (rc)
1649 return rc;
1650#else
1651 return -EINVAL;
1652#endif
1653 }
1654
Chuck Lever5df36e72007-07-01 12:12:56 -04001655 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001656 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001657 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001658
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001659 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001660 return -EINVAL;
1661
Chuck Lever6e88e062007-09-24 15:39:50 -04001662 if (!nfs_verify_server_address((struct sockaddr *)
1663 &args->nfs_server.address))
1664 goto out_no_address;
1665
Chuck Levered596a82008-06-26 17:47:05 -04001666 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1667 args->nfs_server.port);
1668
Trond Myklebust259875e2008-07-02 14:43:47 -04001669 nfs_set_mount_transport_protocol(args);
1670
Chuck Leverdc045892008-06-23 12:36:37 -04001671 status = nfs_parse_devname(dev_name,
1672 &args->nfs_server.hostname,
1673 PAGE_SIZE,
1674 &args->nfs_server.export_path,
1675 NFS_MAXPATHLEN);
1676 if (!status)
1677 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001678
Chuck Leverdc045892008-06-23 12:36:37 -04001679 kfree(args->nfs_server.export_path);
1680 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001681
Chuck Lever136d5582007-07-01 12:13:54 -04001682 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001683 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001684
Chuck Lever136d5582007-07-01 12:13:54 -04001685 break;
1686 }
David Howellsf7b422b2006-06-09 09:34:33 -04001687 }
David Howells54ceac42006-08-22 20:06:13 -04001688
David Howellsf7b422b2006-06-09 09:34:33 -04001689#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001690 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001691 goto out_v3_not_compiled;
1692#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001693
David Howells54ceac42006-08-22 20:06:13 -04001694 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001695
1696out_no_data:
1697 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1698 return -EINVAL;
1699
1700out_no_v3:
1701 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1702 data->version);
1703 return -EINVAL;
1704
1705out_no_sec:
1706 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1707 return -EINVAL;
1708
Chuck Lever5df36e72007-07-01 12:12:56 -04001709#ifndef CONFIG_NFS_V3
1710out_v3_not_compiled:
1711 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1712 return -EPROTONOSUPPORT;
1713#endif /* !CONFIG_NFS_V3 */
1714
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001715out_nomem:
1716 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1717 return -ENOMEM;
1718
Chuck Lever5df36e72007-07-01 12:12:56 -04001719out_no_address:
1720 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1721 return -EINVAL;
1722
1723out_invalid_fh:
1724 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1725 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001726}
1727
Jeff Layton48b605f2008-06-10 15:38:39 -04001728static int
1729nfs_compare_remount_data(struct nfs_server *nfss,
1730 struct nfs_parsed_mount_data *data)
1731{
1732 if (data->flags != nfss->flags ||
1733 data->rsize != nfss->rsize ||
1734 data->wsize != nfss->wsize ||
1735 data->retrans != nfss->client->cl_timeout->to_retries ||
1736 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1737 data->acregmin != nfss->acregmin / HZ ||
1738 data->acregmax != nfss->acregmax / HZ ||
1739 data->acdirmin != nfss->acdirmin / HZ ||
1740 data->acdirmax != nfss->acdirmax / HZ ||
1741 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1742 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1743 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1744 data->nfs_server.addrlen) != 0)
1745 return -EINVAL;
1746
1747 return 0;
1748}
1749
1750static int
1751nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1752{
1753 int error;
1754 struct nfs_server *nfss = sb->s_fs_info;
1755 struct nfs_parsed_mount_data *data;
1756 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1757 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001758 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001759
1760 /*
1761 * Userspace mount programs that send binary options generally send
1762 * them populated with default values. We have no way to know which
1763 * ones were explicitly specified. Fall back to legacy behavior and
1764 * just return success.
1765 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001766 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1767 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1768 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001769 return 0;
1770
1771 data = kzalloc(sizeof(*data), GFP_KERNEL);
1772 if (data == NULL)
1773 return -ENOMEM;
1774
1775 /* fill out struct with values from existing mount */
1776 data->flags = nfss->flags;
1777 data->rsize = nfss->rsize;
1778 data->wsize = nfss->wsize;
1779 data->retrans = nfss->client->cl_timeout->to_retries;
1780 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1781 data->acregmin = nfss->acregmin / HZ;
1782 data->acregmax = nfss->acregmax / HZ;
1783 data->acdirmin = nfss->acdirmin / HZ;
1784 data->acdirmax = nfss->acdirmax / HZ;
1785 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1786 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1787 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1788 data->nfs_server.addrlen);
1789
1790 /* overwrite those values with any that were specified */
1791 error = nfs_parse_mount_options((char *)options, data);
1792 if (error < 0)
1793 goto out;
1794
1795 /* compare new mount options with old ones */
1796 error = nfs_compare_remount_data(nfss, data);
1797out:
1798 kfree(data);
1799 return error;
1800}
1801
David Howells54ceac42006-08-22 20:06:13 -04001802/*
1803 * Initialise the common bits of the superblock
1804 */
1805static inline void nfs_initialise_sb(struct super_block *sb)
1806{
1807 struct nfs_server *server = NFS_SB(sb);
1808
1809 sb->s_magic = NFS_SUPER_MAGIC;
1810
1811 /* We probably want something more informative here */
1812 snprintf(sb->s_id, sizeof(sb->s_id),
1813 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1814
1815 if (sb->s_blocksize == 0)
1816 sb->s_blocksize = nfs_block_bits(server->wsize,
1817 &sb->s_blocksize_bits);
1818
1819 if (server->flags & NFS_MOUNT_NOAC)
1820 sb->s_flags |= MS_SYNCHRONOUS;
1821
1822 nfs_super_set_maxbytes(sb, server->maxfilesize);
1823}
1824
1825/*
1826 * Finish setting up an NFS2/3 superblock
1827 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001828static void nfs_fill_super(struct super_block *sb,
1829 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001830{
1831 struct nfs_server *server = NFS_SB(sb);
1832
1833 sb->s_blocksize_bits = 0;
1834 sb->s_blocksize = 0;
1835 if (data->bsize)
1836 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1837
1838 if (server->flags & NFS_MOUNT_VER3) {
1839 /* The VFS shouldn't apply the umask to mode bits. We will do
1840 * so ourselves when necessary.
1841 */
1842 sb->s_flags |= MS_POSIXACL;
1843 sb->s_time_gran = 1;
1844 }
1845
1846 sb->s_op = &nfs_sops;
1847 nfs_initialise_sb(sb);
1848}
1849
1850/*
1851 * Finish setting up a cloned NFS2/3 superblock
1852 */
1853static void nfs_clone_super(struct super_block *sb,
1854 const struct super_block *old_sb)
1855{
1856 struct nfs_server *server = NFS_SB(sb);
1857
1858 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1859 sb->s_blocksize = old_sb->s_blocksize;
1860 sb->s_maxbytes = old_sb->s_maxbytes;
1861
1862 if (server->flags & NFS_MOUNT_VER3) {
1863 /* The VFS shouldn't apply the umask to mode bits. We will do
1864 * so ourselves when necessary.
1865 */
1866 sb->s_flags |= MS_POSIXACL;
1867 sb->s_time_gran = 1;
1868 }
1869
1870 sb->s_op = old_sb->s_op;
1871 nfs_initialise_sb(sb);
1872}
1873
Trond Myklebust275a5d22007-05-16 16:53:28 -04001874static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1875{
1876 const struct nfs_server *a = s->s_fs_info;
1877 const struct rpc_clnt *clnt_a = a->client;
1878 const struct rpc_clnt *clnt_b = b->client;
1879
1880 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1881 goto Ebusy;
1882 if (a->nfs_client != b->nfs_client)
1883 goto Ebusy;
1884 if (a->flags != b->flags)
1885 goto Ebusy;
1886 if (a->wsize != b->wsize)
1887 goto Ebusy;
1888 if (a->rsize != b->rsize)
1889 goto Ebusy;
1890 if (a->acregmin != b->acregmin)
1891 goto Ebusy;
1892 if (a->acregmax != b->acregmax)
1893 goto Ebusy;
1894 if (a->acdirmin != b->acdirmin)
1895 goto Ebusy;
1896 if (a->acdirmax != b->acdirmax)
1897 goto Ebusy;
1898 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1899 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001900 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001901Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001902 return 0;
1903}
1904
1905struct nfs_sb_mountdata {
1906 struct nfs_server *server;
1907 int mntflags;
1908};
1909
1910static int nfs_set_super(struct super_block *s, void *data)
1911{
1912 struct nfs_sb_mountdata *sb_mntdata = data;
1913 struct nfs_server *server = sb_mntdata->server;
1914 int ret;
1915
1916 s->s_flags = sb_mntdata->mntflags;
1917 s->s_fs_info = server;
1918 ret = set_anon_super(s, server);
1919 if (ret == 0)
1920 server->s_dev = s->s_dev;
1921 return ret;
1922}
1923
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001924static int nfs_compare_super_address(struct nfs_server *server1,
1925 struct nfs_server *server2)
1926{
1927 struct sockaddr *sap1, *sap2;
1928
1929 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1930 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1931
1932 if (sap1->sa_family != sap2->sa_family)
1933 return 0;
1934
1935 switch (sap1->sa_family) {
1936 case AF_INET: {
1937 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1938 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1939 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1940 return 0;
1941 if (sin1->sin_port != sin2->sin_port)
1942 return 0;
1943 break;
1944 }
1945 case AF_INET6: {
1946 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1947 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1948 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1949 return 0;
1950 if (sin1->sin6_port != sin2->sin6_port)
1951 return 0;
1952 break;
1953 }
1954 default:
1955 return 0;
1956 }
1957
1958 return 1;
1959}
1960
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001961static int nfs_compare_super(struct super_block *sb, void *data)
1962{
1963 struct nfs_sb_mountdata *sb_mntdata = data;
1964 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1965 int mntflags = sb_mntdata->mntflags;
1966
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001967 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001968 return 0;
1969 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1970 if (old->flags & NFS_MOUNT_UNSHARED)
1971 return 0;
1972 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1973 return 0;
1974 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001975}
1976
Miklos Szeredifa799752008-04-30 00:54:33 -07001977static int nfs_bdi_register(struct nfs_server *server)
1978{
1979 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1980}
1981
David Howells54ceac42006-08-22 20:06:13 -04001982static int nfs_get_sb(struct file_system_type *fs_type,
1983 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1984{
1985 struct nfs_server *server = NULL;
1986 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001987 struct nfs_parsed_mount_data *data;
1988 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001989 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001990 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001991 struct nfs_sb_mountdata sb_mntdata = {
1992 .mntflags = flags,
1993 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001994 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001995
Trond Myklebust33852a12008-06-19 14:20:11 -04001996 data = kzalloc(sizeof(*data), GFP_KERNEL);
1997 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1998 if (data == NULL || mntfh == NULL)
1999 goto out_free_fh;
2000
2001 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002002
David Howells54ceac42006-08-22 20:06:13 -04002003 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002004 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002005 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002006 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002007
2008 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002009 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002010 if (IS_ERR(server)) {
2011 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002012 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002013 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002014 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002015
Trond Myklebust75180df2007-05-16 16:53:28 -04002016 if (server->flags & NFS_MOUNT_UNSHARED)
2017 compare_super = NULL;
2018
David Howells54ceac42006-08-22 20:06:13 -04002019 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002020 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002021 if (IS_ERR(s)) {
2022 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002023 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002024 }
2025
David Howells54ceac42006-08-22 20:06:13 -04002026 if (s->s_fs_info != server) {
2027 nfs_free_server(server);
2028 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002029 } else {
2030 error = nfs_bdi_register(server);
2031 if (error)
2032 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002033 }
David Howells54ceac42006-08-22 20:06:13 -04002034
2035 if (!s->s_root) {
2036 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002037 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002038 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002039 }
2040
Trond Myklebust33852a12008-06-19 14:20:11 -04002041 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002042 if (IS_ERR(mntroot)) {
2043 error = PTR_ERR(mntroot);
2044 goto error_splat_super;
2045 }
2046
Trond Myklebust33852a12008-06-19 14:20:11 -04002047 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002048 if (error)
2049 goto error_splat_root;
2050
David Howellsf7b422b2006-06-09 09:34:33 -04002051 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002052 mnt->mnt_sb = s;
2053 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002054 error = 0;
2055
2056out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002057 kfree(data->nfs_server.hostname);
2058 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002059 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002060 security_free_mnt_opts(&data->lsm_opts);
2061out_free_fh:
2062 kfree(mntfh);
2063 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002064 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002065
David Howells54ceac42006-08-22 20:06:13 -04002066out_err_nosb:
2067 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002068 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002069
Eric Parisf9c3a382008-03-05 14:20:18 -05002070error_splat_root:
2071 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002072error_splat_super:
2073 up_write(&s->s_umount);
2074 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002075 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002076}
2077
David Howells54ceac42006-08-22 20:06:13 -04002078/*
2079 * Destroy an NFS2/3 superblock
2080 */
David Howellsf7b422b2006-06-09 09:34:33 -04002081static void nfs_kill_super(struct super_block *s)
2082{
2083 struct nfs_server *server = NFS_SB(s);
2084
Miklos Szeredifa799752008-04-30 00:54:33 -07002085 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002086 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002087 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002088 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002089}
2090
David Howells54ceac42006-08-22 20:06:13 -04002091/*
2092 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2093 */
2094static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2095 const char *dev_name, void *raw_data,
2096 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002097{
2098 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002099 struct super_block *s;
2100 struct nfs_server *server;
2101 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002102 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002103 struct nfs_sb_mountdata sb_mntdata = {
2104 .mntflags = flags,
2105 };
David Howells54ceac42006-08-22 20:06:13 -04002106 int error;
2107
2108 dprintk("--> nfs_xdev_get_sb()\n");
2109
2110 /* create a new volume representation */
2111 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2112 if (IS_ERR(server)) {
2113 error = PTR_ERR(server);
2114 goto out_err_noserver;
2115 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002116 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002117
Trond Myklebust75180df2007-05-16 16:53:28 -04002118 if (server->flags & NFS_MOUNT_UNSHARED)
2119 compare_super = NULL;
2120
David Howells54ceac42006-08-22 20:06:13 -04002121 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002122 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002123 if (IS_ERR(s)) {
2124 error = PTR_ERR(s);
2125 goto out_err_nosb;
2126 }
2127
2128 if (s->s_fs_info != server) {
2129 nfs_free_server(server);
2130 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002131 } else {
2132 error = nfs_bdi_register(server);
2133 if (error)
2134 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002135 }
2136
2137 if (!s->s_root) {
2138 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002139 nfs_clone_super(s, data->sb);
2140 }
2141
2142 mntroot = nfs_get_root(s, data->fh);
2143 if (IS_ERR(mntroot)) {
2144 error = PTR_ERR(mntroot);
2145 goto error_splat_super;
2146 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002147 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002148 dput(mntroot);
2149 error = -ESTALE;
2150 goto error_splat_super;
2151 }
David Howells54ceac42006-08-22 20:06:13 -04002152
2153 s->s_flags |= MS_ACTIVE;
2154 mnt->mnt_sb = s;
2155 mnt->mnt_root = mntroot;
2156
Eric Parisf9c3a382008-03-05 14:20:18 -05002157 /* clone any lsm security options from the parent to the new sb */
2158 security_sb_clone_mnt_opts(data->sb, s);
2159
David Howells54ceac42006-08-22 20:06:13 -04002160 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2161 return 0;
2162
2163out_err_nosb:
2164 nfs_free_server(server);
2165out_err_noserver:
2166 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2167 return error;
2168
2169error_splat_super:
2170 up_write(&s->s_umount);
2171 deactivate_super(s);
2172 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2173 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002174}
2175
2176#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002177
2178/*
2179 * Finish setting up a cloned NFS4 superblock
2180 */
2181static void nfs4_clone_super(struct super_block *sb,
2182 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002183{
David Howells54ceac42006-08-22 20:06:13 -04002184 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2185 sb->s_blocksize = old_sb->s_blocksize;
2186 sb->s_maxbytes = old_sb->s_maxbytes;
2187 sb->s_time_gran = 1;
2188 sb->s_op = old_sb->s_op;
2189 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002190}
2191
2192/*
2193 * Set up an NFS4 superblock
2194 */
David Howells54ceac42006-08-22 20:06:13 -04002195static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002196{
David Howellsf7b422b2006-06-09 09:34:33 -04002197 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002198 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002199 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002200}
2201
David Howells54ceac42006-08-22 20:06:13 -04002202/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002203 * Validate NFSv4 mount options
2204 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002205static int nfs4_validate_mount_data(void *options,
2206 struct nfs_parsed_mount_data *args,
2207 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002208{
Chuck Lever4c568012007-12-10 14:59:28 -05002209 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002210 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002211 char *c;
2212
2213 if (data == NULL)
2214 goto out_no_data;
2215
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002216 args->rsize = NFS_MAX_FILE_IO_SIZE;
2217 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002218 args->acregmin = NFS_DEF_ACREGMIN;
2219 args->acregmax = NFS_DEF_ACREGMAX;
2220 args->acdirmin = NFS_DEF_ACDIRMIN;
2221 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002222 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002223 args->auth_flavors[0] = RPC_AUTH_UNIX;
2224 args->auth_flavor_len = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002225
Chuck Leverf0768eb2007-07-01 12:13:01 -04002226 switch (data->version) {
2227 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002228 ap = (struct sockaddr_in *)&args->nfs_server.address;
2229 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002230 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002231 if (data->host_addrlen == 0)
2232 goto out_no_address;
2233 args->nfs_server.addrlen = data->host_addrlen;
2234 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002235 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002236 if (!nfs_verify_server_address((struct sockaddr *)
2237 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002238 goto out_no_address;
2239
Chuck Lever6738b252008-06-24 16:33:54 -04002240 if (data->auth_flavourlen) {
2241 if (data->auth_flavourlen > 1)
2242 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002243 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002244 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002245 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002246 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002247 }
2248
2249 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2250 if (IS_ERR(c))
2251 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002252 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002253
2254 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2255 if (IS_ERR(c))
2256 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002257 args->nfs_server.export_path = c;
2258 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002259
2260 c = strndup_user(data->client_addr.data, 16);
2261 if (IS_ERR(c))
2262 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002263 args->client_address = c;
2264
2265 /*
2266 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2267 * can deal with.
2268 */
2269
2270 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2271 args->rsize = data->rsize;
2272 args->wsize = data->wsize;
2273 args->timeo = data->timeo;
2274 args->retrans = data->retrans;
2275 args->acregmin = data->acregmin;
2276 args->acregmax = data->acregmax;
2277 args->acdirmin = data->acdirmin;
2278 args->acdirmax = data->acdirmax;
2279 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002280 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002281
2282 break;
Chuck Lever80071222007-07-01 12:13:59 -04002283 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002284 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002285
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002286 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002287 return -EINVAL;
2288
2289 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002290 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002291 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002292
Chuck Levered596a82008-06-26 17:47:05 -04002293 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2294 args->nfs_server.port);
2295
Trond Myklebust259875e2008-07-02 14:43:47 -04002296 nfs_validate_transport_protocol(args);
2297
Chuck Lever6738b252008-06-24 16:33:54 -04002298 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002299 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002300
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002301 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002302 goto out_no_client_address;
2303
Chuck Leverdc045892008-06-23 12:36:37 -04002304 status = nfs_parse_devname(dev_name,
2305 &args->nfs_server.hostname,
2306 NFS4_MAXNAMLEN,
2307 &args->nfs_server.export_path,
2308 NFS4_MAXPATHLEN);
2309 if (status < 0)
2310 return status;
2311
Chuck Lever80071222007-07-01 12:13:59 -04002312 break;
2313 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002314 }
2315
2316 return 0;
2317
2318out_no_data:
2319 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2320 return -EINVAL;
2321
2322out_inval_auth:
2323 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2324 data->auth_flavourlen);
2325 return -EINVAL;
2326
2327out_no_address:
2328 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2329 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002330
2331out_no_client_address:
2332 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2333 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002334}
2335
2336/*
David Howells54ceac42006-08-22 20:06:13 -04002337 * Get the superblock for an NFS4 mountpoint
2338 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002339static int nfs4_get_sb(struct file_system_type *fs_type,
2340 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002341{
Trond Myklebust33852a12008-06-19 14:20:11 -04002342 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002343 struct super_block *s;
2344 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002345 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002346 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002347 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002348 struct nfs_sb_mountdata sb_mntdata = {
2349 .mntflags = flags,
2350 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002351 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002352
Trond Myklebust33852a12008-06-19 14:20:11 -04002353 data = kzalloc(sizeof(*data), GFP_KERNEL);
2354 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2355 if (data == NULL || mntfh == NULL)
2356 goto out_free_fh;
2357
2358 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002359
Chuck Leverf0768eb2007-07-01 12:13:01 -04002360 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002361 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002362 if (error < 0)
2363 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002364
David Howells54ceac42006-08-22 20:06:13 -04002365 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002366 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002367 if (IS_ERR(server)) {
2368 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002369 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002370 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002371 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002372
Trond Myklebust75180df2007-05-16 16:53:28 -04002373 if (server->flags & NFS4_MOUNT_UNSHARED)
2374 compare_super = NULL;
2375
David Howells54ceac42006-08-22 20:06:13 -04002376 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002377 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002378 if (IS_ERR(s)) {
2379 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002380 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002381 }
2382
Trond Myklebust5dd31772006-08-24 01:03:05 -04002383 if (s->s_fs_info != server) {
2384 nfs_free_server(server);
2385 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002386 } else {
2387 error = nfs_bdi_register(server);
2388 if (error)
2389 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002390 }
2391
David Howells54ceac42006-08-22 20:06:13 -04002392 if (!s->s_root) {
2393 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002394 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002395 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002396 }
David Howellsf7b422b2006-06-09 09:34:33 -04002397
Trond Myklebust33852a12008-06-19 14:20:11 -04002398 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002399 if (IS_ERR(mntroot)) {
2400 error = PTR_ERR(mntroot);
2401 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002402 }
David Howells54ceac42006-08-22 20:06:13 -04002403
Trond Myklebust33852a12008-06-19 14:20:11 -04002404 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002405 if (error)
2406 goto error_splat_root;
2407
David Howellsf7b422b2006-06-09 09:34:33 -04002408 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002409 mnt->mnt_sb = s;
2410 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002411 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002412
Chuck Lever29eb9812007-07-01 12:12:30 -04002413out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002414 kfree(data->client_address);
2415 kfree(data->nfs_server.export_path);
2416 kfree(data->nfs_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002417 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002418 security_free_mnt_opts(&data->lsm_opts);
2419out_free_fh:
2420 kfree(mntfh);
2421 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002422 return error;
David Howells54ceac42006-08-22 20:06:13 -04002423
Chuck Lever29eb9812007-07-01 12:12:30 -04002424out_free:
2425 nfs_free_server(server);
2426 goto out;
2427
Eric Paris46c8ac72008-05-02 13:42:42 -07002428error_splat_root:
2429 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002430error_splat_super:
2431 up_write(&s->s_umount);
2432 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002433 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002434}
2435
2436static void nfs4_kill_super(struct super_block *sb)
2437{
2438 struct nfs_server *server = NFS_SB(sb);
2439
Trond Myklebust515d8612008-12-23 15:21:46 -05002440 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002441 kill_anon_super(sb);
2442
2443 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002444 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002445 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002446}
2447
2448/*
David Howells54ceac42006-08-22 20:06:13 -04002449 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002450 */
David Howells54ceac42006-08-22 20:06:13 -04002451static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2452 const char *dev_name, void *raw_data,
2453 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002454{
2455 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002456 struct super_block *s;
2457 struct nfs_server *server;
2458 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002459 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002460 struct nfs_sb_mountdata sb_mntdata = {
2461 .mntflags = flags,
2462 };
David Howells54ceac42006-08-22 20:06:13 -04002463 int error;
2464
2465 dprintk("--> nfs4_xdev_get_sb()\n");
2466
2467 /* create a new volume representation */
2468 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2469 if (IS_ERR(server)) {
2470 error = PTR_ERR(server);
2471 goto out_err_noserver;
2472 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002473 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002474
Trond Myklebust75180df2007-05-16 16:53:28 -04002475 if (server->flags & NFS4_MOUNT_UNSHARED)
2476 compare_super = NULL;
2477
David Howells54ceac42006-08-22 20:06:13 -04002478 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002479 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002480 if (IS_ERR(s)) {
2481 error = PTR_ERR(s);
2482 goto out_err_nosb;
2483 }
2484
2485 if (s->s_fs_info != server) {
2486 nfs_free_server(server);
2487 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002488 } else {
2489 error = nfs_bdi_register(server);
2490 if (error)
2491 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002492 }
2493
2494 if (!s->s_root) {
2495 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002496 nfs4_clone_super(s, data->sb);
2497 }
2498
2499 mntroot = nfs4_get_root(s, data->fh);
2500 if (IS_ERR(mntroot)) {
2501 error = PTR_ERR(mntroot);
2502 goto error_splat_super;
2503 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002504 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2505 dput(mntroot);
2506 error = -ESTALE;
2507 goto error_splat_super;
2508 }
David Howells54ceac42006-08-22 20:06:13 -04002509
2510 s->s_flags |= MS_ACTIVE;
2511 mnt->mnt_sb = s;
2512 mnt->mnt_root = mntroot;
2513
Eric Paris46c8ac72008-05-02 13:42:42 -07002514 security_sb_clone_mnt_opts(data->sb, s);
2515
David Howells54ceac42006-08-22 20:06:13 -04002516 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2517 return 0;
2518
2519out_err_nosb:
2520 nfs_free_server(server);
2521out_err_noserver:
2522 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2523 return error;
2524
2525error_splat_super:
2526 up_write(&s->s_umount);
2527 deactivate_super(s);
2528 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2529 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002530}
2531
David Howells54ceac42006-08-22 20:06:13 -04002532/*
2533 * Create an NFS4 server record on referral traversal
2534 */
2535static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2536 const char *dev_name, void *raw_data,
2537 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002538{
2539 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002540 struct super_block *s;
2541 struct nfs_server *server;
2542 struct dentry *mntroot;
2543 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002544 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002545 struct nfs_sb_mountdata sb_mntdata = {
2546 .mntflags = flags,
2547 };
David Howells54ceac42006-08-22 20:06:13 -04002548 int error;
2549
2550 dprintk("--> nfs4_referral_get_sb()\n");
2551
2552 /* create a new volume representation */
2553 server = nfs4_create_referral_server(data, &mntfh);
2554 if (IS_ERR(server)) {
2555 error = PTR_ERR(server);
2556 goto out_err_noserver;
2557 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002558 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002559
Trond Myklebust75180df2007-05-16 16:53:28 -04002560 if (server->flags & NFS4_MOUNT_UNSHARED)
2561 compare_super = NULL;
2562
David Howells54ceac42006-08-22 20:06:13 -04002563 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002564 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002565 if (IS_ERR(s)) {
2566 error = PTR_ERR(s);
2567 goto out_err_nosb;
2568 }
2569
2570 if (s->s_fs_info != server) {
2571 nfs_free_server(server);
2572 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002573 } else {
2574 error = nfs_bdi_register(server);
2575 if (error)
2576 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002577 }
2578
2579 if (!s->s_root) {
2580 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002581 nfs4_fill_super(s);
2582 }
2583
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002584 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002585 if (IS_ERR(mntroot)) {
2586 error = PTR_ERR(mntroot);
2587 goto error_splat_super;
2588 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002589 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2590 dput(mntroot);
2591 error = -ESTALE;
2592 goto error_splat_super;
2593 }
David Howells54ceac42006-08-22 20:06:13 -04002594
2595 s->s_flags |= MS_ACTIVE;
2596 mnt->mnt_sb = s;
2597 mnt->mnt_root = mntroot;
2598
Eric Paris46c8ac72008-05-02 13:42:42 -07002599 security_sb_clone_mnt_opts(data->sb, s);
2600
David Howells54ceac42006-08-22 20:06:13 -04002601 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2602 return 0;
2603
2604out_err_nosb:
2605 nfs_free_server(server);
2606out_err_noserver:
2607 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2608 return error;
2609
2610error_splat_super:
2611 up_write(&s->s_umount);
2612 deactivate_super(s);
2613 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2614 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002615}
2616
David Howells54ceac42006-08-22 20:06:13 -04002617#endif /* CONFIG_NFS_V4 */