blob: 3d460527daab6071168bb5aaf858b076fd670075 [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
Chuck Levera5a16ba2009-06-17 18:02:14 -0700143 { Opt_port, "port=%s" },
144 { Opt_rsize, "rsize=%s" },
145 { Opt_wsize, "wsize=%s" },
146 { Opt_bsize, "bsize=%s" },
147 { Opt_timeo, "timeo=%s" },
148 { Opt_retrans, "retrans=%s" },
149 { Opt_acregmin, "acregmin=%s" },
150 { Opt_acregmax, "acregmax=%s" },
151 { Opt_acdirmin, "acdirmin=%s" },
152 { Opt_acdirmax, "acdirmax=%s" },
153 { Opt_actimeo, "actimeo=%s" },
154 { Opt_namelen, "namlen=%s" },
155 { Opt_mountport, "mountport=%s" },
156 { Opt_mountvers, "mountvers=%s" },
157 { Opt_nfsvers, "nfsvers=%s" },
158 { Opt_nfsvers, "vers=%s" },
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_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400520 { NFS_MOUNT_NOCTO, ",nocto", "" },
521 { NFS_MOUNT_NOAC, ",noac", "" },
522 { NFS_MOUNT_NONLM, ",nolock", "" },
523 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400524 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500525 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
526 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400527 { 0, NULL, NULL }
528 };
David Howells509de812006-08-22 20:06:11 -0400529 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400530 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400531 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400532
Chuck Lever82d101d2008-03-14 14:10:37 -0400533 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400534 seq_printf(m, ",rsize=%u", nfss->rsize);
535 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400536 if (nfss->bsize != 0)
537 seq_printf(m, ",bsize=%u", nfss->bsize);
538 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400539 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400540 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400541 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400542 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400543 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400544 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400545 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400546 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400547 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
548 if (nfss->flags & nfs_infop->flag)
549 seq_puts(m, nfs_infop->str);
550 else
551 seq_puts(m, nfs_infop->nostr);
552 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400553 seq_printf(m, ",proto=%s",
554 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400555 if (version == 4) {
556 if (nfss->port != NFS_PORT)
557 seq_printf(m, ",port=%u", nfss->port);
558 } else
559 if (nfss->port)
560 seq_printf(m, ",port=%u", nfss->port);
561
Trond Myklebust33170232007-12-20 16:03:59 -0500562 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
563 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400564 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400565
566 if (version != 4)
567 nfs_show_mountd_options(m, nfss, showdefaults);
568
569#ifdef CONFIG_NFS_V4
570 if (clp->rpc_ops->version == 4)
571 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
572#endif
David Howellsb797cac2009-04-03 16:42:48 +0100573 if (nfss->options & NFS_OPTION_FSCACHE)
574 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400575}
576
577/*
578 * Describe the mount options on this VFS mountpoint
579 */
580static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
581{
582 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
583
584 nfs_show_mount_options(m, nfss, 0);
585
Chuck Lever5d8515c2007-12-10 14:57:16 -0500586 seq_printf(m, ",addr=%s",
587 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
588 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400589
590 return 0;
591}
592
593/*
594 * Present statistical information for this VFS mountpoint
595 */
596static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
597{
598 int i, cpu;
599 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
600 struct rpc_auth *auth = nfss->client->cl_auth;
601 struct nfs_iostats totals = { };
602
603 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
604
605 /*
606 * Display all mount option settings
607 */
608 seq_printf(m, "\n\topts:\t");
609 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
610 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
611 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
612 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
613 nfs_show_mount_options(m, nfss, 1);
614
615 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
616
617 seq_printf(m, "\n\tcaps:\t");
618 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400619 seq_printf(m, ",wtmult=%u", nfss->wtmult);
620 seq_printf(m, ",dtsize=%u", nfss->dtsize);
621 seq_printf(m, ",bsize=%u", nfss->bsize);
622 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400623
624#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500625 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400626 seq_printf(m, "\n\tnfsv4:\t");
627 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
628 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
629 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
630 }
631#endif
632
633 /*
634 * Display security flavor in effect for this mount
635 */
Chuck Lever2d767432008-03-14 14:10:08 -0400636 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400637 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400638 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400639
640 /*
641 * Display superblock I/O counters
642 */
643 for_each_possible_cpu(cpu) {
644 struct nfs_iostats *stats;
645
646 preempt_disable();
647 stats = per_cpu_ptr(nfss->io_stats, cpu);
648
649 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
650 totals.events[i] += stats->events[i];
651 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
652 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100653#ifdef CONFIG_NFS_FSCACHE
654 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
655 totals.fscache[i] += stats->fscache[i];
656#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400657
658 preempt_enable();
659 }
660
661 seq_printf(m, "\n\tevents:\t");
662 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
663 seq_printf(m, "%lu ", totals.events[i]);
664 seq_printf(m, "\n\tbytes:\t");
665 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
666 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100667#ifdef CONFIG_NFS_FSCACHE
668 if (nfss->options & NFS_OPTION_FSCACHE) {
669 seq_printf(m, "\n\tfsc:\t");
670 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
671 seq_printf(m, "%Lu ", totals.bytes[i]);
672 }
673#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400674 seq_printf(m, "\n");
675
676 rpc_print_iostats(m, nfss->client);
677
678 return 0;
679}
680
681/*
682 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400683 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400684 */
Al Viro42faad92008-04-24 07:21:56 -0400685static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400686{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200687 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400688 struct rpc_clnt *rpc;
689
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200690 lock_kernel();
691
692 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400693 /* -EIO all pending I/O */
694 rpc = server->client_acl;
695 if (!IS_ERR(rpc))
696 rpc_killall_tasks(rpc);
697 rpc = server->client;
698 if (!IS_ERR(rpc))
699 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200700
701 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400702}
703
704/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500705 * Sanity-check a server address provided by the mount command.
706 *
707 * Address family must be initialized, and address must not be
708 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400709 */
710static int nfs_verify_server_address(struct sockaddr *addr)
711{
712 switch (addr->sa_family) {
713 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500714 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700715 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500716 }
717 case AF_INET6: {
718 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
719 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400720 }
721 }
722
723 return 0;
724}
725
Chuck Leverce3b7e12008-06-23 12:36:53 -0400726static void nfs_parse_ipv4_address(char *string, size_t str_len,
727 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500728{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400729 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
730 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500731
Chuck Leverce3b7e12008-06-23 12:36:53 -0400732 if (str_len <= INET_ADDRSTRLEN) {
733 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
734 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500735
Chuck Leverce3b7e12008-06-23 12:36:53 -0400736 sin->sin_family = AF_INET;
737 *addr_len = sizeof(*sin);
738 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500739 return;
740 }
Chuck Lever9412b922007-12-10 14:59:21 -0500741
742 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400743 *addr_len = 0;
744}
745
746#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400747static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
748 const char *delim,
749 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400750{
751 char *p;
752 size_t len;
753
Chuck Lever5e2e7722008-10-08 15:38:10 -0400754 if ((string + str_len) == delim)
755 return 1;
756
Chuck Leverd8e77482008-06-23 12:37:01 -0400757 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400758 return 0;
759
760 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
761 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400762
763 len = (string + str_len) - delim - 1;
764 p = kstrndup(delim + 1, len, GFP_KERNEL);
765 if (p) {
766 unsigned long scope_id = 0;
767 struct net_device *dev;
768
769 dev = dev_get_by_name(&init_net, p);
770 if (dev != NULL) {
771 scope_id = dev->ifindex;
772 dev_put(dev);
773 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400774 if (strict_strtoul(p, 10, &scope_id) == 0) {
775 kfree(p);
776 return 0;
777 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400778 }
779
780 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400781
Chuck Leverd8e77482008-06-23 12:37:01 -0400782 sin6->sin6_scope_id = scope_id;
783 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400784 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400785 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400786
787 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400788}
789
Chuck Leverce3b7e12008-06-23 12:36:53 -0400790static void nfs_parse_ipv6_address(char *string, size_t str_len,
791 struct sockaddr *sap, size_t *addr_len)
792{
793 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
794 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400795 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400796
797 if (str_len <= INET6_ADDRSTRLEN) {
798 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
799 (int)str_len, string);
800
801 sin6->sin6_family = AF_INET6;
802 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400803 if (in6_pton(string, str_len, addr,
804 IPV6_SCOPE_DELIMITER, &delim) != 0) {
805 if (nfs_parse_ipv6_scope_id(string, str_len,
806 delim, sin6) != 0)
807 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400808 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400809 }
810
811 sap->sa_family = AF_UNSPEC;
812 *addr_len = 0;
813}
814#else
815static void nfs_parse_ipv6_address(char *string, size_t str_len,
816 struct sockaddr *sap, size_t *addr_len)
817{
818 sap->sa_family = AF_UNSPEC;
819 *addr_len = 0;
820}
821#endif
822
823/*
824 * Construct a sockaddr based on the contents of a string that contains
825 * an IP address in presentation format.
826 *
827 * If there is a problem constructing the new sockaddr, set the address
828 * family to AF_UNSPEC.
829 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400830void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400831 struct sockaddr *sap, size_t *addr_len)
832{
833 unsigned int i, colons;
834
835 colons = 0;
836 for (i = 0; i < str_len; i++)
837 if (string[i] == ':')
838 colons++;
839
840 if (colons >= 2)
841 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
842 else
843 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500844}
845
846/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400847 * Sanity check the NFS transport protocol.
848 *
849 */
850static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
851{
852 switch (mnt->nfs_server.protocol) {
853 case XPRT_TRANSPORT_UDP:
854 case XPRT_TRANSPORT_TCP:
855 case XPRT_TRANSPORT_RDMA:
856 break;
857 default:
858 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
859 }
860}
861
862/*
863 * For text based NFSv2/v3 mounts, the mount protocol transport default
864 * settings should depend upon the specified NFS transport.
865 */
866static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
867{
868 nfs_validate_transport_protocol(mnt);
869
870 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
871 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
872 return;
873 switch (mnt->nfs_server.protocol) {
874 case XPRT_TRANSPORT_UDP:
875 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
876 break;
877 case XPRT_TRANSPORT_TCP:
878 case XPRT_TRANSPORT_RDMA:
879 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
880 }
881}
882
883/*
Chuck Lever01060c82008-06-24 16:33:38 -0400884 * Parse the value of the 'sec=' option.
885 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400886 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400887 */
888static int nfs_parse_security_flavors(char *value,
889 struct nfs_parsed_mount_data *mnt)
890{
891 substring_t args[MAX_OPT_ARGS];
892
893 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
894
895 switch (match_token(value, nfs_secflavor_tokens, args)) {
896 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400897 mnt->auth_flavor_len = 0;
898 mnt->auth_flavors[0] = RPC_AUTH_NULL;
899 break;
900 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400901 mnt->auth_flavor_len = 0;
902 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
903 break;
904 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400905 mnt->auth_flavor_len = 1;
906 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
907 break;
908 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400909 mnt->auth_flavor_len = 1;
910 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
911 break;
912 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400913 mnt->auth_flavor_len = 1;
914 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
915 break;
916 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400917 mnt->auth_flavor_len = 1;
918 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
919 break;
920 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400921 mnt->auth_flavor_len = 1;
922 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
923 break;
924 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400925 mnt->auth_flavor_len = 1;
926 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
927 break;
928 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400929 mnt->auth_flavor_len = 1;
930 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
931 break;
932 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400933 mnt->auth_flavor_len = 1;
934 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
935 break;
936 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400937 mnt->auth_flavor_len = 1;
938 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
939 break;
940 default:
941 return 0;
942 }
943
944 return 1;
945}
946
947/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400948 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400949 * a data structure. The whole mount string is processed; bad options are
950 * skipped as they are encountered. If there were no errors, return 1;
951 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400952 */
953static int nfs_parse_mount_options(char *raw,
954 struct nfs_parsed_mount_data *mnt)
955{
Eric Parisf9c3a382008-03-05 14:20:18 -0500956 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700957 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958
959 if (!raw) {
960 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
961 return 1;
962 }
963 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
964
Eric Parisf9c3a382008-03-05 14:20:18 -0500965 secdata = alloc_secdata();
966 if (!secdata)
967 goto out_nomem;
968
969 rc = security_sb_copy_data(raw, secdata);
970 if (rc)
971 goto out_security_failure;
972
973 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
974 if (rc)
975 goto out_security_failure;
976
977 free_secdata(secdata);
978
Chuck Leverbf0fd762007-07-01 12:13:44 -0400979 while ((p = strsep(&raw, ",")) != NULL) {
980 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700981 unsigned long option;
Trond Myklebust1f846032009-06-17 18:13:00 -0700982 int int_option;
Chuck Levera5a16ba2009-06-17 18:02:14 -0700983 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400984
985 if (!*p)
986 continue;
987
988 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
989
990 token = match_token(p, nfs_mount_option_tokens, args);
991 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400992
993 /*
994 * boolean options: foo/nofoo
995 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400996 case Opt_soft:
997 mnt->flags |= NFS_MOUNT_SOFT;
998 break;
999 case Opt_hard:
1000 mnt->flags &= ~NFS_MOUNT_SOFT;
1001 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001002 case Opt_posix:
1003 mnt->flags |= NFS_MOUNT_POSIX;
1004 break;
1005 case Opt_noposix:
1006 mnt->flags &= ~NFS_MOUNT_POSIX;
1007 break;
1008 case Opt_cto:
1009 mnt->flags &= ~NFS_MOUNT_NOCTO;
1010 break;
1011 case Opt_nocto:
1012 mnt->flags |= NFS_MOUNT_NOCTO;
1013 break;
1014 case Opt_ac:
1015 mnt->flags &= ~NFS_MOUNT_NOAC;
1016 break;
1017 case Opt_noac:
1018 mnt->flags |= NFS_MOUNT_NOAC;
1019 break;
1020 case Opt_lock:
1021 mnt->flags &= ~NFS_MOUNT_NONLM;
1022 break;
1023 case Opt_nolock:
1024 mnt->flags |= NFS_MOUNT_NONLM;
1025 break;
1026 case Opt_v2:
1027 mnt->flags &= ~NFS_MOUNT_VER3;
1028 break;
1029 case Opt_v3:
1030 mnt->flags |= NFS_MOUNT_VER3;
1031 break;
1032 case Opt_udp:
1033 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001034 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001035 break;
1036 case Opt_tcp:
1037 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001038 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001039 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001040 case Opt_rdma:
1041 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1042 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001043 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001044 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001045 case Opt_acl:
1046 mnt->flags &= ~NFS_MOUNT_NOACL;
1047 break;
1048 case Opt_noacl:
1049 mnt->flags |= NFS_MOUNT_NOACL;
1050 break;
1051 case Opt_rdirplus:
1052 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1053 break;
1054 case Opt_nordirplus:
1055 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1056 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001057 case Opt_sharecache:
1058 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1059 break;
1060 case Opt_nosharecache:
1061 mnt->flags |= NFS_MOUNT_UNSHARED;
1062 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001063 case Opt_resvport:
1064 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1065 break;
1066 case Opt_noresvport:
1067 mnt->flags |= NFS_MOUNT_NORESVPORT;
1068 break;
David Howellsb797cac2009-04-03 16:42:48 +01001069 case Opt_fscache:
1070 mnt->options |= NFS_OPTION_FSCACHE;
1071 kfree(mnt->fscache_uniq);
1072 mnt->fscache_uniq = NULL;
1073 break;
1074 case Opt_nofscache:
1075 mnt->options &= ~NFS_OPTION_FSCACHE;
1076 kfree(mnt->fscache_uniq);
1077 mnt->fscache_uniq = NULL;
1078 break;
1079 case Opt_fscache_uniq:
1080 string = match_strdup(args);
1081 if (!string)
1082 goto out_nomem;
1083 kfree(mnt->fscache_uniq);
1084 mnt->fscache_uniq = string;
1085 mnt->options |= NFS_OPTION_FSCACHE;
1086 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001087
Chuck Leverf45663c2008-06-24 19:28:02 -04001088 /*
1089 * options that take numeric values
1090 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001091 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001092 string = match_strdup(args);
1093 if (string == NULL)
1094 goto out_nomem;
1095 rc = strict_strtoul(string, 10, &option);
1096 kfree(string);
1097 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001098 goto out_invalid_value;
1099 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001100 break;
1101 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001102 string = match_strdup(args);
1103 if (string == NULL)
1104 goto out_nomem;
1105 rc = strict_strtoul(string, 10, &option);
1106 kfree(string);
1107 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001108 goto out_invalid_value;
1109 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001110 break;
1111 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001112 string = match_strdup(args);
1113 if (string == NULL)
1114 goto out_nomem;
1115 rc = strict_strtoul(string, 10, &option);
1116 kfree(string);
1117 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001118 goto out_invalid_value;
1119 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001120 break;
1121 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001122 string = match_strdup(args);
1123 if (string == NULL)
1124 goto out_nomem;
1125 rc = strict_strtoul(string, 10, &option);
1126 kfree(string);
1127 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001128 goto out_invalid_value;
1129 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001130 break;
1131 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001132 string = match_strdup(args);
1133 if (string == NULL)
1134 goto out_nomem;
1135 rc = strict_strtoul(string, 10, &option);
1136 kfree(string);
1137 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001138 goto out_invalid_value;
1139 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001140 break;
1141 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001142 string = match_strdup(args);
1143 if (string == NULL)
1144 goto out_nomem;
1145 rc = strict_strtoul(string, 10, &option);
1146 kfree(string);
1147 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001148 goto out_invalid_value;
1149 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001150 break;
1151 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001152 string = match_strdup(args);
1153 if (string == NULL)
1154 goto out_nomem;
1155 rc = strict_strtoul(string, 10, &option);
1156 kfree(string);
1157 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001158 goto out_invalid_value;
1159 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160 break;
1161 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001162 string = match_strdup(args);
1163 if (string == NULL)
1164 goto out_nomem;
1165 rc = strict_strtoul(string, 10, &option);
1166 kfree(string);
1167 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001168 goto out_invalid_value;
1169 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 break;
1171 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001172 string = match_strdup(args);
1173 if (string == NULL)
1174 goto out_nomem;
1175 rc = strict_strtoul(string, 10, &option);
1176 kfree(string);
1177 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001178 goto out_invalid_value;
1179 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 break;
1181 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001182 string = match_strdup(args);
1183 if (string == NULL)
1184 goto out_nomem;
1185 rc = strict_strtoul(string, 10, &option);
1186 kfree(string);
1187 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001188 goto out_invalid_value;
1189 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001190 break;
1191 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001192 string = match_strdup(args);
1193 if (string == NULL)
1194 goto out_nomem;
1195 rc = strict_strtoul(string, 10, &option);
1196 kfree(string);
1197 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001198 goto out_invalid_value;
1199 mnt->acregmin = mnt->acregmax =
1200 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001201 break;
1202 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001203 string = match_strdup(args);
1204 if (string == NULL)
1205 goto out_nomem;
1206 rc = strict_strtoul(string, 10, &option);
1207 kfree(string);
1208 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001209 goto out_invalid_value;
1210 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001211 break;
1212 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001213 string = match_strdup(args);
1214 if (string == NULL)
1215 goto out_nomem;
1216 rc = strict_strtoul(string, 10, &option);
1217 kfree(string);
1218 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001219 goto out_invalid_value;
1220 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001221 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001222 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001223 string = match_strdup(args);
1224 if (string == NULL)
1225 goto out_nomem;
1226 rc = strict_strtoul(string, 10, &option);
1227 kfree(string);
1228 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001229 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001230 option > NFS_MNT3_VERSION)
1231 goto out_invalid_value;
1232 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001233 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001235 string = match_strdup(args);
1236 if (string == NULL)
1237 goto out_nomem;
1238 rc = strict_strtoul(string, 10, &option);
1239 kfree(string);
1240 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001241 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001243 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001244 mnt->flags &= ~NFS_MOUNT_VER3;
1245 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001246 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 mnt->flags |= NFS_MOUNT_VER3;
1248 break;
1249 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001250 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001251 }
1252 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001253 case Opt_minorversion:
Trond Myklebust1f846032009-06-17 18:13:00 -07001254 if (match_int(args, &int_option))
Mike Sager3fd5be92009-04-01 09:21:48 -04001255 return 0;
Trond Myklebust1f846032009-06-17 18:13:00 -07001256 if (int_option < 0 || int_option > NFS4_MAX_MINOR_VERSION)
Mike Sager3fd5be92009-04-01 09:21:48 -04001257 return 0;
Trond Myklebust1f846032009-06-17 18:13:00 -07001258 mnt->minorversion = int_option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001259 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260
Chuck Leverf45663c2008-06-24 19:28:02 -04001261 /*
1262 * options that take text values
1263 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001264 case Opt_sec:
1265 string = match_strdup(args);
1266 if (string == NULL)
1267 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001268 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001269 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001270 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001271 dfprintk(MOUNT, "NFS: unrecognized "
1272 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001273 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001274 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275 break;
1276 case Opt_proto:
1277 string = match_strdup(args);
1278 if (string == NULL)
1279 goto out_nomem;
1280 token = match_token(string,
1281 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282
1283 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001284 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001286 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001287 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001289 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001290 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001291 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001292 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001293 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001294 case Opt_xprt_rdma:
1295 /* vector side protocols to TCP */
1296 mnt->flags |= NFS_MOUNT_TCP;
1297 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001298 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001299 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001300 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001301 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001302 dfprintk(MOUNT, "NFS: unrecognized "
1303 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001304 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001305 }
1306 break;
1307 case Opt_mountproto:
1308 string = match_strdup(args);
1309 if (string == NULL)
1310 goto out_nomem;
1311 token = match_token(string,
1312 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001313 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314
1315 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001316 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001317 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001318 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001319 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001320 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001322 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001324 dfprintk(MOUNT, "NFS: unrecognized "
1325 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001326 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327 }
1328 break;
1329 case Opt_addr:
1330 string = match_strdup(args);
1331 if (string == NULL)
1332 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001333 nfs_parse_ip_address(string, strlen(string),
1334 (struct sockaddr *)
1335 &mnt->nfs_server.address,
1336 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001337 kfree(string);
1338 break;
1339 case Opt_clientaddr:
1340 string = match_strdup(args);
1341 if (string == NULL)
1342 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001343 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001344 mnt->client_address = string;
1345 break;
Chuck Lever33832032007-12-10 14:59:13 -05001346 case Opt_mounthost:
1347 string = match_strdup(args);
1348 if (string == NULL)
1349 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001350 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001351 mnt->mount_server.hostname = string;
1352 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001353 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001354 string = match_strdup(args);
1355 if (string == NULL)
1356 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001357 nfs_parse_ip_address(string, strlen(string),
1358 (struct sockaddr *)
1359 &mnt->mount_server.address,
1360 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 kfree(string);
1362 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001363 case Opt_lookupcache:
1364 string = match_strdup(args);
1365 if (string == NULL)
1366 goto out_nomem;
1367 token = match_token(string,
1368 nfs_lookupcache_tokens, args);
1369 kfree(string);
1370 switch (token) {
1371 case Opt_lookupcache_all:
1372 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1373 break;
1374 case Opt_lookupcache_positive:
1375 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1376 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1377 break;
1378 case Opt_lookupcache_none:
1379 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1380 break;
1381 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001382 dfprintk(MOUNT, "NFS: invalid "
1383 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001384 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001385 };
1386 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001387
Chuck Leverf45663c2008-06-24 19:28:02 -04001388 /*
1389 * Special options
1390 */
1391 case Opt_sloppy:
1392 sloppy = 1;
1393 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1394 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001395 case Opt_userspace:
1396 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001397 dfprintk(MOUNT, "NFS: ignoring mount option "
1398 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 break;
1400
1401 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001402 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001403 dfprintk(MOUNT, "NFS: unrecognized mount option "
1404 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405 }
1406 }
1407
Chuck Leverd23c45f2009-06-17 18:02:13 -07001408 if (!sloppy && invalid_option)
1409 return 0;
1410
Chuck Leverbf0fd762007-07-01 12:13:44 -04001411 return 1;
1412
Chuck Leverd23c45f2009-06-17 18:02:13 -07001413out_invalid_value:
1414 printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p);
1415 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001416out_nomem:
1417 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1418 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001419out_security_failure:
1420 free_secdata(secdata);
1421 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1422 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423}
1424
1425/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001426 * Use the remote server's MOUNT service to request the NFS file handle
1427 * corresponding to the provided path.
1428 */
1429static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1430 struct nfs_fh *root_fh)
1431{
Chuck Lever8e02f6b2009-06-17 18:02:13 -07001432 unsigned int auth_flavor_len = 0;
Chuck Leverc5d120f2008-12-23 15:21:35 -05001433 struct nfs_mount_request request = {
1434 .sap = (struct sockaddr *)
1435 &args->mount_server.address,
1436 .dirpath = args->nfs_server.export_path,
1437 .protocol = args->mount_server.protocol,
1438 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001439 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Lever8e02f6b2009-06-17 18:02:13 -07001440 .auth_flav_len = &auth_flavor_len,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001441 };
Chuck Lever4c568012007-12-10 14:59:28 -05001442 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001443
1444 if (args->mount_server.version == 0) {
1445 if (args->flags & NFS_MOUNT_VER3)
1446 args->mount_server.version = NFS_MNT3_VERSION;
1447 else
1448 args->mount_server.version = NFS_MNT_VERSION;
1449 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001450 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001451
Chuck Lever33832032007-12-10 14:59:13 -05001452 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001453 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001454 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001455 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001456
Chuck Lever0076d7b2007-07-01 12:13:49 -04001457 /*
1458 * Construct the mount server's address.
1459 */
Chuck Lever4c568012007-12-10 14:59:28 -05001460 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001461 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001462 args->nfs_server.addrlen);
1463 args->mount_server.addrlen = args->nfs_server.addrlen;
1464 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001465 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001466
James Lentiniaad70002007-09-24 17:32:49 -04001467 /*
1468 * autobind will be used if mount_server.port == 0
1469 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001470 nfs_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001471
1472 /*
1473 * Now ask the mount server to map our export path
1474 * to a file handle.
1475 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001476 status = nfs_mount(&request);
Chuck Leverefd83402007-09-11 18:00:58 -04001477 if (status == 0)
1478 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001479
Chuck Lever396cee972008-06-12 12:37:49 -04001480 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Leverc5d120f2008-12-23 15:21:35 -05001481 request.hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001482 return status;
1483}
1484
Chuck Leverd1aa0822008-06-23 12:36:45 -04001485static int nfs_parse_simple_hostname(const char *dev_name,
1486 char **hostname, size_t maxnamlen,
1487 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001488{
1489 size_t len;
1490 char *colon, *comma;
1491
1492 colon = strchr(dev_name, ':');
1493 if (colon == NULL)
1494 goto out_bad_devname;
1495
1496 len = colon - dev_name;
1497 if (len > maxnamlen)
1498 goto out_hostname;
1499
1500 /* N.B. caller will free nfs_server.hostname in all cases */
1501 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1502 if (!*hostname)
1503 goto out_nomem;
1504
1505 /* kill possible hostname list: not supported */
1506 comma = strchr(*hostname, ',');
1507 if (comma != NULL) {
1508 if (comma == *hostname)
1509 goto out_bad_devname;
1510 *comma = '\0';
1511 }
1512
1513 colon++;
1514 len = strlen(colon);
1515 if (len > maxpathlen)
1516 goto out_path;
1517 *export_path = kstrndup(colon, len, GFP_KERNEL);
1518 if (!*export_path)
1519 goto out_nomem;
1520
1521 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1522 return 0;
1523
1524out_bad_devname:
1525 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1526 return -EINVAL;
1527
1528out_nomem:
1529 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1530 return -ENOMEM;
1531
1532out_hostname:
1533 dfprintk(MOUNT, "NFS: server hostname too long\n");
1534 return -ENAMETOOLONG;
1535
1536out_path:
1537 dfprintk(MOUNT, "NFS: export pathname too long\n");
1538 return -ENAMETOOLONG;
1539}
1540
1541/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001542 * Hostname has square brackets around it because it contains one or
1543 * more colons. We look for the first closing square bracket, and a
1544 * colon must follow it.
1545 */
1546static int nfs_parse_protected_hostname(const char *dev_name,
1547 char **hostname, size_t maxnamlen,
1548 char **export_path, size_t maxpathlen)
1549{
1550 size_t len;
1551 char *start, *end;
1552
1553 start = (char *)(dev_name + 1);
1554
1555 end = strchr(start, ']');
1556 if (end == NULL)
1557 goto out_bad_devname;
1558 if (*(end + 1) != ':')
1559 goto out_bad_devname;
1560
1561 len = end - start;
1562 if (len > maxnamlen)
1563 goto out_hostname;
1564
1565 /* N.B. caller will free nfs_server.hostname in all cases */
1566 *hostname = kstrndup(start, len, GFP_KERNEL);
1567 if (*hostname == NULL)
1568 goto out_nomem;
1569
1570 end += 2;
1571 len = strlen(end);
1572 if (len > maxpathlen)
1573 goto out_path;
1574 *export_path = kstrndup(end, len, GFP_KERNEL);
1575 if (!*export_path)
1576 goto out_nomem;
1577
1578 return 0;
1579
1580out_bad_devname:
1581 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1582 return -EINVAL;
1583
1584out_nomem:
1585 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1586 return -ENOMEM;
1587
1588out_hostname:
1589 dfprintk(MOUNT, "NFS: server hostname too long\n");
1590 return -ENAMETOOLONG;
1591
1592out_path:
1593 dfprintk(MOUNT, "NFS: export pathname too long\n");
1594 return -ENAMETOOLONG;
1595}
1596
1597/*
1598 * Split "dev_name" into "hostname:export_path".
1599 *
1600 * The leftmost colon demarks the split between the server's hostname
1601 * and the export path. If the hostname starts with a left square
1602 * bracket, then it may contain colons.
1603 *
1604 * Note: caller frees hostname and export path, even on error.
1605 */
1606static int nfs_parse_devname(const char *dev_name,
1607 char **hostname, size_t maxnamlen,
1608 char **export_path, size_t maxpathlen)
1609{
1610 if (*dev_name == '[')
1611 return nfs_parse_protected_hostname(dev_name,
1612 hostname, maxnamlen,
1613 export_path, maxpathlen);
1614
1615 return nfs_parse_simple_hostname(dev_name,
1616 hostname, maxnamlen,
1617 export_path, maxpathlen);
1618}
1619
1620/*
David Howells54ceac42006-08-22 20:06:13 -04001621 * Validate the NFS2/NFS3 mount data
1622 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001623 *
1624 * For option strings, user space handles the following behaviors:
1625 *
1626 * + DNS: mapping server host name to IP address ("addr=" option)
1627 *
1628 * + failure mode: how to behave if a mount request can't be handled
1629 * immediately ("fg/bg" option)
1630 *
1631 * + retry: how often to retry a mount request ("retry=" option)
1632 *
1633 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1634 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001635 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001636static int nfs_validate_mount_data(void *options,
1637 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001638 struct nfs_fh *mntfh,
1639 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001640{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001641 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001642
Chuck Lever5df36e72007-07-01 12:12:56 -04001643 if (data == NULL)
1644 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001645
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001646 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1647 args->rsize = NFS_MAX_FILE_IO_SIZE;
1648 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001649 args->acregmin = NFS_DEF_ACREGMIN;
1650 args->acregmax = NFS_DEF_ACREGMAX;
1651 args->acdirmin = NFS_DEF_ACDIRMIN;
1652 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001653 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001654 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001655 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001656 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001657
David Howellsf7b422b2006-06-09 09:34:33 -04001658 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001659 case 1:
1660 data->namlen = 0;
1661 case 2:
1662 data->bsize = 0;
1663 case 3:
1664 if (data->flags & NFS_MOUNT_VER3)
1665 goto out_no_v3;
1666 data->root.size = NFS2_FHSIZE;
1667 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1668 case 4:
1669 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1670 goto out_no_sec;
1671 case 5:
1672 memset(data->context, 0, sizeof(data->context));
1673 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001674 if (data->flags & NFS_MOUNT_VER3) {
1675 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1676 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001677 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001678 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001679 mntfh->size = NFS2_FHSIZE;
1680
Chuck Lever5df36e72007-07-01 12:12:56 -04001681
1682 memcpy(mntfh->data, data->root.data, mntfh->size);
1683 if (mntfh->size < sizeof(mntfh->data))
1684 memset(mntfh->data + mntfh->size, 0,
1685 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001686
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001687 /*
1688 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1689 * can deal with.
1690 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001691 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001692 args->rsize = data->rsize;
1693 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001694 args->timeo = data->timeo;
1695 args->retrans = data->retrans;
1696 args->acregmin = data->acregmin;
1697 args->acregmax = data->acregmax;
1698 args->acdirmin = data->acdirmin;
1699 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001700
1701 memcpy(&args->nfs_server.address, &data->addr,
1702 sizeof(data->addr));
1703 args->nfs_server.addrlen = sizeof(data->addr);
1704 if (!nfs_verify_server_address((struct sockaddr *)
1705 &args->nfs_server.address))
1706 goto out_no_address;
1707
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001708 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001709 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001710 /* N.B. caller will free nfs_server.hostname in all cases */
1711 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1712 args->namlen = data->namlen;
1713 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001714
1715 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1716 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001717 if (!args->nfs_server.hostname)
1718 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001719
1720 /*
1721 * The legacy version 6 binary mount data from userspace has a
1722 * field used only to transport selinux information into the
1723 * the kernel. To continue to support that functionality we
1724 * have a touch of selinux knowledge here in the NFS code. The
1725 * userspace code converted context=blah to just blah so we are
1726 * converting back to the full string selinux understands.
1727 */
1728 if (data->context[0]){
1729#ifdef CONFIG_SECURITY_SELINUX
1730 int rc;
1731 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1732 if (!opts_str)
1733 return -ENOMEM;
1734 strcpy(opts_str, "context=");
1735 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1736 strcat(opts_str, &data->context[0]);
1737 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1738 kfree(opts_str);
1739 if (rc)
1740 return rc;
1741#else
1742 return -EINVAL;
1743#endif
1744 }
1745
Chuck Lever5df36e72007-07-01 12:12:56 -04001746 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001747 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001748 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001749
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001750 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001751 return -EINVAL;
1752
Chuck Lever6e88e062007-09-24 15:39:50 -04001753 if (!nfs_verify_server_address((struct sockaddr *)
1754 &args->nfs_server.address))
1755 goto out_no_address;
1756
Chuck Levered596a82008-06-26 17:47:05 -04001757 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1758 args->nfs_server.port);
1759
Trond Myklebust259875e2008-07-02 14:43:47 -04001760 nfs_set_mount_transport_protocol(args);
1761
Chuck Leverdc045892008-06-23 12:36:37 -04001762 status = nfs_parse_devname(dev_name,
1763 &args->nfs_server.hostname,
1764 PAGE_SIZE,
1765 &args->nfs_server.export_path,
1766 NFS_MAXPATHLEN);
1767 if (!status)
1768 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001769
Chuck Leverdc045892008-06-23 12:36:37 -04001770 kfree(args->nfs_server.export_path);
1771 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001772
Chuck Lever136d5582007-07-01 12:13:54 -04001773 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001774 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001775
Chuck Lever136d5582007-07-01 12:13:54 -04001776 break;
1777 }
David Howellsf7b422b2006-06-09 09:34:33 -04001778 }
David Howells54ceac42006-08-22 20:06:13 -04001779
David Howellsf7b422b2006-06-09 09:34:33 -04001780#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001781 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001782 goto out_v3_not_compiled;
1783#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001784
David Howells54ceac42006-08-22 20:06:13 -04001785 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001786
1787out_no_data:
1788 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1789 return -EINVAL;
1790
1791out_no_v3:
1792 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1793 data->version);
1794 return -EINVAL;
1795
1796out_no_sec:
1797 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1798 return -EINVAL;
1799
Chuck Lever5df36e72007-07-01 12:12:56 -04001800#ifndef CONFIG_NFS_V3
1801out_v3_not_compiled:
1802 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1803 return -EPROTONOSUPPORT;
1804#endif /* !CONFIG_NFS_V3 */
1805
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001806out_nomem:
1807 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1808 return -ENOMEM;
1809
Chuck Lever5df36e72007-07-01 12:12:56 -04001810out_no_address:
1811 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1812 return -EINVAL;
1813
1814out_invalid_fh:
1815 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1816 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001817}
1818
Jeff Layton48b605f2008-06-10 15:38:39 -04001819static int
1820nfs_compare_remount_data(struct nfs_server *nfss,
1821 struct nfs_parsed_mount_data *data)
1822{
1823 if (data->flags != nfss->flags ||
1824 data->rsize != nfss->rsize ||
1825 data->wsize != nfss->wsize ||
1826 data->retrans != nfss->client->cl_timeout->to_retries ||
1827 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1828 data->acregmin != nfss->acregmin / HZ ||
1829 data->acregmax != nfss->acregmax / HZ ||
1830 data->acdirmin != nfss->acdirmin / HZ ||
1831 data->acdirmax != nfss->acdirmax / HZ ||
1832 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1833 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1834 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1835 data->nfs_server.addrlen) != 0)
1836 return -EINVAL;
1837
1838 return 0;
1839}
1840
1841static int
1842nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1843{
1844 int error;
1845 struct nfs_server *nfss = sb->s_fs_info;
1846 struct nfs_parsed_mount_data *data;
1847 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1848 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001849 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001850
1851 /*
1852 * Userspace mount programs that send binary options generally send
1853 * them populated with default values. We have no way to know which
1854 * ones were explicitly specified. Fall back to legacy behavior and
1855 * just return success.
1856 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001857 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1858 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1859 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001860 return 0;
1861
1862 data = kzalloc(sizeof(*data), GFP_KERNEL);
1863 if (data == NULL)
1864 return -ENOMEM;
1865
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001866 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001867 /* fill out struct with values from existing mount */
1868 data->flags = nfss->flags;
1869 data->rsize = nfss->rsize;
1870 data->wsize = nfss->wsize;
1871 data->retrans = nfss->client->cl_timeout->to_retries;
1872 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1873 data->acregmin = nfss->acregmin / HZ;
1874 data->acregmax = nfss->acregmax / HZ;
1875 data->acdirmin = nfss->acdirmin / HZ;
1876 data->acdirmax = nfss->acdirmax / HZ;
1877 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1878 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1879 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1880 data->nfs_server.addrlen);
1881
1882 /* overwrite those values with any that were specified */
1883 error = nfs_parse_mount_options((char *)options, data);
1884 if (error < 0)
1885 goto out;
1886
1887 /* compare new mount options with old ones */
1888 error = nfs_compare_remount_data(nfss, data);
1889out:
1890 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001891 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001892 return error;
1893}
1894
David Howells54ceac42006-08-22 20:06:13 -04001895/*
1896 * Initialise the common bits of the superblock
1897 */
1898static inline void nfs_initialise_sb(struct super_block *sb)
1899{
1900 struct nfs_server *server = NFS_SB(sb);
1901
1902 sb->s_magic = NFS_SUPER_MAGIC;
1903
1904 /* We probably want something more informative here */
1905 snprintf(sb->s_id, sizeof(sb->s_id),
1906 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1907
1908 if (sb->s_blocksize == 0)
1909 sb->s_blocksize = nfs_block_bits(server->wsize,
1910 &sb->s_blocksize_bits);
1911
1912 if (server->flags & NFS_MOUNT_NOAC)
1913 sb->s_flags |= MS_SYNCHRONOUS;
1914
1915 nfs_super_set_maxbytes(sb, server->maxfilesize);
1916}
1917
1918/*
1919 * Finish setting up an NFS2/3 superblock
1920 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001921static void nfs_fill_super(struct super_block *sb,
1922 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001923{
1924 struct nfs_server *server = NFS_SB(sb);
1925
1926 sb->s_blocksize_bits = 0;
1927 sb->s_blocksize = 0;
1928 if (data->bsize)
1929 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1930
1931 if (server->flags & NFS_MOUNT_VER3) {
1932 /* The VFS shouldn't apply the umask to mode bits. We will do
1933 * so ourselves when necessary.
1934 */
1935 sb->s_flags |= MS_POSIXACL;
1936 sb->s_time_gran = 1;
1937 }
1938
1939 sb->s_op = &nfs_sops;
1940 nfs_initialise_sb(sb);
1941}
1942
1943/*
1944 * Finish setting up a cloned NFS2/3 superblock
1945 */
1946static void nfs_clone_super(struct super_block *sb,
1947 const struct super_block *old_sb)
1948{
1949 struct nfs_server *server = NFS_SB(sb);
1950
1951 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1952 sb->s_blocksize = old_sb->s_blocksize;
1953 sb->s_maxbytes = old_sb->s_maxbytes;
1954
1955 if (server->flags & NFS_MOUNT_VER3) {
1956 /* The VFS shouldn't apply the umask to mode bits. We will do
1957 * so ourselves when necessary.
1958 */
1959 sb->s_flags |= MS_POSIXACL;
1960 sb->s_time_gran = 1;
1961 }
1962
1963 sb->s_op = old_sb->s_op;
1964 nfs_initialise_sb(sb);
1965}
1966
Trond Myklebust275a5d22007-05-16 16:53:28 -04001967static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1968{
1969 const struct nfs_server *a = s->s_fs_info;
1970 const struct rpc_clnt *clnt_a = a->client;
1971 const struct rpc_clnt *clnt_b = b->client;
1972
1973 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1974 goto Ebusy;
1975 if (a->nfs_client != b->nfs_client)
1976 goto Ebusy;
1977 if (a->flags != b->flags)
1978 goto Ebusy;
1979 if (a->wsize != b->wsize)
1980 goto Ebusy;
1981 if (a->rsize != b->rsize)
1982 goto Ebusy;
1983 if (a->acregmin != b->acregmin)
1984 goto Ebusy;
1985 if (a->acregmax != b->acregmax)
1986 goto Ebusy;
1987 if (a->acdirmin != b->acdirmin)
1988 goto Ebusy;
1989 if (a->acdirmax != b->acdirmax)
1990 goto Ebusy;
1991 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1992 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001993 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001994Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001995 return 0;
1996}
1997
1998struct nfs_sb_mountdata {
1999 struct nfs_server *server;
2000 int mntflags;
2001};
2002
2003static int nfs_set_super(struct super_block *s, void *data)
2004{
2005 struct nfs_sb_mountdata *sb_mntdata = data;
2006 struct nfs_server *server = sb_mntdata->server;
2007 int ret;
2008
2009 s->s_flags = sb_mntdata->mntflags;
2010 s->s_fs_info = server;
2011 ret = set_anon_super(s, server);
2012 if (ret == 0)
2013 server->s_dev = s->s_dev;
2014 return ret;
2015}
2016
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002017static int nfs_compare_super_address(struct nfs_server *server1,
2018 struct nfs_server *server2)
2019{
2020 struct sockaddr *sap1, *sap2;
2021
2022 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2023 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2024
2025 if (sap1->sa_family != sap2->sa_family)
2026 return 0;
2027
2028 switch (sap1->sa_family) {
2029 case AF_INET: {
2030 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2031 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2032 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2033 return 0;
2034 if (sin1->sin_port != sin2->sin_port)
2035 return 0;
2036 break;
2037 }
2038 case AF_INET6: {
2039 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2040 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2041 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2042 return 0;
2043 if (sin1->sin6_port != sin2->sin6_port)
2044 return 0;
2045 break;
2046 }
2047 default:
2048 return 0;
2049 }
2050
2051 return 1;
2052}
2053
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002054static int nfs_compare_super(struct super_block *sb, void *data)
2055{
2056 struct nfs_sb_mountdata *sb_mntdata = data;
2057 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2058 int mntflags = sb_mntdata->mntflags;
2059
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002060 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002061 return 0;
2062 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2063 if (old->flags & NFS_MOUNT_UNSHARED)
2064 return 0;
2065 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2066 return 0;
2067 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002068}
2069
Miklos Szeredifa799752008-04-30 00:54:33 -07002070static int nfs_bdi_register(struct nfs_server *server)
2071{
2072 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2073}
2074
David Howells54ceac42006-08-22 20:06:13 -04002075static int nfs_get_sb(struct file_system_type *fs_type,
2076 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2077{
2078 struct nfs_server *server = NULL;
2079 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002080 struct nfs_parsed_mount_data *data;
2081 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002082 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002083 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002084 struct nfs_sb_mountdata sb_mntdata = {
2085 .mntflags = flags,
2086 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002087 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002088
Trond Myklebust33852a12008-06-19 14:20:11 -04002089 data = kzalloc(sizeof(*data), GFP_KERNEL);
2090 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2091 if (data == NULL || mntfh == NULL)
2092 goto out_free_fh;
2093
2094 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002095
David Howells54ceac42006-08-22 20:06:13 -04002096 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002097 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002098 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002099 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002100
2101 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002102 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002103 if (IS_ERR(server)) {
2104 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002105 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002106 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002107 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002108
Trond Myklebust75180df2007-05-16 16:53:28 -04002109 if (server->flags & NFS_MOUNT_UNSHARED)
2110 compare_super = NULL;
2111
David Howells54ceac42006-08-22 20:06:13 -04002112 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002113 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002114 if (IS_ERR(s)) {
2115 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002116 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002117 }
2118
David Howells54ceac42006-08-22 20:06:13 -04002119 if (s->s_fs_info != server) {
2120 nfs_free_server(server);
2121 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002122 } else {
2123 error = nfs_bdi_register(server);
2124 if (error)
2125 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002126 }
David Howells54ceac42006-08-22 20:06:13 -04002127
2128 if (!s->s_root) {
2129 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002130 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002131 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002132 }
2133
Trond Myklebust33852a12008-06-19 14:20:11 -04002134 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002135 if (IS_ERR(mntroot)) {
2136 error = PTR_ERR(mntroot);
2137 goto error_splat_super;
2138 }
2139
Trond Myklebust33852a12008-06-19 14:20:11 -04002140 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002141 if (error)
2142 goto error_splat_root;
2143
David Howellsf7b422b2006-06-09 09:34:33 -04002144 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002145 mnt->mnt_sb = s;
2146 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002147 error = 0;
2148
2149out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002150 kfree(data->nfs_server.hostname);
2151 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002152 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002153 security_free_mnt_opts(&data->lsm_opts);
2154out_free_fh:
2155 kfree(mntfh);
2156 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002157 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002158
David Howells54ceac42006-08-22 20:06:13 -04002159out_err_nosb:
2160 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002161 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002162
Eric Parisf9c3a382008-03-05 14:20:18 -05002163error_splat_root:
2164 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002165error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002166 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002167 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002168}
2169
David Howells54ceac42006-08-22 20:06:13 -04002170/*
2171 * Destroy an NFS2/3 superblock
2172 */
David Howellsf7b422b2006-06-09 09:34:33 -04002173static void nfs_kill_super(struct super_block *s)
2174{
2175 struct nfs_server *server = NFS_SB(s);
2176
Miklos Szeredifa799752008-04-30 00:54:33 -07002177 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002178 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002179 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002180 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002181}
2182
David Howells54ceac42006-08-22 20:06:13 -04002183/*
2184 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2185 */
2186static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2187 const char *dev_name, void *raw_data,
2188 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002189{
2190 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002191 struct super_block *s;
2192 struct nfs_server *server;
2193 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002194 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002195 struct nfs_sb_mountdata sb_mntdata = {
2196 .mntflags = flags,
2197 };
David Howells54ceac42006-08-22 20:06:13 -04002198 int error;
2199
2200 dprintk("--> nfs_xdev_get_sb()\n");
2201
2202 /* create a new volume representation */
2203 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2204 if (IS_ERR(server)) {
2205 error = PTR_ERR(server);
2206 goto out_err_noserver;
2207 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002208 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002209
Trond Myklebust75180df2007-05-16 16:53:28 -04002210 if (server->flags & NFS_MOUNT_UNSHARED)
2211 compare_super = NULL;
2212
David Howells54ceac42006-08-22 20:06:13 -04002213 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002214 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002215 if (IS_ERR(s)) {
2216 error = PTR_ERR(s);
2217 goto out_err_nosb;
2218 }
2219
2220 if (s->s_fs_info != server) {
2221 nfs_free_server(server);
2222 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002223 } else {
2224 error = nfs_bdi_register(server);
2225 if (error)
2226 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002227 }
2228
2229 if (!s->s_root) {
2230 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002231 nfs_clone_super(s, data->sb);
2232 }
2233
2234 mntroot = nfs_get_root(s, data->fh);
2235 if (IS_ERR(mntroot)) {
2236 error = PTR_ERR(mntroot);
2237 goto error_splat_super;
2238 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002239 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002240 dput(mntroot);
2241 error = -ESTALE;
2242 goto error_splat_super;
2243 }
David Howells54ceac42006-08-22 20:06:13 -04002244
2245 s->s_flags |= MS_ACTIVE;
2246 mnt->mnt_sb = s;
2247 mnt->mnt_root = mntroot;
2248
Eric Parisf9c3a382008-03-05 14:20:18 -05002249 /* clone any lsm security options from the parent to the new sb */
2250 security_sb_clone_mnt_opts(data->sb, s);
2251
David Howells54ceac42006-08-22 20:06:13 -04002252 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2253 return 0;
2254
2255out_err_nosb:
2256 nfs_free_server(server);
2257out_err_noserver:
2258 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2259 return error;
2260
2261error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002262 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002263 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2264 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002265}
2266
2267#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002268
2269/*
2270 * Finish setting up a cloned NFS4 superblock
2271 */
2272static void nfs4_clone_super(struct super_block *sb,
2273 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002274{
David Howells54ceac42006-08-22 20:06:13 -04002275 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2276 sb->s_blocksize = old_sb->s_blocksize;
2277 sb->s_maxbytes = old_sb->s_maxbytes;
2278 sb->s_time_gran = 1;
2279 sb->s_op = old_sb->s_op;
2280 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002281}
2282
2283/*
2284 * Set up an NFS4 superblock
2285 */
David Howells54ceac42006-08-22 20:06:13 -04002286static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002287{
David Howellsf7b422b2006-06-09 09:34:33 -04002288 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002289 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002290 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002291}
2292
Trond Myklebust01c3f052009-06-17 13:22:58 -07002293static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2294{
2295 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2296}
2297
David Howells54ceac42006-08-22 20:06:13 -04002298/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002299 * Validate NFSv4 mount options
2300 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002301static int nfs4_validate_mount_data(void *options,
2302 struct nfs_parsed_mount_data *args,
2303 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002304{
Chuck Lever4c568012007-12-10 14:59:28 -05002305 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002306 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002307 char *c;
2308
2309 if (data == NULL)
2310 goto out_no_data;
2311
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002312 args->rsize = NFS_MAX_FILE_IO_SIZE;
2313 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002314 args->acregmin = NFS_DEF_ACREGMIN;
2315 args->acregmax = NFS_DEF_ACREGMAX;
2316 args->acdirmin = NFS_DEF_ACDIRMIN;
2317 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002318 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002319 args->auth_flavors[0] = RPC_AUTH_UNIX;
2320 args->auth_flavor_len = 0;
Mike Sager3fd5be92009-04-01 09:21:48 -04002321 args->minorversion = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002322
Chuck Leverf0768eb2007-07-01 12:13:01 -04002323 switch (data->version) {
2324 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002325 ap = (struct sockaddr_in *)&args->nfs_server.address;
2326 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002327 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002328 if (data->host_addrlen == 0)
2329 goto out_no_address;
2330 args->nfs_server.addrlen = data->host_addrlen;
2331 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002332 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002333 if (!nfs_verify_server_address((struct sockaddr *)
2334 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002335 goto out_no_address;
2336
Chuck Lever6738b252008-06-24 16:33:54 -04002337 if (data->auth_flavourlen) {
2338 if (data->auth_flavourlen > 1)
2339 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002340 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002341 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002342 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002343 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002344 }
2345
2346 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2347 if (IS_ERR(c))
2348 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002349 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002350
2351 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2352 if (IS_ERR(c))
2353 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002354 args->nfs_server.export_path = c;
2355 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002356
2357 c = strndup_user(data->client_addr.data, 16);
2358 if (IS_ERR(c))
2359 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002360 args->client_address = c;
2361
2362 /*
2363 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2364 * can deal with.
2365 */
2366
2367 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2368 args->rsize = data->rsize;
2369 args->wsize = data->wsize;
2370 args->timeo = data->timeo;
2371 args->retrans = data->retrans;
2372 args->acregmin = data->acregmin;
2373 args->acregmax = data->acregmax;
2374 args->acdirmin = data->acdirmin;
2375 args->acdirmax = data->acdirmax;
2376 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002377 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002378
2379 break;
Chuck Lever80071222007-07-01 12:13:59 -04002380 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002381 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002382
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002383 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002384 return -EINVAL;
2385
2386 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002387 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002388 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002389
Chuck Levered596a82008-06-26 17:47:05 -04002390 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2391 args->nfs_server.port);
2392
Trond Myklebust259875e2008-07-02 14:43:47 -04002393 nfs_validate_transport_protocol(args);
2394
Trond Myklebust01c3f052009-06-17 13:22:58 -07002395 nfs4_validate_mount_flags(args);
2396
Chuck Lever6738b252008-06-24 16:33:54 -04002397 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002398 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002399
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002400 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002401 goto out_no_client_address;
2402
Chuck Leverdc045892008-06-23 12:36:37 -04002403 status = nfs_parse_devname(dev_name,
2404 &args->nfs_server.hostname,
2405 NFS4_MAXNAMLEN,
2406 &args->nfs_server.export_path,
2407 NFS4_MAXPATHLEN);
2408 if (status < 0)
2409 return status;
2410
Chuck Lever80071222007-07-01 12:13:59 -04002411 break;
2412 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002413 }
2414
2415 return 0;
2416
2417out_no_data:
2418 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2419 return -EINVAL;
2420
2421out_inval_auth:
2422 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2423 data->auth_flavourlen);
2424 return -EINVAL;
2425
2426out_no_address:
2427 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2428 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002429
2430out_no_client_address:
2431 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2432 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002433}
2434
2435/*
David Howells54ceac42006-08-22 20:06:13 -04002436 * Get the superblock for an NFS4 mountpoint
2437 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002438static int nfs4_get_sb(struct file_system_type *fs_type,
2439 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002440{
Trond Myklebust33852a12008-06-19 14:20:11 -04002441 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002442 struct super_block *s;
2443 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002444 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002445 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002446 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002447 struct nfs_sb_mountdata sb_mntdata = {
2448 .mntflags = flags,
2449 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002450 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002451
Trond Myklebust33852a12008-06-19 14:20:11 -04002452 data = kzalloc(sizeof(*data), GFP_KERNEL);
2453 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2454 if (data == NULL || mntfh == NULL)
2455 goto out_free_fh;
2456
2457 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002458
Chuck Leverf0768eb2007-07-01 12:13:01 -04002459 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002460 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002461 if (error < 0)
2462 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002463
David Howells54ceac42006-08-22 20:06:13 -04002464 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002465 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002466 if (IS_ERR(server)) {
2467 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002468 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002469 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002470 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002471
Trond Myklebust75180df2007-05-16 16:53:28 -04002472 if (server->flags & NFS4_MOUNT_UNSHARED)
2473 compare_super = NULL;
2474
David Howells54ceac42006-08-22 20:06:13 -04002475 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002476 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002477 if (IS_ERR(s)) {
2478 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002479 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002480 }
2481
Trond Myklebust5dd31772006-08-24 01:03:05 -04002482 if (s->s_fs_info != server) {
2483 nfs_free_server(server);
2484 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002485 } else {
2486 error = nfs_bdi_register(server);
2487 if (error)
2488 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002489 }
2490
David Howells54ceac42006-08-22 20:06:13 -04002491 if (!s->s_root) {
2492 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002493 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002494 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002495 }
David Howellsf7b422b2006-06-09 09:34:33 -04002496
Trond Myklebust33852a12008-06-19 14:20:11 -04002497 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002498 if (IS_ERR(mntroot)) {
2499 error = PTR_ERR(mntroot);
2500 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002501 }
David Howells54ceac42006-08-22 20:06:13 -04002502
Trond Myklebust33852a12008-06-19 14:20:11 -04002503 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002504 if (error)
2505 goto error_splat_root;
2506
David Howellsf7b422b2006-06-09 09:34:33 -04002507 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002508 mnt->mnt_sb = s;
2509 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002510 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002511
Chuck Lever29eb9812007-07-01 12:12:30 -04002512out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002513 kfree(data->client_address);
2514 kfree(data->nfs_server.export_path);
2515 kfree(data->nfs_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002516 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002517 security_free_mnt_opts(&data->lsm_opts);
2518out_free_fh:
2519 kfree(mntfh);
2520 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002521 return error;
David Howells54ceac42006-08-22 20:06:13 -04002522
Chuck Lever29eb9812007-07-01 12:12:30 -04002523out_free:
2524 nfs_free_server(server);
2525 goto out;
2526
Eric Paris46c8ac72008-05-02 13:42:42 -07002527error_splat_root:
2528 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002529error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002530 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002531 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002532}
2533
2534static void nfs4_kill_super(struct super_block *sb)
2535{
2536 struct nfs_server *server = NFS_SB(sb);
2537
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002538 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002539 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002540 kill_anon_super(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002541 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002542 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002543 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002544 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002545}
2546
2547/*
David Howells54ceac42006-08-22 20:06:13 -04002548 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002549 */
David Howells54ceac42006-08-22 20:06:13 -04002550static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2551 const char *dev_name, void *raw_data,
2552 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002553{
2554 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002555 struct super_block *s;
2556 struct nfs_server *server;
2557 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002558 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002559 struct nfs_sb_mountdata sb_mntdata = {
2560 .mntflags = flags,
2561 };
David Howells54ceac42006-08-22 20:06:13 -04002562 int error;
2563
2564 dprintk("--> nfs4_xdev_get_sb()\n");
2565
2566 /* create a new volume representation */
2567 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2568 if (IS_ERR(server)) {
2569 error = PTR_ERR(server);
2570 goto out_err_noserver;
2571 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002572 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002573
Trond Myklebust75180df2007-05-16 16:53:28 -04002574 if (server->flags & NFS4_MOUNT_UNSHARED)
2575 compare_super = NULL;
2576
David Howells54ceac42006-08-22 20:06:13 -04002577 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002578 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002579 if (IS_ERR(s)) {
2580 error = PTR_ERR(s);
2581 goto out_err_nosb;
2582 }
2583
2584 if (s->s_fs_info != server) {
2585 nfs_free_server(server);
2586 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002587 } else {
2588 error = nfs_bdi_register(server);
2589 if (error)
2590 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002591 }
2592
2593 if (!s->s_root) {
2594 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002595 nfs4_clone_super(s, data->sb);
2596 }
2597
2598 mntroot = nfs4_get_root(s, data->fh);
2599 if (IS_ERR(mntroot)) {
2600 error = PTR_ERR(mntroot);
2601 goto error_splat_super;
2602 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002603 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2604 dput(mntroot);
2605 error = -ESTALE;
2606 goto error_splat_super;
2607 }
David Howells54ceac42006-08-22 20:06:13 -04002608
2609 s->s_flags |= MS_ACTIVE;
2610 mnt->mnt_sb = s;
2611 mnt->mnt_root = mntroot;
2612
Eric Paris46c8ac72008-05-02 13:42:42 -07002613 security_sb_clone_mnt_opts(data->sb, s);
2614
David Howells54ceac42006-08-22 20:06:13 -04002615 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2616 return 0;
2617
2618out_err_nosb:
2619 nfs_free_server(server);
2620out_err_noserver:
2621 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2622 return error;
2623
2624error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002625 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002626 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2627 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002628}
2629
David Howells54ceac42006-08-22 20:06:13 -04002630/*
2631 * Create an NFS4 server record on referral traversal
2632 */
2633static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2634 const char *dev_name, void *raw_data,
2635 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002636{
2637 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002638 struct super_block *s;
2639 struct nfs_server *server;
2640 struct dentry *mntroot;
2641 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002642 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002643 struct nfs_sb_mountdata sb_mntdata = {
2644 .mntflags = flags,
2645 };
David Howells54ceac42006-08-22 20:06:13 -04002646 int error;
2647
2648 dprintk("--> nfs4_referral_get_sb()\n");
2649
2650 /* create a new volume representation */
2651 server = nfs4_create_referral_server(data, &mntfh);
2652 if (IS_ERR(server)) {
2653 error = PTR_ERR(server);
2654 goto out_err_noserver;
2655 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002656 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002657
Trond Myklebust75180df2007-05-16 16:53:28 -04002658 if (server->flags & NFS4_MOUNT_UNSHARED)
2659 compare_super = NULL;
2660
David Howells54ceac42006-08-22 20:06:13 -04002661 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002662 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002663 if (IS_ERR(s)) {
2664 error = PTR_ERR(s);
2665 goto out_err_nosb;
2666 }
2667
2668 if (s->s_fs_info != server) {
2669 nfs_free_server(server);
2670 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002671 } else {
2672 error = nfs_bdi_register(server);
2673 if (error)
2674 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002675 }
2676
2677 if (!s->s_root) {
2678 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002679 nfs4_fill_super(s);
2680 }
2681
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002682 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002683 if (IS_ERR(mntroot)) {
2684 error = PTR_ERR(mntroot);
2685 goto error_splat_super;
2686 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002687 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2688 dput(mntroot);
2689 error = -ESTALE;
2690 goto error_splat_super;
2691 }
David Howells54ceac42006-08-22 20:06:13 -04002692
2693 s->s_flags |= MS_ACTIVE;
2694 mnt->mnt_sb = s;
2695 mnt->mnt_root = mntroot;
2696
Eric Paris46c8ac72008-05-02 13:42:42 -07002697 security_sb_clone_mnt_opts(data->sb, s);
2698
David Howells54ceac42006-08-22 20:06:13 -04002699 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2700 return 0;
2701
2702out_err_nosb:
2703 nfs_free_server(server);
2704out_err_noserver:
2705 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2706 return error;
2707
2708error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002709 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002710 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2711 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002712}
2713
David Howells54ceac42006-08-22 20:06:13 -04002714#endif /* CONFIG_NFS_V4 */