blob: 5a8fdc791cc13dcb75e4646a4082e890bd9db875 [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040050#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040051#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080052#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040053#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040054
55#include <asm/system.h>
56#include <asm/uaccess.h>
57
58#include "nfs4_fs.h"
59#include "callback.h"
60#include "delegation.h"
61#include "iostat.h"
62#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010063#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040064
65#define NFSDBG_FACILITY NFSDBG_VFS
66
Chuck Leverbf0fd762007-07-01 12:13:44 -040067enum {
68 /* Mount options that take no arguments */
69 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040070 Opt_posix, Opt_noposix,
71 Opt_cto, Opt_nocto,
72 Opt_ac, Opt_noac,
73 Opt_lock, Opt_nolock,
74 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040075 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040076 Opt_acl, Opt_noacl,
77 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040078 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050079 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010080 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040081
82 /* Mount options that take integer arguments */
83 Opt_port,
84 Opt_rsize, Opt_wsize, Opt_bsize,
85 Opt_timeo, Opt_retrans,
86 Opt_acregmin, Opt_acregmax,
87 Opt_acdirmin, Opt_acdirmax,
88 Opt_actimeo,
89 Opt_namelen,
90 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040091 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040092 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -040093 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050096 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040097 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -040098 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +010099 Opt_fscache_uniq,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400100
Chuck Leverf45663c2008-06-24 19:28:02 -0400101 /* Special mount options */
102 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103
104 Opt_err
105};
106
Steven Whitehousea447c092008-10-13 10:46:57 +0100107static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400108 { Opt_userspace, "bg" },
109 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400110 { Opt_userspace, "retry=%s" },
111
Chuck Leverf45663c2008-06-24 19:28:02 -0400112 { Opt_sloppy, "sloppy" },
113
Chuck Leverbf0fd762007-07-01 12:13:44 -0400114 { Opt_soft, "soft" },
115 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400116 { Opt_deprecated, "intr" },
117 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400118 { Opt_posix, "posix" },
119 { Opt_noposix, "noposix" },
120 { Opt_cto, "cto" },
121 { Opt_nocto, "nocto" },
122 { Opt_ac, "ac" },
123 { Opt_noac, "noac" },
124 { Opt_lock, "lock" },
125 { Opt_nolock, "nolock" },
126 { Opt_v2, "v2" },
127 { Opt_v3, "v3" },
128 { Opt_udp, "udp" },
129 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400130 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400131 { Opt_acl, "acl" },
132 { Opt_noacl, "noacl" },
133 { Opt_rdirplus, "rdirplus" },
134 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400135 { Opt_sharecache, "sharecache" },
136 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500137 { Opt_resvport, "resvport" },
138 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100139 { Opt_fscache, "fsc" },
140 { Opt_fscache_uniq, "fsc=%s" },
141 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142
143 { Opt_port, "port=%u" },
144 { Opt_rsize, "rsize=%u" },
145 { Opt_wsize, "wsize=%u" },
146 { Opt_bsize, "bsize=%u" },
147 { Opt_timeo, "timeo=%u" },
148 { Opt_retrans, "retrans=%u" },
149 { Opt_acregmin, "acregmin=%u" },
150 { Opt_acregmax, "acregmax=%u" },
151 { Opt_acdirmin, "acdirmin=%u" },
152 { Opt_acdirmax, "acdirmax=%u" },
153 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400154 { Opt_namelen, "namlen=%u" },
155 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400156 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400157 { Opt_nfsvers, "nfsvers=%u" },
158 { Opt_nfsvers, "vers=%u" },
Mike Sager3fd5be92009-04-01 09:21:48 -0400159 { Opt_minorversion, "minorversion=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400160
161 { Opt_sec, "sec=%s" },
162 { Opt_proto, "proto=%s" },
163 { Opt_mountproto, "mountproto=%s" },
164 { Opt_addr, "addr=%s" },
165 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500166 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400167 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400168
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400169 { Opt_lookupcache, "lookupcache=%s" },
170
Chuck Leverbf0fd762007-07-01 12:13:44 -0400171 { Opt_err, NULL }
172};
173
174enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400175 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400176
177 Opt_xprt_err
178};
179
Steven Whitehousea447c092008-10-13 10:46:57 +0100180static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400181 { Opt_xprt_udp, "udp" },
182 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400183 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400184
185 { Opt_xprt_err, NULL }
186};
187
188enum {
189 Opt_sec_none, Opt_sec_sys,
190 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
191 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
192 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
193
194 Opt_sec_err
195};
196
Steven Whitehousea447c092008-10-13 10:46:57 +0100197static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198 { Opt_sec_none, "none" },
199 { Opt_sec_none, "null" },
200 { Opt_sec_sys, "sys" },
201
202 { Opt_sec_krb5, "krb5" },
203 { Opt_sec_krb5i, "krb5i" },
204 { Opt_sec_krb5p, "krb5p" },
205
206 { Opt_sec_lkey, "lkey" },
207 { Opt_sec_lkeyi, "lkeyi" },
208 { Opt_sec_lkeyp, "lkeyp" },
209
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500210 { Opt_sec_spkm, "spkm3" },
211 { Opt_sec_spkmi, "spkm3i" },
212 { Opt_sec_spkmp, "spkm3p" },
213
Chuck Leverbf0fd762007-07-01 12:13:44 -0400214 { Opt_sec_err, NULL }
215};
216
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400217enum {
218 Opt_lookupcache_all, Opt_lookupcache_positive,
219 Opt_lookupcache_none,
220
221 Opt_lookupcache_err
222};
223
224static match_table_t nfs_lookupcache_tokens = {
225 { Opt_lookupcache_all, "all" },
226 { Opt_lookupcache_positive, "pos" },
227 { Opt_lookupcache_positive, "positive" },
228 { Opt_lookupcache_none, "none" },
229
230 { Opt_lookupcache_err, NULL }
231};
232
Chuck Leverbf0fd762007-07-01 12:13:44 -0400233
Al Viro42faad92008-04-24 07:21:56 -0400234static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400235static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400236static int nfs_show_options(struct seq_file *, struct vfsmount *);
237static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400238static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400239static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400240 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400241static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400242static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400243
244static struct file_system_type nfs_fs_type = {
245 .owner = THIS_MODULE,
246 .name = "nfs",
247 .get_sb = nfs_get_sb,
248 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700249 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400250};
251
David Howells54ceac42006-08-22 20:06:13 -0400252struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400253 .owner = THIS_MODULE,
254 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400255 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400256 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700257 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400258};
259
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800260static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400261 .alloc_inode = nfs_alloc_inode,
262 .destroy_inode = nfs_destroy_inode,
263 .write_inode = nfs_write_inode,
264 .statfs = nfs_statfs,
265 .clear_inode = nfs_clear_inode,
266 .umount_begin = nfs_umount_begin,
267 .show_options = nfs_show_options,
268 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400269 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400270};
271
272#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400273static int nfs4_get_sb(struct file_system_type *fs_type,
274 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400275static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
277static int nfs4_referral_get_sb(struct file_system_type *fs_type,
278 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400279static void nfs4_kill_super(struct super_block *sb);
280
281static struct file_system_type nfs4_fs_type = {
282 .owner = THIS_MODULE,
283 .name = "nfs4",
284 .get_sb = nfs4_get_sb,
285 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700286 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400287};
288
David Howells54ceac42006-08-22 20:06:13 -0400289struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400290 .owner = THIS_MODULE,
291 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400292 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400293 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700294 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400295};
296
David Howells54ceac42006-08-22 20:06:13 -0400297struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400298 .owner = THIS_MODULE,
299 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400300 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400301 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400303};
304
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800305static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400306 .alloc_inode = nfs_alloc_inode,
307 .destroy_inode = nfs_destroy_inode,
308 .write_inode = nfs_write_inode,
309 .statfs = nfs_statfs,
310 .clear_inode = nfs4_clear_inode,
311 .umount_begin = nfs_umount_begin,
312 .show_options = nfs_show_options,
313 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400314 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400315};
316#endif
317
Rusty Russell8e1f9362007-07-17 04:03:17 -0700318static struct shrinker acl_shrinker = {
319 .shrink = nfs_access_cache_shrinker,
320 .seeks = DEFAULT_SEEKS,
321};
Trond Myklebust979df722006-07-25 11:28:19 -0400322
David Howellsf7b422b2006-06-09 09:34:33 -0400323/*
324 * Register the NFS filesystems
325 */
326int __init register_nfs_fs(void)
327{
328 int ret;
329
330 ret = register_filesystem(&nfs_fs_type);
331 if (ret < 0)
332 goto error_0;
333
David Howellsf7b422b2006-06-09 09:34:33 -0400334 ret = nfs_register_sysctl();
335 if (ret < 0)
336 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800337#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400338 ret = register_filesystem(&nfs4_fs_type);
339 if (ret < 0)
340 goto error_2;
341#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700342 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400343 return 0;
344
345#ifdef CONFIG_NFS_V4
346error_2:
347 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800348#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400349error_1:
350 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400351error_0:
352 return ret;
353}
354
355/*
356 * Unregister the NFS filesystems
357 */
358void __exit unregister_nfs_fs(void)
359{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700360 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400361#ifdef CONFIG_NFS_V4
362 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400363#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700364 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400365 unregister_filesystem(&nfs_fs_type);
366}
367
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400368void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500369{
370 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400371
372 if (atomic_inc_return(&server->active) == 1)
373 atomic_inc(&sb->s_active);
374}
375
376void nfs_sb_deactive(struct super_block *sb)
377{
378 struct nfs_server *server = NFS_SB(sb);
379
380 if (atomic_dec_and_test(&server->active))
381 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500382}
383
David Howellsf7b422b2006-06-09 09:34:33 -0400384/*
385 * Deliver file system statistics to userspace
386 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400387static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400388{
David Howells0c7d90c2006-08-22 20:06:10 -0400389 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400390 unsigned char blockbits;
391 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400392 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400393 struct nfs_fattr fattr;
394 struct nfs_fsstat res = {
395 .fattr = &fattr,
396 };
397 int error;
398
David Howells8fa5c002006-08-22 20:06:12 -0400399 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400400 if (error < 0)
401 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700402 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400403
404 /*
405 * Current versions of glibc do not correctly handle the
406 * case where f_frsize != f_bsize. Eventually we want to
407 * report the value of wtmult in this field.
408 */
David Howells0c7d90c2006-08-22 20:06:10 -0400409 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400410
411 /*
412 * On most *nix systems, f_blocks, f_bfree, and f_bavail
413 * are reported in units of f_frsize. Linux hasn't had
414 * an f_frsize field in its statfs struct until recently,
415 * thus historically Linux's sys_statfs reports these
416 * fields in units of f_bsize.
417 */
David Howells0c7d90c2006-08-22 20:06:10 -0400418 buf->f_bsize = dentry->d_sb->s_blocksize;
419 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400420 blockres = (1 << blockbits) - 1;
421 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
422 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
423 buf->f_bavail = (res.abytes + blockres) >> blockbits;
424
425 buf->f_files = res.tfiles;
426 buf->f_ffree = res.afiles;
427
428 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700429
David Howellsf7b422b2006-06-09 09:34:33 -0400430 return 0;
431
432 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700433 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700434 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400435}
436
David Howells7d4e2742006-08-22 20:06:07 -0400437/*
438 * Map the security flavour number to a name
439 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400440static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
441{
David Howells7d4e2742006-08-22 20:06:07 -0400442 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400443 rpc_authflavor_t flavour;
444 const char *str;
445 } sec_flavours[] = {
446 { RPC_AUTH_NULL, "null" },
447 { RPC_AUTH_UNIX, "sys" },
448 { RPC_AUTH_GSS_KRB5, "krb5" },
449 { RPC_AUTH_GSS_KRB5I, "krb5i" },
450 { RPC_AUTH_GSS_KRB5P, "krb5p" },
451 { RPC_AUTH_GSS_LKEY, "lkey" },
452 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
453 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
454 { RPC_AUTH_GSS_SPKM, "spkm" },
455 { RPC_AUTH_GSS_SPKMI, "spkmi" },
456 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400457 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400458 };
459 int i;
460
Chuck Lever4d81cd12007-07-01 12:12:40 -0400461 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400462 if (sec_flavours[i].flavour == flavour)
463 break;
464 }
465 return sec_flavours[i].str;
466}
467
Chuck Lever82d101d2008-03-14 14:10:37 -0400468static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
469 int showdefaults)
470{
471 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
472
473 switch (sap->sa_family) {
474 case AF_INET: {
475 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700476 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400477 break;
478 }
479 case AF_INET6: {
480 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700481 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400482 break;
483 }
484 default:
485 if (showdefaults)
486 seq_printf(m, ",mountaddr=unspecified");
487 }
488
489 if (nfss->mountd_version || showdefaults)
490 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
491 if (nfss->mountd_port || showdefaults)
492 seq_printf(m, ",mountport=%u", nfss->mountd_port);
493
494 switch (nfss->mountd_protocol) {
495 case IPPROTO_UDP:
496 seq_printf(m, ",mountproto=udp");
497 break;
498 case IPPROTO_TCP:
499 seq_printf(m, ",mountproto=tcp");
500 break;
501 default:
502 if (showdefaults)
503 seq_printf(m, ",mountproto=auto");
504 }
505}
506
David Howellsf7b422b2006-06-09 09:34:33 -0400507/*
508 * Describe the mount options in force on this server representation
509 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400510static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
511 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400512{
David Howells509de812006-08-22 20:06:11 -0400513 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400514 int flag;
David Howells509de812006-08-22 20:06:11 -0400515 const char *str;
516 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400517 } nfs_info[] = {
518 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400519 { NFS_MOUNT_INTR, ",intr", ",nointr" },
520 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400521 { NFS_MOUNT_NOCTO, ",nocto", "" },
522 { NFS_MOUNT_NOAC, ",noac", "" },
523 { NFS_MOUNT_NONLM, ",nolock", "" },
524 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400525 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500526 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
527 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400528 { 0, NULL, NULL }
529 };
David Howells509de812006-08-22 20:06:11 -0400530 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400531 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400532 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400533
Chuck Lever82d101d2008-03-14 14:10:37 -0400534 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400535 seq_printf(m, ",rsize=%u", nfss->rsize);
536 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400537 if (nfss->bsize != 0)
538 seq_printf(m, ",bsize=%u", nfss->bsize);
539 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400540 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400541 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400542 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400543 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400544 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400545 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400546 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400547 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400548 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
549 if (nfss->flags & nfs_infop->flag)
550 seq_puts(m, nfs_infop->str);
551 else
552 seq_puts(m, nfs_infop->nostr);
553 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400554 seq_printf(m, ",proto=%s",
555 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400556 if (version == 4) {
557 if (nfss->port != NFS_PORT)
558 seq_printf(m, ",port=%u", nfss->port);
559 } else
560 if (nfss->port)
561 seq_printf(m, ",port=%u", nfss->port);
562
Trond Myklebust33170232007-12-20 16:03:59 -0500563 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
564 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400565 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400566
567 if (version != 4)
568 nfs_show_mountd_options(m, nfss, showdefaults);
569
570#ifdef CONFIG_NFS_V4
571 if (clp->rpc_ops->version == 4)
572 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
573#endif
David Howellsb797cac2009-04-03 16:42:48 +0100574 if (nfss->options & NFS_OPTION_FSCACHE)
575 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400576}
577
578/*
579 * Describe the mount options on this VFS mountpoint
580 */
581static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
582{
583 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
584
585 nfs_show_mount_options(m, nfss, 0);
586
Chuck Lever5d8515c2007-12-10 14:57:16 -0500587 seq_printf(m, ",addr=%s",
588 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
589 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400590
591 return 0;
592}
593
594/*
595 * Present statistical information for this VFS mountpoint
596 */
597static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
598{
599 int i, cpu;
600 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
601 struct rpc_auth *auth = nfss->client->cl_auth;
602 struct nfs_iostats totals = { };
603
604 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
605
606 /*
607 * Display all mount option settings
608 */
609 seq_printf(m, "\n\topts:\t");
610 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
611 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
612 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
613 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
614 nfs_show_mount_options(m, nfss, 1);
615
616 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
617
618 seq_printf(m, "\n\tcaps:\t");
619 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400620 seq_printf(m, ",wtmult=%u", nfss->wtmult);
621 seq_printf(m, ",dtsize=%u", nfss->dtsize);
622 seq_printf(m, ",bsize=%u", nfss->bsize);
623 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400624
625#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500626 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400627 seq_printf(m, "\n\tnfsv4:\t");
628 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
629 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
630 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
631 }
632#endif
633
634 /*
635 * Display security flavor in effect for this mount
636 */
Chuck Lever2d767432008-03-14 14:10:08 -0400637 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400638 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400639 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400640
641 /*
642 * Display superblock I/O counters
643 */
644 for_each_possible_cpu(cpu) {
645 struct nfs_iostats *stats;
646
647 preempt_disable();
648 stats = per_cpu_ptr(nfss->io_stats, cpu);
649
650 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
651 totals.events[i] += stats->events[i];
652 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
653 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100654#ifdef CONFIG_NFS_FSCACHE
655 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
656 totals.fscache[i] += stats->fscache[i];
657#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400658
659 preempt_enable();
660 }
661
662 seq_printf(m, "\n\tevents:\t");
663 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
664 seq_printf(m, "%lu ", totals.events[i]);
665 seq_printf(m, "\n\tbytes:\t");
666 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
667 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100668#ifdef CONFIG_NFS_FSCACHE
669 if (nfss->options & NFS_OPTION_FSCACHE) {
670 seq_printf(m, "\n\tfsc:\t");
671 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
672 seq_printf(m, "%Lu ", totals.bytes[i]);
673 }
674#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400675 seq_printf(m, "\n");
676
677 rpc_print_iostats(m, nfss->client);
678
679 return 0;
680}
681
682/*
683 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400684 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400685 */
Al Viro42faad92008-04-24 07:21:56 -0400686static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400687{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200688 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400689 struct rpc_clnt *rpc;
690
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200691 lock_kernel();
692
693 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400694 /* -EIO all pending I/O */
695 rpc = server->client_acl;
696 if (!IS_ERR(rpc))
697 rpc_killall_tasks(rpc);
698 rpc = server->client;
699 if (!IS_ERR(rpc))
700 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200701
702 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400703}
704
705/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500706 * Sanity-check a server address provided by the mount command.
707 *
708 * Address family must be initialized, and address must not be
709 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400710 */
711static int nfs_verify_server_address(struct sockaddr *addr)
712{
713 switch (addr->sa_family) {
714 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500715 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700716 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500717 }
718 case AF_INET6: {
719 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
720 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400721 }
722 }
723
724 return 0;
725}
726
Chuck Leverce3b7e12008-06-23 12:36:53 -0400727static void nfs_parse_ipv4_address(char *string, size_t str_len,
728 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500729{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400730 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
731 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500732
Chuck Leverce3b7e12008-06-23 12:36:53 -0400733 if (str_len <= INET_ADDRSTRLEN) {
734 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
735 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500736
Chuck Leverce3b7e12008-06-23 12:36:53 -0400737 sin->sin_family = AF_INET;
738 *addr_len = sizeof(*sin);
739 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500740 return;
741 }
Chuck Lever9412b922007-12-10 14:59:21 -0500742
743 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400744 *addr_len = 0;
745}
746
747#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400748static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
749 const char *delim,
750 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400751{
752 char *p;
753 size_t len;
754
Chuck Lever5e2e7722008-10-08 15:38:10 -0400755 if ((string + str_len) == delim)
756 return 1;
757
Chuck Leverd8e77482008-06-23 12:37:01 -0400758 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400759 return 0;
760
761 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
762 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400763
764 len = (string + str_len) - delim - 1;
765 p = kstrndup(delim + 1, len, GFP_KERNEL);
766 if (p) {
767 unsigned long scope_id = 0;
768 struct net_device *dev;
769
770 dev = dev_get_by_name(&init_net, p);
771 if (dev != NULL) {
772 scope_id = dev->ifindex;
773 dev_put(dev);
774 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400775 if (strict_strtoul(p, 10, &scope_id) == 0) {
776 kfree(p);
777 return 0;
778 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400779 }
780
781 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400782
Chuck Leverd8e77482008-06-23 12:37:01 -0400783 sin6->sin6_scope_id = scope_id;
784 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400785 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400786 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400787
788 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400789}
790
Chuck Leverce3b7e12008-06-23 12:36:53 -0400791static void nfs_parse_ipv6_address(char *string, size_t str_len,
792 struct sockaddr *sap, size_t *addr_len)
793{
794 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
795 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400796 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400797
798 if (str_len <= INET6_ADDRSTRLEN) {
799 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
800 (int)str_len, string);
801
802 sin6->sin6_family = AF_INET6;
803 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400804 if (in6_pton(string, str_len, addr,
805 IPV6_SCOPE_DELIMITER, &delim) != 0) {
806 if (nfs_parse_ipv6_scope_id(string, str_len,
807 delim, sin6) != 0)
808 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400809 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400810 }
811
812 sap->sa_family = AF_UNSPEC;
813 *addr_len = 0;
814}
815#else
816static void nfs_parse_ipv6_address(char *string, size_t str_len,
817 struct sockaddr *sap, size_t *addr_len)
818{
819 sap->sa_family = AF_UNSPEC;
820 *addr_len = 0;
821}
822#endif
823
824/*
825 * Construct a sockaddr based on the contents of a string that contains
826 * an IP address in presentation format.
827 *
828 * If there is a problem constructing the new sockaddr, set the address
829 * family to AF_UNSPEC.
830 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400831void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400832 struct sockaddr *sap, size_t *addr_len)
833{
834 unsigned int i, colons;
835
836 colons = 0;
837 for (i = 0; i < str_len; i++)
838 if (string[i] == ':')
839 colons++;
840
841 if (colons >= 2)
842 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
843 else
844 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500845}
846
847/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400848 * Sanity check the NFS transport protocol.
849 *
850 */
851static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
852{
853 switch (mnt->nfs_server.protocol) {
854 case XPRT_TRANSPORT_UDP:
855 case XPRT_TRANSPORT_TCP:
856 case XPRT_TRANSPORT_RDMA:
857 break;
858 default:
859 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
860 }
861}
862
863/*
864 * For text based NFSv2/v3 mounts, the mount protocol transport default
865 * settings should depend upon the specified NFS transport.
866 */
867static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
868{
869 nfs_validate_transport_protocol(mnt);
870
871 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
872 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
873 return;
874 switch (mnt->nfs_server.protocol) {
875 case XPRT_TRANSPORT_UDP:
876 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
877 break;
878 case XPRT_TRANSPORT_TCP:
879 case XPRT_TRANSPORT_RDMA:
880 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
881 }
882}
883
884/*
Chuck Lever01060c82008-06-24 16:33:38 -0400885 * Parse the value of the 'sec=' option.
886 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400887 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400888 */
889static int nfs_parse_security_flavors(char *value,
890 struct nfs_parsed_mount_data *mnt)
891{
892 substring_t args[MAX_OPT_ARGS];
893
894 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
895
896 switch (match_token(value, nfs_secflavor_tokens, args)) {
897 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400898 mnt->auth_flavor_len = 0;
899 mnt->auth_flavors[0] = RPC_AUTH_NULL;
900 break;
901 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400902 mnt->auth_flavor_len = 0;
903 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
904 break;
905 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400906 mnt->auth_flavor_len = 1;
907 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
908 break;
909 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400910 mnt->auth_flavor_len = 1;
911 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
912 break;
913 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400914 mnt->auth_flavor_len = 1;
915 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
916 break;
917 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400918 mnt->auth_flavor_len = 1;
919 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
920 break;
921 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400922 mnt->auth_flavor_len = 1;
923 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
924 break;
925 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400926 mnt->auth_flavor_len = 1;
927 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
928 break;
929 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400930 mnt->auth_flavor_len = 1;
931 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
932 break;
933 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400934 mnt->auth_flavor_len = 1;
935 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
936 break;
937 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400938 mnt->auth_flavor_len = 1;
939 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
940 break;
941 default:
942 return 0;
943 }
944
945 return 1;
946}
947
Chuck Leverf45663c2008-06-24 19:28:02 -0400948static void nfs_parse_invalid_value(const char *option)
949{
950 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
951}
952
Chuck Lever01060c82008-06-24 16:33:38 -0400953/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400954 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400955 * a data structure. The whole mount string is processed; bad options are
956 * skipped as they are encountered. If there were no errors, return 1;
957 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958 */
959static int nfs_parse_mount_options(char *raw,
960 struct nfs_parsed_mount_data *mnt)
961{
Eric Parisf9c3a382008-03-05 14:20:18 -0500962 char *p, *string, *secdata;
Chuck Leverf45663c2008-06-24 19:28:02 -0400963 int rc, sloppy = 0, errors = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400964
965 if (!raw) {
966 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
967 return 1;
968 }
969 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
970
Eric Parisf9c3a382008-03-05 14:20:18 -0500971 secdata = alloc_secdata();
972 if (!secdata)
973 goto out_nomem;
974
975 rc = security_sb_copy_data(raw, secdata);
976 if (rc)
977 goto out_security_failure;
978
979 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
980 if (rc)
981 goto out_security_failure;
982
983 free_secdata(secdata);
984
Chuck Leverbf0fd762007-07-01 12:13:44 -0400985 while ((p = strsep(&raw, ",")) != NULL) {
986 substring_t args[MAX_OPT_ARGS];
987 int option, token;
988
989 if (!*p)
990 continue;
991
992 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
993
994 token = match_token(p, nfs_mount_option_tokens, args);
995 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400996
997 /*
998 * boolean options: foo/nofoo
999 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 case Opt_soft:
1001 mnt->flags |= NFS_MOUNT_SOFT;
1002 break;
1003 case Opt_hard:
1004 mnt->flags &= ~NFS_MOUNT_SOFT;
1005 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001006 case Opt_posix:
1007 mnt->flags |= NFS_MOUNT_POSIX;
1008 break;
1009 case Opt_noposix:
1010 mnt->flags &= ~NFS_MOUNT_POSIX;
1011 break;
1012 case Opt_cto:
1013 mnt->flags &= ~NFS_MOUNT_NOCTO;
1014 break;
1015 case Opt_nocto:
1016 mnt->flags |= NFS_MOUNT_NOCTO;
1017 break;
1018 case Opt_ac:
1019 mnt->flags &= ~NFS_MOUNT_NOAC;
1020 break;
1021 case Opt_noac:
1022 mnt->flags |= NFS_MOUNT_NOAC;
1023 break;
1024 case Opt_lock:
1025 mnt->flags &= ~NFS_MOUNT_NONLM;
1026 break;
1027 case Opt_nolock:
1028 mnt->flags |= NFS_MOUNT_NONLM;
1029 break;
1030 case Opt_v2:
1031 mnt->flags &= ~NFS_MOUNT_VER3;
1032 break;
1033 case Opt_v3:
1034 mnt->flags |= NFS_MOUNT_VER3;
1035 break;
1036 case Opt_udp:
1037 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001038 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001039 break;
1040 case Opt_tcp:
1041 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001042 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001043 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001044 case Opt_rdma:
1045 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1046 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001047 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001048 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001049 case Opt_acl:
1050 mnt->flags &= ~NFS_MOUNT_NOACL;
1051 break;
1052 case Opt_noacl:
1053 mnt->flags |= NFS_MOUNT_NOACL;
1054 break;
1055 case Opt_rdirplus:
1056 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1057 break;
1058 case Opt_nordirplus:
1059 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1060 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001061 case Opt_sharecache:
1062 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1063 break;
1064 case Opt_nosharecache:
1065 mnt->flags |= NFS_MOUNT_UNSHARED;
1066 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001067 case Opt_resvport:
1068 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1069 break;
1070 case Opt_noresvport:
1071 mnt->flags |= NFS_MOUNT_NORESVPORT;
1072 break;
David Howellsb797cac2009-04-03 16:42:48 +01001073 case Opt_fscache:
1074 mnt->options |= NFS_OPTION_FSCACHE;
1075 kfree(mnt->fscache_uniq);
1076 mnt->fscache_uniq = NULL;
1077 break;
1078 case Opt_nofscache:
1079 mnt->options &= ~NFS_OPTION_FSCACHE;
1080 kfree(mnt->fscache_uniq);
1081 mnt->fscache_uniq = NULL;
1082 break;
1083 case Opt_fscache_uniq:
1084 string = match_strdup(args);
1085 if (!string)
1086 goto out_nomem;
1087 kfree(mnt->fscache_uniq);
1088 mnt->fscache_uniq = string;
1089 mnt->options |= NFS_OPTION_FSCACHE;
1090 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001091
Chuck Leverf45663c2008-06-24 19:28:02 -04001092 /*
1093 * options that take numeric values
1094 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001095 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001096 if (match_int(args, &option) ||
1097 option < 0 || option > USHORT_MAX) {
1098 errors++;
1099 nfs_parse_invalid_value("port");
1100 } else
1101 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001102 break;
1103 case Opt_rsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001104 if (match_int(args, &option) || option < 0) {
1105 errors++;
1106 nfs_parse_invalid_value("rsize");
1107 } else
1108 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001109 break;
1110 case Opt_wsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001111 if (match_int(args, &option) || option < 0) {
1112 errors++;
1113 nfs_parse_invalid_value("wsize");
1114 } else
1115 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001116 break;
1117 case Opt_bsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001118 if (match_int(args, &option) || option < 0) {
1119 errors++;
1120 nfs_parse_invalid_value("bsize");
1121 } else
1122 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001123 break;
1124 case Opt_timeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001125 if (match_int(args, &option) || option <= 0) {
1126 errors++;
1127 nfs_parse_invalid_value("timeo");
1128 } else
1129 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 break;
1131 case Opt_retrans:
Chuck Leverf45663c2008-06-24 19:28:02 -04001132 if (match_int(args, &option) || option <= 0) {
1133 errors++;
1134 nfs_parse_invalid_value("retrans");
1135 } else
1136 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001137 break;
1138 case Opt_acregmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001139 if (match_int(args, &option) || option < 0) {
1140 errors++;
1141 nfs_parse_invalid_value("acregmin");
1142 } else
1143 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001144 break;
1145 case Opt_acregmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001146 if (match_int(args, &option) || option < 0) {
1147 errors++;
1148 nfs_parse_invalid_value("acregmax");
1149 } else
1150 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001151 break;
1152 case Opt_acdirmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001153 if (match_int(args, &option) || option < 0) {
1154 errors++;
1155 nfs_parse_invalid_value("acdirmin");
1156 } else
1157 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001158 break;
1159 case Opt_acdirmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001160 if (match_int(args, &option) || option < 0) {
1161 errors++;
1162 nfs_parse_invalid_value("acdirmax");
1163 } else
1164 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 break;
1166 case Opt_actimeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001167 if (match_int(args, &option) || option < 0) {
1168 errors++;
1169 nfs_parse_invalid_value("actimeo");
1170 } else
1171 mnt->acregmin = mnt->acregmax =
1172 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001173 break;
1174 case Opt_namelen:
Chuck Leverf45663c2008-06-24 19:28:02 -04001175 if (match_int(args, &option) || option < 0) {
1176 errors++;
1177 nfs_parse_invalid_value("namlen");
1178 } else
1179 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 break;
1181 case Opt_mountport:
Chuck Leverf45663c2008-06-24 19:28:02 -04001182 if (match_int(args, &option) ||
1183 option < 0 || option > USHORT_MAX) {
1184 errors++;
1185 nfs_parse_invalid_value("mountport");
1186 } else
1187 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001190 if (match_int(args, &option) ||
1191 option < NFS_MNT_VERSION ||
1192 option > NFS_MNT3_VERSION) {
1193 errors++;
1194 nfs_parse_invalid_value("mountvers");
1195 } else
1196 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001197 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001198 case Opt_nfsvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001199 if (match_int(args, &option)) {
1200 errors++;
1201 nfs_parse_invalid_value("nfsvers");
1202 break;
1203 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001205 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 mnt->flags &= ~NFS_MOUNT_VER3;
1207 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001208 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 mnt->flags |= NFS_MOUNT_VER3;
1210 break;
1211 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001212 errors++;
1213 nfs_parse_invalid_value("nfsvers");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 }
1215 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001216 case Opt_minorversion:
1217 if (match_int(args, &option))
1218 return 0;
1219 if (option < 0 || option > NFS4_MAX_MINOR_VERSION)
1220 return 0;
1221 mnt->minorversion = option;
1222 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001223
Chuck Leverf45663c2008-06-24 19:28:02 -04001224 /*
1225 * options that take text values
1226 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227 case Opt_sec:
1228 string = match_strdup(args);
1229 if (string == NULL)
1230 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001231 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001233 if (!rc) {
1234 errors++;
1235 dfprintk(MOUNT, "NFS: unrecognized "
1236 "security flavor\n");
1237 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001238 break;
1239 case Opt_proto:
1240 string = match_strdup(args);
1241 if (string == NULL)
1242 goto out_nomem;
1243 token = match_token(string,
1244 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245
1246 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001247 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001249 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001250 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001251 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001253 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001255 case Opt_xprt_rdma:
1256 /* vector side protocols to TCP */
1257 mnt->flags |= NFS_MOUNT_TCP;
1258 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001259 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001260 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001262 errors++;
1263 dfprintk(MOUNT, "NFS: unrecognized "
1264 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001265 }
Tom Talpeya67d18f2009-03-11 14:37:56 -04001266 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 break;
1268 case Opt_mountproto:
1269 string = match_strdup(args);
1270 if (string == NULL)
1271 goto out_nomem;
1272 token = match_token(string,
1273 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001274 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275
1276 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001277 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001278 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001279 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001280 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001281 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001283 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001284 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001285 errors++;
1286 dfprintk(MOUNT, "NFS: unrecognized "
1287 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288 }
1289 break;
1290 case Opt_addr:
1291 string = match_strdup(args);
1292 if (string == NULL)
1293 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001294 nfs_parse_ip_address(string, strlen(string),
1295 (struct sockaddr *)
1296 &mnt->nfs_server.address,
1297 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001298 kfree(string);
1299 break;
1300 case Opt_clientaddr:
1301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001304 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001305 mnt->client_address = string;
1306 break;
Chuck Lever33832032007-12-10 14:59:13 -05001307 case Opt_mounthost:
1308 string = match_strdup(args);
1309 if (string == NULL)
1310 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001311 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001312 mnt->mount_server.hostname = string;
1313 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001314 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001315 string = match_strdup(args);
1316 if (string == NULL)
1317 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001318 nfs_parse_ip_address(string, strlen(string),
1319 (struct sockaddr *)
1320 &mnt->mount_server.address,
1321 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 kfree(string);
1323 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001324 case Opt_lookupcache:
1325 string = match_strdup(args);
1326 if (string == NULL)
1327 goto out_nomem;
1328 token = match_token(string,
1329 nfs_lookupcache_tokens, args);
1330 kfree(string);
1331 switch (token) {
1332 case Opt_lookupcache_all:
1333 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1334 break;
1335 case Opt_lookupcache_positive:
1336 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1337 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1338 break;
1339 case Opt_lookupcache_none:
1340 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1341 break;
1342 default:
1343 errors++;
1344 dfprintk(MOUNT, "NFS: invalid "
1345 "lookupcache argument\n");
1346 };
1347 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001348
Chuck Leverf45663c2008-06-24 19:28:02 -04001349 /*
1350 * Special options
1351 */
1352 case Opt_sloppy:
1353 sloppy = 1;
1354 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1355 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356 case Opt_userspace:
1357 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001358 dfprintk(MOUNT, "NFS: ignoring mount option "
1359 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001360 break;
1361
1362 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001363 errors++;
1364 dfprintk(MOUNT, "NFS: unrecognized mount option "
1365 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001366 }
1367 }
1368
Chuck Leveraf904de2008-09-08 11:58:13 -04001369 if (errors > 0) {
1370 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1371 errors, (errors == 1 ? "" : "s"));
1372 if (!sloppy)
1373 return 0;
1374 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001375 return 1;
1376
1377out_nomem:
1378 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1379 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001380out_security_failure:
1381 free_secdata(secdata);
1382 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1383 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001384}
1385
1386/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001387 * Use the remote server's MOUNT service to request the NFS file handle
1388 * corresponding to the provided path.
1389 */
1390static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1391 struct nfs_fh *root_fh)
1392{
Chuck Leverc5d120f2008-12-23 15:21:35 -05001393 struct nfs_mount_request request = {
1394 .sap = (struct sockaddr *)
1395 &args->mount_server.address,
1396 .dirpath = args->nfs_server.export_path,
1397 .protocol = args->mount_server.protocol,
1398 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001399 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001400 };
Chuck Lever4c568012007-12-10 14:59:28 -05001401 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001402
1403 if (args->mount_server.version == 0) {
1404 if (args->flags & NFS_MOUNT_VER3)
1405 args->mount_server.version = NFS_MNT3_VERSION;
1406 else
1407 args->mount_server.version = NFS_MNT_VERSION;
1408 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001409 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001410
Chuck Lever33832032007-12-10 14:59:13 -05001411 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001412 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001413 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001414 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001415
Chuck Lever0076d7b2007-07-01 12:13:49 -04001416 /*
1417 * Construct the mount server's address.
1418 */
Chuck Lever4c568012007-12-10 14:59:28 -05001419 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001420 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001421 args->nfs_server.addrlen);
1422 args->mount_server.addrlen = args->nfs_server.addrlen;
1423 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001424 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001425
James Lentiniaad70002007-09-24 17:32:49 -04001426 /*
1427 * autobind will be used if mount_server.port == 0
1428 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001429 nfs_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001430
1431 /*
1432 * Now ask the mount server to map our export path
1433 * to a file handle.
1434 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001435 status = nfs_mount(&request);
Chuck Leverefd83402007-09-11 18:00:58 -04001436 if (status == 0)
1437 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001438
Chuck Lever396cee972008-06-12 12:37:49 -04001439 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Leverc5d120f2008-12-23 15:21:35 -05001440 request.hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001441 return status;
1442}
1443
Chuck Leverd1aa0822008-06-23 12:36:45 -04001444static int nfs_parse_simple_hostname(const char *dev_name,
1445 char **hostname, size_t maxnamlen,
1446 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001447{
1448 size_t len;
1449 char *colon, *comma;
1450
1451 colon = strchr(dev_name, ':');
1452 if (colon == NULL)
1453 goto out_bad_devname;
1454
1455 len = colon - dev_name;
1456 if (len > maxnamlen)
1457 goto out_hostname;
1458
1459 /* N.B. caller will free nfs_server.hostname in all cases */
1460 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1461 if (!*hostname)
1462 goto out_nomem;
1463
1464 /* kill possible hostname list: not supported */
1465 comma = strchr(*hostname, ',');
1466 if (comma != NULL) {
1467 if (comma == *hostname)
1468 goto out_bad_devname;
1469 *comma = '\0';
1470 }
1471
1472 colon++;
1473 len = strlen(colon);
1474 if (len > maxpathlen)
1475 goto out_path;
1476 *export_path = kstrndup(colon, len, GFP_KERNEL);
1477 if (!*export_path)
1478 goto out_nomem;
1479
1480 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1481 return 0;
1482
1483out_bad_devname:
1484 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1485 return -EINVAL;
1486
1487out_nomem:
1488 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1489 return -ENOMEM;
1490
1491out_hostname:
1492 dfprintk(MOUNT, "NFS: server hostname too long\n");
1493 return -ENAMETOOLONG;
1494
1495out_path:
1496 dfprintk(MOUNT, "NFS: export pathname too long\n");
1497 return -ENAMETOOLONG;
1498}
1499
1500/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001501 * Hostname has square brackets around it because it contains one or
1502 * more colons. We look for the first closing square bracket, and a
1503 * colon must follow it.
1504 */
1505static int nfs_parse_protected_hostname(const char *dev_name,
1506 char **hostname, size_t maxnamlen,
1507 char **export_path, size_t maxpathlen)
1508{
1509 size_t len;
1510 char *start, *end;
1511
1512 start = (char *)(dev_name + 1);
1513
1514 end = strchr(start, ']');
1515 if (end == NULL)
1516 goto out_bad_devname;
1517 if (*(end + 1) != ':')
1518 goto out_bad_devname;
1519
1520 len = end - start;
1521 if (len > maxnamlen)
1522 goto out_hostname;
1523
1524 /* N.B. caller will free nfs_server.hostname in all cases */
1525 *hostname = kstrndup(start, len, GFP_KERNEL);
1526 if (*hostname == NULL)
1527 goto out_nomem;
1528
1529 end += 2;
1530 len = strlen(end);
1531 if (len > maxpathlen)
1532 goto out_path;
1533 *export_path = kstrndup(end, len, GFP_KERNEL);
1534 if (!*export_path)
1535 goto out_nomem;
1536
1537 return 0;
1538
1539out_bad_devname:
1540 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1541 return -EINVAL;
1542
1543out_nomem:
1544 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1545 return -ENOMEM;
1546
1547out_hostname:
1548 dfprintk(MOUNT, "NFS: server hostname too long\n");
1549 return -ENAMETOOLONG;
1550
1551out_path:
1552 dfprintk(MOUNT, "NFS: export pathname too long\n");
1553 return -ENAMETOOLONG;
1554}
1555
1556/*
1557 * Split "dev_name" into "hostname:export_path".
1558 *
1559 * The leftmost colon demarks the split between the server's hostname
1560 * and the export path. If the hostname starts with a left square
1561 * bracket, then it may contain colons.
1562 *
1563 * Note: caller frees hostname and export path, even on error.
1564 */
1565static int nfs_parse_devname(const char *dev_name,
1566 char **hostname, size_t maxnamlen,
1567 char **export_path, size_t maxpathlen)
1568{
1569 if (*dev_name == '[')
1570 return nfs_parse_protected_hostname(dev_name,
1571 hostname, maxnamlen,
1572 export_path, maxpathlen);
1573
1574 return nfs_parse_simple_hostname(dev_name,
1575 hostname, maxnamlen,
1576 export_path, maxpathlen);
1577}
1578
1579/*
David Howells54ceac42006-08-22 20:06:13 -04001580 * Validate the NFS2/NFS3 mount data
1581 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001582 *
1583 * For option strings, user space handles the following behaviors:
1584 *
1585 * + DNS: mapping server host name to IP address ("addr=" option)
1586 *
1587 * + failure mode: how to behave if a mount request can't be handled
1588 * immediately ("fg/bg" option)
1589 *
1590 * + retry: how often to retry a mount request ("retry=" option)
1591 *
1592 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1593 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001594 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001595static int nfs_validate_mount_data(void *options,
1596 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001597 struct nfs_fh *mntfh,
1598 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001599{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001600 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001601
Chuck Lever5df36e72007-07-01 12:12:56 -04001602 if (data == NULL)
1603 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001604
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001605 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1606 args->rsize = NFS_MAX_FILE_IO_SIZE;
1607 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001608 args->acregmin = NFS_DEF_ACREGMIN;
1609 args->acregmax = NFS_DEF_ACREGMAX;
1610 args->acdirmin = NFS_DEF_ACDIRMIN;
1611 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001612 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001613 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001614 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001615 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001616
David Howellsf7b422b2006-06-09 09:34:33 -04001617 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001618 case 1:
1619 data->namlen = 0;
1620 case 2:
1621 data->bsize = 0;
1622 case 3:
1623 if (data->flags & NFS_MOUNT_VER3)
1624 goto out_no_v3;
1625 data->root.size = NFS2_FHSIZE;
1626 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1627 case 4:
1628 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1629 goto out_no_sec;
1630 case 5:
1631 memset(data->context, 0, sizeof(data->context));
1632 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001633 if (data->flags & NFS_MOUNT_VER3) {
1634 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1635 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001636 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001637 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001638 mntfh->size = NFS2_FHSIZE;
1639
Chuck Lever5df36e72007-07-01 12:12:56 -04001640
1641 memcpy(mntfh->data, data->root.data, mntfh->size);
1642 if (mntfh->size < sizeof(mntfh->data))
1643 memset(mntfh->data + mntfh->size, 0,
1644 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001645
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001646 /*
1647 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1648 * can deal with.
1649 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001650 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001651 args->rsize = data->rsize;
1652 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001653 args->timeo = data->timeo;
1654 args->retrans = data->retrans;
1655 args->acregmin = data->acregmin;
1656 args->acregmax = data->acregmax;
1657 args->acdirmin = data->acdirmin;
1658 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001659
1660 memcpy(&args->nfs_server.address, &data->addr,
1661 sizeof(data->addr));
1662 args->nfs_server.addrlen = sizeof(data->addr);
1663 if (!nfs_verify_server_address((struct sockaddr *)
1664 &args->nfs_server.address))
1665 goto out_no_address;
1666
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001667 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001668 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001669 /* N.B. caller will free nfs_server.hostname in all cases */
1670 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1671 args->namlen = data->namlen;
1672 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001673
1674 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1675 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001676 if (!args->nfs_server.hostname)
1677 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001678
1679 /*
1680 * The legacy version 6 binary mount data from userspace has a
1681 * field used only to transport selinux information into the
1682 * the kernel. To continue to support that functionality we
1683 * have a touch of selinux knowledge here in the NFS code. The
1684 * userspace code converted context=blah to just blah so we are
1685 * converting back to the full string selinux understands.
1686 */
1687 if (data->context[0]){
1688#ifdef CONFIG_SECURITY_SELINUX
1689 int rc;
1690 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1691 if (!opts_str)
1692 return -ENOMEM;
1693 strcpy(opts_str, "context=");
1694 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1695 strcat(opts_str, &data->context[0]);
1696 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1697 kfree(opts_str);
1698 if (rc)
1699 return rc;
1700#else
1701 return -EINVAL;
1702#endif
1703 }
1704
Chuck Lever5df36e72007-07-01 12:12:56 -04001705 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001706 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001707 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001708
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001709 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001710 return -EINVAL;
1711
Chuck Lever6e88e062007-09-24 15:39:50 -04001712 if (!nfs_verify_server_address((struct sockaddr *)
1713 &args->nfs_server.address))
1714 goto out_no_address;
1715
Chuck Levered596a82008-06-26 17:47:05 -04001716 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1717 args->nfs_server.port);
1718
Trond Myklebust259875e2008-07-02 14:43:47 -04001719 nfs_set_mount_transport_protocol(args);
1720
Chuck Leverdc045892008-06-23 12:36:37 -04001721 status = nfs_parse_devname(dev_name,
1722 &args->nfs_server.hostname,
1723 PAGE_SIZE,
1724 &args->nfs_server.export_path,
1725 NFS_MAXPATHLEN);
1726 if (!status)
1727 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001728
Chuck Leverdc045892008-06-23 12:36:37 -04001729 kfree(args->nfs_server.export_path);
1730 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001731
Chuck Lever136d5582007-07-01 12:13:54 -04001732 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001733 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001734
Chuck Lever136d5582007-07-01 12:13:54 -04001735 break;
1736 }
David Howellsf7b422b2006-06-09 09:34:33 -04001737 }
David Howells54ceac42006-08-22 20:06:13 -04001738
David Howellsf7b422b2006-06-09 09:34:33 -04001739#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001740 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001741 goto out_v3_not_compiled;
1742#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001743
David Howells54ceac42006-08-22 20:06:13 -04001744 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001745
1746out_no_data:
1747 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1748 return -EINVAL;
1749
1750out_no_v3:
1751 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1752 data->version);
1753 return -EINVAL;
1754
1755out_no_sec:
1756 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1757 return -EINVAL;
1758
Chuck Lever5df36e72007-07-01 12:12:56 -04001759#ifndef CONFIG_NFS_V3
1760out_v3_not_compiled:
1761 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1762 return -EPROTONOSUPPORT;
1763#endif /* !CONFIG_NFS_V3 */
1764
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001765out_nomem:
1766 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1767 return -ENOMEM;
1768
Chuck Lever5df36e72007-07-01 12:12:56 -04001769out_no_address:
1770 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1771 return -EINVAL;
1772
1773out_invalid_fh:
1774 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1775 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001776}
1777
Jeff Layton48b605f2008-06-10 15:38:39 -04001778static int
1779nfs_compare_remount_data(struct nfs_server *nfss,
1780 struct nfs_parsed_mount_data *data)
1781{
1782 if (data->flags != nfss->flags ||
1783 data->rsize != nfss->rsize ||
1784 data->wsize != nfss->wsize ||
1785 data->retrans != nfss->client->cl_timeout->to_retries ||
1786 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1787 data->acregmin != nfss->acregmin / HZ ||
1788 data->acregmax != nfss->acregmax / HZ ||
1789 data->acdirmin != nfss->acdirmin / HZ ||
1790 data->acdirmax != nfss->acdirmax / HZ ||
1791 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1792 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1793 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1794 data->nfs_server.addrlen) != 0)
1795 return -EINVAL;
1796
1797 return 0;
1798}
1799
1800static int
1801nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1802{
1803 int error;
1804 struct nfs_server *nfss = sb->s_fs_info;
1805 struct nfs_parsed_mount_data *data;
1806 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1807 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001808 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001809
1810 /*
1811 * Userspace mount programs that send binary options generally send
1812 * them populated with default values. We have no way to know which
1813 * ones were explicitly specified. Fall back to legacy behavior and
1814 * just return success.
1815 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001816 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1817 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1818 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001819 return 0;
1820
1821 data = kzalloc(sizeof(*data), GFP_KERNEL);
1822 if (data == NULL)
1823 return -ENOMEM;
1824
1825 /* fill out struct with values from existing mount */
1826 data->flags = nfss->flags;
1827 data->rsize = nfss->rsize;
1828 data->wsize = nfss->wsize;
1829 data->retrans = nfss->client->cl_timeout->to_retries;
1830 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1831 data->acregmin = nfss->acregmin / HZ;
1832 data->acregmax = nfss->acregmax / HZ;
1833 data->acdirmin = nfss->acdirmin / HZ;
1834 data->acdirmax = nfss->acdirmax / HZ;
1835 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1836 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1837 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1838 data->nfs_server.addrlen);
1839
1840 /* overwrite those values with any that were specified */
1841 error = nfs_parse_mount_options((char *)options, data);
1842 if (error < 0)
1843 goto out;
1844
1845 /* compare new mount options with old ones */
1846 error = nfs_compare_remount_data(nfss, data);
1847out:
1848 kfree(data);
1849 return error;
1850}
1851
David Howells54ceac42006-08-22 20:06:13 -04001852/*
1853 * Initialise the common bits of the superblock
1854 */
1855static inline void nfs_initialise_sb(struct super_block *sb)
1856{
1857 struct nfs_server *server = NFS_SB(sb);
1858
1859 sb->s_magic = NFS_SUPER_MAGIC;
1860
1861 /* We probably want something more informative here */
1862 snprintf(sb->s_id, sizeof(sb->s_id),
1863 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1864
1865 if (sb->s_blocksize == 0)
1866 sb->s_blocksize = nfs_block_bits(server->wsize,
1867 &sb->s_blocksize_bits);
1868
1869 if (server->flags & NFS_MOUNT_NOAC)
1870 sb->s_flags |= MS_SYNCHRONOUS;
1871
1872 nfs_super_set_maxbytes(sb, server->maxfilesize);
1873}
1874
1875/*
1876 * Finish setting up an NFS2/3 superblock
1877 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001878static void nfs_fill_super(struct super_block *sb,
1879 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001880{
1881 struct nfs_server *server = NFS_SB(sb);
1882
1883 sb->s_blocksize_bits = 0;
1884 sb->s_blocksize = 0;
1885 if (data->bsize)
1886 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1887
1888 if (server->flags & NFS_MOUNT_VER3) {
1889 /* The VFS shouldn't apply the umask to mode bits. We will do
1890 * so ourselves when necessary.
1891 */
1892 sb->s_flags |= MS_POSIXACL;
1893 sb->s_time_gran = 1;
1894 }
1895
1896 sb->s_op = &nfs_sops;
1897 nfs_initialise_sb(sb);
1898}
1899
1900/*
1901 * Finish setting up a cloned NFS2/3 superblock
1902 */
1903static void nfs_clone_super(struct super_block *sb,
1904 const struct super_block *old_sb)
1905{
1906 struct nfs_server *server = NFS_SB(sb);
1907
1908 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1909 sb->s_blocksize = old_sb->s_blocksize;
1910 sb->s_maxbytes = old_sb->s_maxbytes;
1911
1912 if (server->flags & NFS_MOUNT_VER3) {
1913 /* The VFS shouldn't apply the umask to mode bits. We will do
1914 * so ourselves when necessary.
1915 */
1916 sb->s_flags |= MS_POSIXACL;
1917 sb->s_time_gran = 1;
1918 }
1919
1920 sb->s_op = old_sb->s_op;
1921 nfs_initialise_sb(sb);
1922}
1923
Trond Myklebust275a5d22007-05-16 16:53:28 -04001924static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1925{
1926 const struct nfs_server *a = s->s_fs_info;
1927 const struct rpc_clnt *clnt_a = a->client;
1928 const struct rpc_clnt *clnt_b = b->client;
1929
1930 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1931 goto Ebusy;
1932 if (a->nfs_client != b->nfs_client)
1933 goto Ebusy;
1934 if (a->flags != b->flags)
1935 goto Ebusy;
1936 if (a->wsize != b->wsize)
1937 goto Ebusy;
1938 if (a->rsize != b->rsize)
1939 goto Ebusy;
1940 if (a->acregmin != b->acregmin)
1941 goto Ebusy;
1942 if (a->acregmax != b->acregmax)
1943 goto Ebusy;
1944 if (a->acdirmin != b->acdirmin)
1945 goto Ebusy;
1946 if (a->acdirmax != b->acdirmax)
1947 goto Ebusy;
1948 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1949 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001950 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001951Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001952 return 0;
1953}
1954
1955struct nfs_sb_mountdata {
1956 struct nfs_server *server;
1957 int mntflags;
1958};
1959
1960static int nfs_set_super(struct super_block *s, void *data)
1961{
1962 struct nfs_sb_mountdata *sb_mntdata = data;
1963 struct nfs_server *server = sb_mntdata->server;
1964 int ret;
1965
1966 s->s_flags = sb_mntdata->mntflags;
1967 s->s_fs_info = server;
1968 ret = set_anon_super(s, server);
1969 if (ret == 0)
1970 server->s_dev = s->s_dev;
1971 return ret;
1972}
1973
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001974static int nfs_compare_super_address(struct nfs_server *server1,
1975 struct nfs_server *server2)
1976{
1977 struct sockaddr *sap1, *sap2;
1978
1979 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1980 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1981
1982 if (sap1->sa_family != sap2->sa_family)
1983 return 0;
1984
1985 switch (sap1->sa_family) {
1986 case AF_INET: {
1987 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1988 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1989 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1990 return 0;
1991 if (sin1->sin_port != sin2->sin_port)
1992 return 0;
1993 break;
1994 }
1995 case AF_INET6: {
1996 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1997 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1998 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1999 return 0;
2000 if (sin1->sin6_port != sin2->sin6_port)
2001 return 0;
2002 break;
2003 }
2004 default:
2005 return 0;
2006 }
2007
2008 return 1;
2009}
2010
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002011static int nfs_compare_super(struct super_block *sb, void *data)
2012{
2013 struct nfs_sb_mountdata *sb_mntdata = data;
2014 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2015 int mntflags = sb_mntdata->mntflags;
2016
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002017 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002018 return 0;
2019 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2020 if (old->flags & NFS_MOUNT_UNSHARED)
2021 return 0;
2022 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2023 return 0;
2024 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002025}
2026
Miklos Szeredifa799752008-04-30 00:54:33 -07002027static int nfs_bdi_register(struct nfs_server *server)
2028{
2029 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2030}
2031
David Howells54ceac42006-08-22 20:06:13 -04002032static int nfs_get_sb(struct file_system_type *fs_type,
2033 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2034{
2035 struct nfs_server *server = NULL;
2036 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002037 struct nfs_parsed_mount_data *data;
2038 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002039 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002040 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002041 struct nfs_sb_mountdata sb_mntdata = {
2042 .mntflags = flags,
2043 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002044 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002045
Trond Myklebust33852a12008-06-19 14:20:11 -04002046 data = kzalloc(sizeof(*data), GFP_KERNEL);
2047 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2048 if (data == NULL || mntfh == NULL)
2049 goto out_free_fh;
2050
2051 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002052
David Howells54ceac42006-08-22 20:06:13 -04002053 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002054 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002055 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002056 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002057
2058 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002059 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002060 if (IS_ERR(server)) {
2061 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002062 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002063 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002064 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002065
Trond Myklebust75180df2007-05-16 16:53:28 -04002066 if (server->flags & NFS_MOUNT_UNSHARED)
2067 compare_super = NULL;
2068
David Howells54ceac42006-08-22 20:06:13 -04002069 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002070 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002071 if (IS_ERR(s)) {
2072 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002073 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002074 }
2075
David Howells54ceac42006-08-22 20:06:13 -04002076 if (s->s_fs_info != server) {
2077 nfs_free_server(server);
2078 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002079 } else {
2080 error = nfs_bdi_register(server);
2081 if (error)
2082 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002083 }
David Howells54ceac42006-08-22 20:06:13 -04002084
2085 if (!s->s_root) {
2086 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002087 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002088 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002089 }
2090
Trond Myklebust33852a12008-06-19 14:20:11 -04002091 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002092 if (IS_ERR(mntroot)) {
2093 error = PTR_ERR(mntroot);
2094 goto error_splat_super;
2095 }
2096
Trond Myklebust33852a12008-06-19 14:20:11 -04002097 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002098 if (error)
2099 goto error_splat_root;
2100
David Howellsf7b422b2006-06-09 09:34:33 -04002101 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002102 mnt->mnt_sb = s;
2103 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002104 error = 0;
2105
2106out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002107 kfree(data->nfs_server.hostname);
2108 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002109 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002110 security_free_mnt_opts(&data->lsm_opts);
2111out_free_fh:
2112 kfree(mntfh);
2113 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002114 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002115
David Howells54ceac42006-08-22 20:06:13 -04002116out_err_nosb:
2117 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002118 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002119
Eric Parisf9c3a382008-03-05 14:20:18 -05002120error_splat_root:
2121 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002122error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002123 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002124 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002125}
2126
David Howells54ceac42006-08-22 20:06:13 -04002127/*
2128 * Destroy an NFS2/3 superblock
2129 */
David Howellsf7b422b2006-06-09 09:34:33 -04002130static void nfs_kill_super(struct super_block *s)
2131{
2132 struct nfs_server *server = NFS_SB(s);
2133
Miklos Szeredifa799752008-04-30 00:54:33 -07002134 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002135 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002136 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002137 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002138}
2139
David Howells54ceac42006-08-22 20:06:13 -04002140/*
2141 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2142 */
2143static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2144 const char *dev_name, void *raw_data,
2145 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002146{
2147 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002148 struct super_block *s;
2149 struct nfs_server *server;
2150 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002151 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002152 struct nfs_sb_mountdata sb_mntdata = {
2153 .mntflags = flags,
2154 };
David Howells54ceac42006-08-22 20:06:13 -04002155 int error;
2156
2157 dprintk("--> nfs_xdev_get_sb()\n");
2158
2159 /* create a new volume representation */
2160 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2161 if (IS_ERR(server)) {
2162 error = PTR_ERR(server);
2163 goto out_err_noserver;
2164 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002165 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002166
Trond Myklebust75180df2007-05-16 16:53:28 -04002167 if (server->flags & NFS_MOUNT_UNSHARED)
2168 compare_super = NULL;
2169
David Howells54ceac42006-08-22 20:06:13 -04002170 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002171 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002172 if (IS_ERR(s)) {
2173 error = PTR_ERR(s);
2174 goto out_err_nosb;
2175 }
2176
2177 if (s->s_fs_info != server) {
2178 nfs_free_server(server);
2179 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002180 } else {
2181 error = nfs_bdi_register(server);
2182 if (error)
2183 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002184 }
2185
2186 if (!s->s_root) {
2187 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002188 nfs_clone_super(s, data->sb);
2189 }
2190
2191 mntroot = nfs_get_root(s, data->fh);
2192 if (IS_ERR(mntroot)) {
2193 error = PTR_ERR(mntroot);
2194 goto error_splat_super;
2195 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002196 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002197 dput(mntroot);
2198 error = -ESTALE;
2199 goto error_splat_super;
2200 }
David Howells54ceac42006-08-22 20:06:13 -04002201
2202 s->s_flags |= MS_ACTIVE;
2203 mnt->mnt_sb = s;
2204 mnt->mnt_root = mntroot;
2205
Eric Parisf9c3a382008-03-05 14:20:18 -05002206 /* clone any lsm security options from the parent to the new sb */
2207 security_sb_clone_mnt_opts(data->sb, s);
2208
David Howells54ceac42006-08-22 20:06:13 -04002209 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2210 return 0;
2211
2212out_err_nosb:
2213 nfs_free_server(server);
2214out_err_noserver:
2215 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2216 return error;
2217
2218error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002219 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002220 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2221 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002222}
2223
2224#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002225
2226/*
2227 * Finish setting up a cloned NFS4 superblock
2228 */
2229static void nfs4_clone_super(struct super_block *sb,
2230 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002231{
David Howells54ceac42006-08-22 20:06:13 -04002232 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2233 sb->s_blocksize = old_sb->s_blocksize;
2234 sb->s_maxbytes = old_sb->s_maxbytes;
2235 sb->s_time_gran = 1;
2236 sb->s_op = old_sb->s_op;
2237 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002238}
2239
2240/*
2241 * Set up an NFS4 superblock
2242 */
David Howells54ceac42006-08-22 20:06:13 -04002243static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002244{
David Howellsf7b422b2006-06-09 09:34:33 -04002245 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002246 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002247 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002248}
2249
David Howells54ceac42006-08-22 20:06:13 -04002250/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002251 * Validate NFSv4 mount options
2252 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002253static int nfs4_validate_mount_data(void *options,
2254 struct nfs_parsed_mount_data *args,
2255 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002256{
Chuck Lever4c568012007-12-10 14:59:28 -05002257 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002258 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002259 char *c;
2260
2261 if (data == NULL)
2262 goto out_no_data;
2263
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002264 args->rsize = NFS_MAX_FILE_IO_SIZE;
2265 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002266 args->acregmin = NFS_DEF_ACREGMIN;
2267 args->acregmax = NFS_DEF_ACREGMAX;
2268 args->acdirmin = NFS_DEF_ACDIRMIN;
2269 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002270 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002271 args->auth_flavors[0] = RPC_AUTH_UNIX;
2272 args->auth_flavor_len = 0;
Mike Sager3fd5be92009-04-01 09:21:48 -04002273 args->minorversion = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002274
Chuck Leverf0768eb2007-07-01 12:13:01 -04002275 switch (data->version) {
2276 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002277 ap = (struct sockaddr_in *)&args->nfs_server.address;
2278 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002279 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002280 if (data->host_addrlen == 0)
2281 goto out_no_address;
2282 args->nfs_server.addrlen = data->host_addrlen;
2283 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002284 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002285 if (!nfs_verify_server_address((struct sockaddr *)
2286 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002287 goto out_no_address;
2288
Chuck Lever6738b252008-06-24 16:33:54 -04002289 if (data->auth_flavourlen) {
2290 if (data->auth_flavourlen > 1)
2291 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002292 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002293 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002294 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002295 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002296 }
2297
2298 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2299 if (IS_ERR(c))
2300 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002301 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002302
2303 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2304 if (IS_ERR(c))
2305 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002306 args->nfs_server.export_path = c;
2307 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002308
2309 c = strndup_user(data->client_addr.data, 16);
2310 if (IS_ERR(c))
2311 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002312 args->client_address = c;
2313
2314 /*
2315 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2316 * can deal with.
2317 */
2318
2319 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2320 args->rsize = data->rsize;
2321 args->wsize = data->wsize;
2322 args->timeo = data->timeo;
2323 args->retrans = data->retrans;
2324 args->acregmin = data->acregmin;
2325 args->acregmax = data->acregmax;
2326 args->acdirmin = data->acdirmin;
2327 args->acdirmax = data->acdirmax;
2328 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002329 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002330
2331 break;
Chuck Lever80071222007-07-01 12:13:59 -04002332 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002333 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002334
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002335 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002336 return -EINVAL;
2337
2338 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002339 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002340 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002341
Chuck Levered596a82008-06-26 17:47:05 -04002342 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2343 args->nfs_server.port);
2344
Trond Myklebust259875e2008-07-02 14:43:47 -04002345 nfs_validate_transport_protocol(args);
2346
Chuck Lever6738b252008-06-24 16:33:54 -04002347 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002348 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002349
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002350 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002351 goto out_no_client_address;
2352
Chuck Leverdc045892008-06-23 12:36:37 -04002353 status = nfs_parse_devname(dev_name,
2354 &args->nfs_server.hostname,
2355 NFS4_MAXNAMLEN,
2356 &args->nfs_server.export_path,
2357 NFS4_MAXPATHLEN);
2358 if (status < 0)
2359 return status;
2360
Chuck Lever80071222007-07-01 12:13:59 -04002361 break;
2362 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002363 }
2364
2365 return 0;
2366
2367out_no_data:
2368 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2369 return -EINVAL;
2370
2371out_inval_auth:
2372 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2373 data->auth_flavourlen);
2374 return -EINVAL;
2375
2376out_no_address:
2377 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2378 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002379
2380out_no_client_address:
2381 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2382 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002383}
2384
2385/*
David Howells54ceac42006-08-22 20:06:13 -04002386 * Get the superblock for an NFS4 mountpoint
2387 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002388static int nfs4_get_sb(struct file_system_type *fs_type,
2389 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002390{
Trond Myklebust33852a12008-06-19 14:20:11 -04002391 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002392 struct super_block *s;
2393 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002394 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002395 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002396 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002397 struct nfs_sb_mountdata sb_mntdata = {
2398 .mntflags = flags,
2399 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002400 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002401
Trond Myklebust33852a12008-06-19 14:20:11 -04002402 data = kzalloc(sizeof(*data), GFP_KERNEL);
2403 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2404 if (data == NULL || mntfh == NULL)
2405 goto out_free_fh;
2406
2407 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002408
Chuck Leverf0768eb2007-07-01 12:13:01 -04002409 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002410 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002411 if (error < 0)
2412 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002413
David Howells54ceac42006-08-22 20:06:13 -04002414 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002415 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002416 if (IS_ERR(server)) {
2417 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002418 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002419 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002420 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002421
Trond Myklebust75180df2007-05-16 16:53:28 -04002422 if (server->flags & NFS4_MOUNT_UNSHARED)
2423 compare_super = NULL;
2424
David Howells54ceac42006-08-22 20:06:13 -04002425 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002426 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002427 if (IS_ERR(s)) {
2428 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002429 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002430 }
2431
Trond Myklebust5dd31772006-08-24 01:03:05 -04002432 if (s->s_fs_info != server) {
2433 nfs_free_server(server);
2434 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002435 } else {
2436 error = nfs_bdi_register(server);
2437 if (error)
2438 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002439 }
2440
David Howells54ceac42006-08-22 20:06:13 -04002441 if (!s->s_root) {
2442 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002443 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002444 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002445 }
David Howellsf7b422b2006-06-09 09:34:33 -04002446
Trond Myklebust33852a12008-06-19 14:20:11 -04002447 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002448 if (IS_ERR(mntroot)) {
2449 error = PTR_ERR(mntroot);
2450 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002451 }
David Howells54ceac42006-08-22 20:06:13 -04002452
Trond Myklebust33852a12008-06-19 14:20:11 -04002453 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002454 if (error)
2455 goto error_splat_root;
2456
David Howellsf7b422b2006-06-09 09:34:33 -04002457 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002458 mnt->mnt_sb = s;
2459 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002460 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002461
Chuck Lever29eb9812007-07-01 12:12:30 -04002462out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002463 kfree(data->client_address);
2464 kfree(data->nfs_server.export_path);
2465 kfree(data->nfs_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002466 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002467 security_free_mnt_opts(&data->lsm_opts);
2468out_free_fh:
2469 kfree(mntfh);
2470 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002471 return error;
David Howells54ceac42006-08-22 20:06:13 -04002472
Chuck Lever29eb9812007-07-01 12:12:30 -04002473out_free:
2474 nfs_free_server(server);
2475 goto out;
2476
Eric Paris46c8ac72008-05-02 13:42:42 -07002477error_splat_root:
2478 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002479error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002480 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002481 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002482}
2483
2484static void nfs4_kill_super(struct super_block *sb)
2485{
2486 struct nfs_server *server = NFS_SB(sb);
2487
Trond Myklebust515d8612008-12-23 15:21:46 -05002488 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002489 kill_anon_super(sb);
2490
2491 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002492 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002493 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002494}
2495
2496/*
David Howells54ceac42006-08-22 20:06:13 -04002497 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002498 */
David Howells54ceac42006-08-22 20:06:13 -04002499static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2500 const char *dev_name, void *raw_data,
2501 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002502{
2503 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002504 struct super_block *s;
2505 struct nfs_server *server;
2506 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002507 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002508 struct nfs_sb_mountdata sb_mntdata = {
2509 .mntflags = flags,
2510 };
David Howells54ceac42006-08-22 20:06:13 -04002511 int error;
2512
2513 dprintk("--> nfs4_xdev_get_sb()\n");
2514
2515 /* create a new volume representation */
2516 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2517 if (IS_ERR(server)) {
2518 error = PTR_ERR(server);
2519 goto out_err_noserver;
2520 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002521 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002522
Trond Myklebust75180df2007-05-16 16:53:28 -04002523 if (server->flags & NFS4_MOUNT_UNSHARED)
2524 compare_super = NULL;
2525
David Howells54ceac42006-08-22 20:06:13 -04002526 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002527 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002528 if (IS_ERR(s)) {
2529 error = PTR_ERR(s);
2530 goto out_err_nosb;
2531 }
2532
2533 if (s->s_fs_info != server) {
2534 nfs_free_server(server);
2535 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002536 } else {
2537 error = nfs_bdi_register(server);
2538 if (error)
2539 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002540 }
2541
2542 if (!s->s_root) {
2543 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002544 nfs4_clone_super(s, data->sb);
2545 }
2546
2547 mntroot = nfs4_get_root(s, data->fh);
2548 if (IS_ERR(mntroot)) {
2549 error = PTR_ERR(mntroot);
2550 goto error_splat_super;
2551 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002552 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2553 dput(mntroot);
2554 error = -ESTALE;
2555 goto error_splat_super;
2556 }
David Howells54ceac42006-08-22 20:06:13 -04002557
2558 s->s_flags |= MS_ACTIVE;
2559 mnt->mnt_sb = s;
2560 mnt->mnt_root = mntroot;
2561
Eric Paris46c8ac72008-05-02 13:42:42 -07002562 security_sb_clone_mnt_opts(data->sb, s);
2563
David Howells54ceac42006-08-22 20:06:13 -04002564 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2565 return 0;
2566
2567out_err_nosb:
2568 nfs_free_server(server);
2569out_err_noserver:
2570 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2571 return error;
2572
2573error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002574 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002575 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2576 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002577}
2578
David Howells54ceac42006-08-22 20:06:13 -04002579/*
2580 * Create an NFS4 server record on referral traversal
2581 */
2582static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2583 const char *dev_name, void *raw_data,
2584 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002585{
2586 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002587 struct super_block *s;
2588 struct nfs_server *server;
2589 struct dentry *mntroot;
2590 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002591 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002592 struct nfs_sb_mountdata sb_mntdata = {
2593 .mntflags = flags,
2594 };
David Howells54ceac42006-08-22 20:06:13 -04002595 int error;
2596
2597 dprintk("--> nfs4_referral_get_sb()\n");
2598
2599 /* create a new volume representation */
2600 server = nfs4_create_referral_server(data, &mntfh);
2601 if (IS_ERR(server)) {
2602 error = PTR_ERR(server);
2603 goto out_err_noserver;
2604 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002605 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002606
Trond Myklebust75180df2007-05-16 16:53:28 -04002607 if (server->flags & NFS4_MOUNT_UNSHARED)
2608 compare_super = NULL;
2609
David Howells54ceac42006-08-22 20:06:13 -04002610 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002611 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002612 if (IS_ERR(s)) {
2613 error = PTR_ERR(s);
2614 goto out_err_nosb;
2615 }
2616
2617 if (s->s_fs_info != server) {
2618 nfs_free_server(server);
2619 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002620 } else {
2621 error = nfs_bdi_register(server);
2622 if (error)
2623 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002624 }
2625
2626 if (!s->s_root) {
2627 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002628 nfs4_fill_super(s);
2629 }
2630
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002631 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002632 if (IS_ERR(mntroot)) {
2633 error = PTR_ERR(mntroot);
2634 goto error_splat_super;
2635 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002636 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2637 dput(mntroot);
2638 error = -ESTALE;
2639 goto error_splat_super;
2640 }
David Howells54ceac42006-08-22 20:06:13 -04002641
2642 s->s_flags |= MS_ACTIVE;
2643 mnt->mnt_sb = s;
2644 mnt->mnt_root = mntroot;
2645
Eric Paris46c8ac72008-05-02 13:42:42 -07002646 security_sb_clone_mnt_opts(data->sb, s);
2647
David Howells54ceac42006-08-22 20:06:13 -04002648 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2649 return 0;
2650
2651out_err_nosb:
2652 nfs_free_server(server);
2653out_err_noserver:
2654 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2655 return error;
2656
2657error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002658 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002659 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2660 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002661}
2662
David Howells54ceac42006-08-22 20:06:13 -04002663#endif /* CONFIG_NFS_V4 */