blob: 9c85cdb353aa6d5238fe24209460e38d71592f8d [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>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040045#include <linux/mnt_namespace.h>
46#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040047#include <linux/nfs_idmap.h>
48#include <linux/vfs.h>
49#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <linux/in6.h>
51#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040052#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080054#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040055#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040056
57#include <asm/system.h>
58#include <asm/uaccess.h>
59
60#include "nfs4_fs.h"
61#include "callback.h"
62#include "delegation.h"
63#include "iostat.h"
64#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010065#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040066
67#define NFSDBG_FACILITY NFSDBG_VFS
68
Chuck Leverbf0fd762007-07-01 12:13:44 -040069enum {
70 /* Mount options that take no arguments */
71 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040072 Opt_posix, Opt_noposix,
73 Opt_cto, Opt_nocto,
74 Opt_ac, Opt_noac,
75 Opt_lock, Opt_nolock,
76 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040077 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_acl, Opt_noacl,
79 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040080 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050081 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010082 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040083
84 /* Mount options that take integer arguments */
85 Opt_port,
86 Opt_rsize, Opt_wsize, Opt_bsize,
87 Opt_timeo, Opt_retrans,
88 Opt_acregmin, Opt_acregmax,
89 Opt_acdirmin, Opt_acdirmax,
90 Opt_actimeo,
91 Opt_namelen,
92 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040093 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040094 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -040095 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -040096
97 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050098 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040099 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400100 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100101 Opt_fscache_uniq,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
Chuck Leverf45663c2008-06-24 19:28:02 -0400103 /* Special mount options */
104 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400105
106 Opt_err
107};
108
Steven Whitehousea447c092008-10-13 10:46:57 +0100109static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110 { Opt_userspace, "bg" },
111 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400112 { Opt_userspace, "retry=%s" },
113
Chuck Leverf45663c2008-06-24 19:28:02 -0400114 { Opt_sloppy, "sloppy" },
115
Chuck Leverbf0fd762007-07-01 12:13:44 -0400116 { Opt_soft, "soft" },
117 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400118 { Opt_deprecated, "intr" },
119 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400120 { Opt_posix, "posix" },
121 { Opt_noposix, "noposix" },
122 { Opt_cto, "cto" },
123 { Opt_nocto, "nocto" },
124 { Opt_ac, "ac" },
125 { Opt_noac, "noac" },
126 { Opt_lock, "lock" },
127 { Opt_nolock, "nolock" },
128 { Opt_v2, "v2" },
129 { Opt_v3, "v3" },
130 { Opt_udp, "udp" },
131 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400132 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400133 { Opt_acl, "acl" },
134 { Opt_noacl, "noacl" },
135 { Opt_rdirplus, "rdirplus" },
136 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400137 { Opt_sharecache, "sharecache" },
138 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500139 { Opt_resvport, "resvport" },
140 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100141 { Opt_fscache, "fsc" },
142 { Opt_fscache_uniq, "fsc=%s" },
143 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144
Chuck Levera5a16ba2009-06-17 18:02:14 -0700145 { Opt_port, "port=%s" },
146 { Opt_rsize, "rsize=%s" },
147 { Opt_wsize, "wsize=%s" },
148 { Opt_bsize, "bsize=%s" },
149 { Opt_timeo, "timeo=%s" },
150 { Opt_retrans, "retrans=%s" },
151 { Opt_acregmin, "acregmin=%s" },
152 { Opt_acregmax, "acregmax=%s" },
153 { Opt_acdirmin, "acdirmin=%s" },
154 { Opt_acdirmax, "acdirmax=%s" },
155 { Opt_actimeo, "actimeo=%s" },
156 { Opt_namelen, "namlen=%s" },
157 { Opt_mountport, "mountport=%s" },
158 { Opt_mountvers, "mountvers=%s" },
159 { Opt_nfsvers, "nfsvers=%s" },
160 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400161 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400162
163 { Opt_sec, "sec=%s" },
164 { Opt_proto, "proto=%s" },
165 { Opt_mountproto, "mountproto=%s" },
166 { Opt_addr, "addr=%s" },
167 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500168 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400169 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400170
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400171 { Opt_lookupcache, "lookupcache=%s" },
172
Chuck Leverbf0fd762007-07-01 12:13:44 -0400173 { Opt_err, NULL }
174};
175
176enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400177 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400178
179 Opt_xprt_err
180};
181
Steven Whitehousea447c092008-10-13 10:46:57 +0100182static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400183 { Opt_xprt_udp, "udp" },
184 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400185 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400186
187 { Opt_xprt_err, NULL }
188};
189
190enum {
191 Opt_sec_none, Opt_sec_sys,
192 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
193 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
194 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
195
196 Opt_sec_err
197};
198
Steven Whitehousea447c092008-10-13 10:46:57 +0100199static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400200 { Opt_sec_none, "none" },
201 { Opt_sec_none, "null" },
202 { Opt_sec_sys, "sys" },
203
204 { Opt_sec_krb5, "krb5" },
205 { Opt_sec_krb5i, "krb5i" },
206 { Opt_sec_krb5p, "krb5p" },
207
208 { Opt_sec_lkey, "lkey" },
209 { Opt_sec_lkeyi, "lkeyi" },
210 { Opt_sec_lkeyp, "lkeyp" },
211
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500212 { Opt_sec_spkm, "spkm3" },
213 { Opt_sec_spkmi, "spkm3i" },
214 { Opt_sec_spkmp, "spkm3p" },
215
Chuck Leverbf0fd762007-07-01 12:13:44 -0400216 { Opt_sec_err, NULL }
217};
218
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400219enum {
220 Opt_lookupcache_all, Opt_lookupcache_positive,
221 Opt_lookupcache_none,
222
223 Opt_lookupcache_err
224};
225
226static match_table_t nfs_lookupcache_tokens = {
227 { Opt_lookupcache_all, "all" },
228 { Opt_lookupcache_positive, "pos" },
229 { Opt_lookupcache_positive, "positive" },
230 { Opt_lookupcache_none, "none" },
231
232 { Opt_lookupcache_err, NULL }
233};
234
Chuck Leverbf0fd762007-07-01 12:13:44 -0400235
Al Viro42faad92008-04-24 07:21:56 -0400236static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400237static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400238static int nfs_show_options(struct seq_file *, struct vfsmount *);
239static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400240static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400241static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400242 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400243static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400244static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400245
246static struct file_system_type nfs_fs_type = {
247 .owner = THIS_MODULE,
248 .name = "nfs",
249 .get_sb = nfs_get_sb,
250 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700251 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400252};
253
David Howells54ceac42006-08-22 20:06:13 -0400254struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400255 .owner = THIS_MODULE,
256 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400257 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400258 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400260};
261
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800262static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode,
266 .statfs = nfs_statfs,
267 .clear_inode = nfs_clear_inode,
268 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400271 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400272};
273
274#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400275static int nfs4_get_sb(struct file_system_type *fs_type,
276 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400277static int nfs4_remote_get_sb(struct file_system_type *fs_type,
278 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400279static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
280 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
281static int nfs4_referral_get_sb(struct file_system_type *fs_type,
282 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400283static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
284 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400285static void nfs4_kill_super(struct super_block *sb);
286
287static struct file_system_type nfs4_fs_type = {
288 .owner = THIS_MODULE,
289 .name = "nfs4",
290 .get_sb = nfs4_get_sb,
291 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700292 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400293};
294
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400295static struct file_system_type nfs4_remote_fs_type = {
296 .owner = THIS_MODULE,
297 .name = "nfs4",
298 .get_sb = nfs4_remote_get_sb,
299 .kill_sb = nfs4_kill_super,
300 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
301};
302
David Howells54ceac42006-08-22 20:06:13 -0400303struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400304 .owner = THIS_MODULE,
305 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400306 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400307 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700308 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400309};
310
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400311static struct file_system_type nfs4_remote_referral_fs_type = {
312 .owner = THIS_MODULE,
313 .name = "nfs4",
314 .get_sb = nfs4_remote_referral_get_sb,
315 .kill_sb = nfs4_kill_super,
316 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
317};
318
David Howells54ceac42006-08-22 20:06:13 -0400319struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400320 .owner = THIS_MODULE,
321 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400322 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400323 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700324 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400325};
326
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800327static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400328 .alloc_inode = nfs_alloc_inode,
329 .destroy_inode = nfs_destroy_inode,
330 .write_inode = nfs_write_inode,
331 .statfs = nfs_statfs,
332 .clear_inode = nfs4_clear_inode,
333 .umount_begin = nfs_umount_begin,
334 .show_options = nfs_show_options,
335 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400336 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400337};
338#endif
339
Rusty Russell8e1f9362007-07-17 04:03:17 -0700340static struct shrinker acl_shrinker = {
341 .shrink = nfs_access_cache_shrinker,
342 .seeks = DEFAULT_SEEKS,
343};
Trond Myklebust979df722006-07-25 11:28:19 -0400344
David Howellsf7b422b2006-06-09 09:34:33 -0400345/*
346 * Register the NFS filesystems
347 */
348int __init register_nfs_fs(void)
349{
350 int ret;
351
352 ret = register_filesystem(&nfs_fs_type);
353 if (ret < 0)
354 goto error_0;
355
David Howellsf7b422b2006-06-09 09:34:33 -0400356 ret = nfs_register_sysctl();
357 if (ret < 0)
358 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800359#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400360 ret = register_filesystem(&nfs4_fs_type);
361 if (ret < 0)
362 goto error_2;
363#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700364 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400365 return 0;
366
367#ifdef CONFIG_NFS_V4
368error_2:
369 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800370#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400371error_1:
372 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400373error_0:
374 return ret;
375}
376
377/*
378 * Unregister the NFS filesystems
379 */
380void __exit unregister_nfs_fs(void)
381{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700382 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400383#ifdef CONFIG_NFS_V4
384 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400385#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700386 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400387 unregister_filesystem(&nfs_fs_type);
388}
389
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400390void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500391{
392 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400393
394 if (atomic_inc_return(&server->active) == 1)
395 atomic_inc(&sb->s_active);
396}
397
398void nfs_sb_deactive(struct super_block *sb)
399{
400 struct nfs_server *server = NFS_SB(sb);
401
402 if (atomic_dec_and_test(&server->active))
403 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500404}
405
David Howellsf7b422b2006-06-09 09:34:33 -0400406/*
407 * Deliver file system statistics to userspace
408 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400409static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400410{
David Howells0c7d90c2006-08-22 20:06:10 -0400411 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400412 unsigned char blockbits;
413 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400414 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400415 struct nfs_fattr fattr;
416 struct nfs_fsstat res = {
417 .fattr = &fattr,
418 };
419 int error;
420
David Howells8fa5c002006-08-22 20:06:12 -0400421 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400422 if (error < 0)
423 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700424 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400425
426 /*
427 * Current versions of glibc do not correctly handle the
428 * case where f_frsize != f_bsize. Eventually we want to
429 * report the value of wtmult in this field.
430 */
David Howells0c7d90c2006-08-22 20:06:10 -0400431 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400432
433 /*
434 * On most *nix systems, f_blocks, f_bfree, and f_bavail
435 * are reported in units of f_frsize. Linux hasn't had
436 * an f_frsize field in its statfs struct until recently,
437 * thus historically Linux's sys_statfs reports these
438 * fields in units of f_bsize.
439 */
David Howells0c7d90c2006-08-22 20:06:10 -0400440 buf->f_bsize = dentry->d_sb->s_blocksize;
441 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400442 blockres = (1 << blockbits) - 1;
443 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
444 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
445 buf->f_bavail = (res.abytes + blockres) >> blockbits;
446
447 buf->f_files = res.tfiles;
448 buf->f_ffree = res.afiles;
449
450 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700451
David Howellsf7b422b2006-06-09 09:34:33 -0400452 return 0;
453
454 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700455 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700456 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400457}
458
David Howells7d4e2742006-08-22 20:06:07 -0400459/*
460 * Map the security flavour number to a name
461 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400462static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
463{
David Howells7d4e2742006-08-22 20:06:07 -0400464 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400465 rpc_authflavor_t flavour;
466 const char *str;
467 } sec_flavours[] = {
468 { RPC_AUTH_NULL, "null" },
469 { RPC_AUTH_UNIX, "sys" },
470 { RPC_AUTH_GSS_KRB5, "krb5" },
471 { RPC_AUTH_GSS_KRB5I, "krb5i" },
472 { RPC_AUTH_GSS_KRB5P, "krb5p" },
473 { RPC_AUTH_GSS_LKEY, "lkey" },
474 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
475 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
476 { RPC_AUTH_GSS_SPKM, "spkm" },
477 { RPC_AUTH_GSS_SPKMI, "spkmi" },
478 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400479 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400480 };
481 int i;
482
Chuck Lever4d81cd12007-07-01 12:12:40 -0400483 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400484 if (sec_flavours[i].flavour == flavour)
485 break;
486 }
487 return sec_flavours[i].str;
488}
489
Chuck Lever82d101d2008-03-14 14:10:37 -0400490static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
491 int showdefaults)
492{
493 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
494
495 switch (sap->sa_family) {
496 case AF_INET: {
497 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700498 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400499 break;
500 }
501 case AF_INET6: {
502 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700503 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400504 break;
505 }
506 default:
507 if (showdefaults)
508 seq_printf(m, ",mountaddr=unspecified");
509 }
510
511 if (nfss->mountd_version || showdefaults)
512 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
513 if (nfss->mountd_port || showdefaults)
514 seq_printf(m, ",mountport=%u", nfss->mountd_port);
515
516 switch (nfss->mountd_protocol) {
517 case IPPROTO_UDP:
518 seq_printf(m, ",mountproto=udp");
519 break;
520 case IPPROTO_TCP:
521 seq_printf(m, ",mountproto=tcp");
522 break;
523 default:
524 if (showdefaults)
525 seq_printf(m, ",mountproto=auto");
526 }
527}
528
David Howellsf7b422b2006-06-09 09:34:33 -0400529/*
530 * Describe the mount options in force on this server representation
531 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400532static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
533 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400534{
David Howells509de812006-08-22 20:06:11 -0400535 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400536 int flag;
David Howells509de812006-08-22 20:06:11 -0400537 const char *str;
538 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400539 } nfs_info[] = {
540 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400541 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400542 { NFS_MOUNT_NOCTO, ",nocto", "" },
543 { NFS_MOUNT_NOAC, ",noac", "" },
544 { NFS_MOUNT_NONLM, ",nolock", "" },
545 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400546 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500547 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
548 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400549 { 0, NULL, NULL }
550 };
David Howells509de812006-08-22 20:06:11 -0400551 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400552 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400553 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400554
Chuck Lever82d101d2008-03-14 14:10:37 -0400555 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400556 seq_printf(m, ",rsize=%u", nfss->rsize);
557 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400558 if (nfss->bsize != 0)
559 seq_printf(m, ",bsize=%u", nfss->bsize);
560 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400561 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400562 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400563 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400564 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400565 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400566 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400567 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400568 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400569 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
570 if (nfss->flags & nfs_infop->flag)
571 seq_puts(m, nfs_infop->str);
572 else
573 seq_puts(m, nfs_infop->nostr);
574 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400575 seq_printf(m, ",proto=%s",
576 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400577 if (version == 4) {
578 if (nfss->port != NFS_PORT)
579 seq_printf(m, ",port=%u", nfss->port);
580 } else
581 if (nfss->port)
582 seq_printf(m, ",port=%u", nfss->port);
583
Trond Myklebust33170232007-12-20 16:03:59 -0500584 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
585 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400586 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400587
588 if (version != 4)
589 nfs_show_mountd_options(m, nfss, showdefaults);
590
591#ifdef CONFIG_NFS_V4
592 if (clp->rpc_ops->version == 4)
593 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
594#endif
David Howellsb797cac2009-04-03 16:42:48 +0100595 if (nfss->options & NFS_OPTION_FSCACHE)
596 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400597}
598
599/*
600 * Describe the mount options on this VFS mountpoint
601 */
602static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
603{
604 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
605
606 nfs_show_mount_options(m, nfss, 0);
607
Chuck Lever5d8515c2007-12-10 14:57:16 -0500608 seq_printf(m, ",addr=%s",
609 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
610 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400611
612 return 0;
613}
614
615/*
616 * Present statistical information for this VFS mountpoint
617 */
618static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
619{
620 int i, cpu;
621 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
622 struct rpc_auth *auth = nfss->client->cl_auth;
623 struct nfs_iostats totals = { };
624
625 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
626
627 /*
628 * Display all mount option settings
629 */
630 seq_printf(m, "\n\topts:\t");
631 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
632 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
633 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
634 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
635 nfs_show_mount_options(m, nfss, 1);
636
637 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
638
639 seq_printf(m, "\n\tcaps:\t");
640 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400641 seq_printf(m, ",wtmult=%u", nfss->wtmult);
642 seq_printf(m, ",dtsize=%u", nfss->dtsize);
643 seq_printf(m, ",bsize=%u", nfss->bsize);
644 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400645
646#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500647 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400648 seq_printf(m, "\n\tnfsv4:\t");
649 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
650 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
651 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
652 }
653#endif
654
655 /*
656 * Display security flavor in effect for this mount
657 */
Chuck Lever2d767432008-03-14 14:10:08 -0400658 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400659 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400660 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400661
662 /*
663 * Display superblock I/O counters
664 */
665 for_each_possible_cpu(cpu) {
666 struct nfs_iostats *stats;
667
668 preempt_disable();
669 stats = per_cpu_ptr(nfss->io_stats, cpu);
670
671 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
672 totals.events[i] += stats->events[i];
673 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
674 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100675#ifdef CONFIG_NFS_FSCACHE
676 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
677 totals.fscache[i] += stats->fscache[i];
678#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400679
680 preempt_enable();
681 }
682
683 seq_printf(m, "\n\tevents:\t");
684 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
685 seq_printf(m, "%lu ", totals.events[i]);
686 seq_printf(m, "\n\tbytes:\t");
687 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
688 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100689#ifdef CONFIG_NFS_FSCACHE
690 if (nfss->options & NFS_OPTION_FSCACHE) {
691 seq_printf(m, "\n\tfsc:\t");
692 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
693 seq_printf(m, "%Lu ", totals.bytes[i]);
694 }
695#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400696 seq_printf(m, "\n");
697
698 rpc_print_iostats(m, nfss->client);
699
700 return 0;
701}
702
703/*
704 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400705 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400706 */
Al Viro42faad92008-04-24 07:21:56 -0400707static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400708{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200709 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400710 struct rpc_clnt *rpc;
711
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200712 lock_kernel();
713
714 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400715 /* -EIO all pending I/O */
716 rpc = server->client_acl;
717 if (!IS_ERR(rpc))
718 rpc_killall_tasks(rpc);
719 rpc = server->client;
720 if (!IS_ERR(rpc))
721 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200722
723 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400724}
725
726/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500727 * Sanity-check a server address provided by the mount command.
728 *
729 * Address family must be initialized, and address must not be
730 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400731 */
732static int nfs_verify_server_address(struct sockaddr *addr)
733{
734 switch (addr->sa_family) {
735 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500736 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700737 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500738 }
739 case AF_INET6: {
740 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
741 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400742 }
743 }
744
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400745 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400746 return 0;
747}
748
Chuck Lever9412b922007-12-10 14:59:21 -0500749/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400750 * Sanity check the NFS transport protocol.
751 *
752 */
753static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
754{
755 switch (mnt->nfs_server.protocol) {
756 case XPRT_TRANSPORT_UDP:
757 case XPRT_TRANSPORT_TCP:
758 case XPRT_TRANSPORT_RDMA:
759 break;
760 default:
761 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
762 }
763}
764
765/*
766 * For text based NFSv2/v3 mounts, the mount protocol transport default
767 * settings should depend upon the specified NFS transport.
768 */
769static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
770{
771 nfs_validate_transport_protocol(mnt);
772
773 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
774 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
775 return;
776 switch (mnt->nfs_server.protocol) {
777 case XPRT_TRANSPORT_UDP:
778 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
779 break;
780 case XPRT_TRANSPORT_TCP:
781 case XPRT_TRANSPORT_RDMA:
782 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
783 }
784}
785
786/*
Chuck Lever01060c82008-06-24 16:33:38 -0400787 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400788 */
789static int nfs_parse_security_flavors(char *value,
790 struct nfs_parsed_mount_data *mnt)
791{
792 substring_t args[MAX_OPT_ARGS];
793
794 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
795
796 switch (match_token(value, nfs_secflavor_tokens, args)) {
797 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400798 mnt->auth_flavors[0] = RPC_AUTH_NULL;
799 break;
800 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400801 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
802 break;
803 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400804 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
805 break;
806 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400807 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
808 break;
809 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400810 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
811 break;
812 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400813 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
814 break;
815 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400816 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
817 break;
818 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400819 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
820 break;
821 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400822 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
823 break;
824 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400825 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
826 break;
827 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400828 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
829 break;
830 default:
831 return 0;
832 }
833
Chuck Lever059f90b2009-08-09 15:09:31 -0400834 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400835 return 1;
836}
837
838/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400839 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400840 * a data structure. The whole mount string is processed; bad options are
841 * skipped as they are encountered. If there were no errors, return 1;
842 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400843 */
844static int nfs_parse_mount_options(char *raw,
845 struct nfs_parsed_mount_data *mnt)
846{
Eric Parisf9c3a382008-03-05 14:20:18 -0500847 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700848 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400849
850 if (!raw) {
851 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
852 return 1;
853 }
854 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
855
Eric Parisf9c3a382008-03-05 14:20:18 -0500856 secdata = alloc_secdata();
857 if (!secdata)
858 goto out_nomem;
859
860 rc = security_sb_copy_data(raw, secdata);
861 if (rc)
862 goto out_security_failure;
863
864 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
865 if (rc)
866 goto out_security_failure;
867
868 free_secdata(secdata);
869
Chuck Leverbf0fd762007-07-01 12:13:44 -0400870 while ((p = strsep(&raw, ",")) != NULL) {
871 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700872 unsigned long option;
873 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400874
875 if (!*p)
876 continue;
877
878 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
879
880 token = match_token(p, nfs_mount_option_tokens, args);
881 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400882
883 /*
884 * boolean options: foo/nofoo
885 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400886 case Opt_soft:
887 mnt->flags |= NFS_MOUNT_SOFT;
888 break;
889 case Opt_hard:
890 mnt->flags &= ~NFS_MOUNT_SOFT;
891 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400892 case Opt_posix:
893 mnt->flags |= NFS_MOUNT_POSIX;
894 break;
895 case Opt_noposix:
896 mnt->flags &= ~NFS_MOUNT_POSIX;
897 break;
898 case Opt_cto:
899 mnt->flags &= ~NFS_MOUNT_NOCTO;
900 break;
901 case Opt_nocto:
902 mnt->flags |= NFS_MOUNT_NOCTO;
903 break;
904 case Opt_ac:
905 mnt->flags &= ~NFS_MOUNT_NOAC;
906 break;
907 case Opt_noac:
908 mnt->flags |= NFS_MOUNT_NOAC;
909 break;
910 case Opt_lock:
911 mnt->flags &= ~NFS_MOUNT_NONLM;
912 break;
913 case Opt_nolock:
914 mnt->flags |= NFS_MOUNT_NONLM;
915 break;
916 case Opt_v2:
917 mnt->flags &= ~NFS_MOUNT_VER3;
918 break;
919 case Opt_v3:
920 mnt->flags |= NFS_MOUNT_VER3;
921 break;
922 case Opt_udp:
923 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400924 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400925 break;
926 case Opt_tcp:
927 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400928 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400929 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400930 case Opt_rdma:
931 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
932 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -0400933 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400934 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400935 case Opt_acl:
936 mnt->flags &= ~NFS_MOUNT_NOACL;
937 break;
938 case Opt_noacl:
939 mnt->flags |= NFS_MOUNT_NOACL;
940 break;
941 case Opt_rdirplus:
942 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
943 break;
944 case Opt_nordirplus:
945 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
946 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400947 case Opt_sharecache:
948 mnt->flags &= ~NFS_MOUNT_UNSHARED;
949 break;
950 case Opt_nosharecache:
951 mnt->flags |= NFS_MOUNT_UNSHARED;
952 break;
Chuck Leverd7403512008-12-23 15:21:37 -0500953 case Opt_resvport:
954 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
955 break;
956 case Opt_noresvport:
957 mnt->flags |= NFS_MOUNT_NORESVPORT;
958 break;
David Howellsb797cac2009-04-03 16:42:48 +0100959 case Opt_fscache:
960 mnt->options |= NFS_OPTION_FSCACHE;
961 kfree(mnt->fscache_uniq);
962 mnt->fscache_uniq = NULL;
963 break;
964 case Opt_nofscache:
965 mnt->options &= ~NFS_OPTION_FSCACHE;
966 kfree(mnt->fscache_uniq);
967 mnt->fscache_uniq = NULL;
968 break;
969 case Opt_fscache_uniq:
970 string = match_strdup(args);
971 if (!string)
972 goto out_nomem;
973 kfree(mnt->fscache_uniq);
974 mnt->fscache_uniq = string;
975 mnt->options |= NFS_OPTION_FSCACHE;
976 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400977
Chuck Leverf45663c2008-06-24 19:28:02 -0400978 /*
979 * options that take numeric values
980 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400981 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -0700982 string = match_strdup(args);
983 if (string == NULL)
984 goto out_nomem;
985 rc = strict_strtoul(string, 10, &option);
986 kfree(string);
987 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -0700988 goto out_invalid_value;
989 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400990 break;
991 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -0700992 string = match_strdup(args);
993 if (string == NULL)
994 goto out_nomem;
995 rc = strict_strtoul(string, 10, &option);
996 kfree(string);
997 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -0700998 goto out_invalid_value;
999 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 break;
1001 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001002 string = match_strdup(args);
1003 if (string == NULL)
1004 goto out_nomem;
1005 rc = strict_strtoul(string, 10, &option);
1006 kfree(string);
1007 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001008 goto out_invalid_value;
1009 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001010 break;
1011 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001012 string = match_strdup(args);
1013 if (string == NULL)
1014 goto out_nomem;
1015 rc = strict_strtoul(string, 10, &option);
1016 kfree(string);
1017 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001018 goto out_invalid_value;
1019 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001020 break;
1021 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001022 string = match_strdup(args);
1023 if (string == NULL)
1024 goto out_nomem;
1025 rc = strict_strtoul(string, 10, &option);
1026 kfree(string);
1027 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001028 goto out_invalid_value;
1029 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001030 break;
1031 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001032 string = match_strdup(args);
1033 if (string == NULL)
1034 goto out_nomem;
1035 rc = strict_strtoul(string, 10, &option);
1036 kfree(string);
1037 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001038 goto out_invalid_value;
1039 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001040 break;
1041 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001042 string = match_strdup(args);
1043 if (string == NULL)
1044 goto out_nomem;
1045 rc = strict_strtoul(string, 10, &option);
1046 kfree(string);
1047 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001048 goto out_invalid_value;
1049 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001050 break;
1051 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001052 string = match_strdup(args);
1053 if (string == NULL)
1054 goto out_nomem;
1055 rc = strict_strtoul(string, 10, &option);
1056 kfree(string);
1057 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001058 goto out_invalid_value;
1059 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001060 break;
1061 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001062 string = match_strdup(args);
1063 if (string == NULL)
1064 goto out_nomem;
1065 rc = strict_strtoul(string, 10, &option);
1066 kfree(string);
1067 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001068 goto out_invalid_value;
1069 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001070 break;
1071 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001072 string = match_strdup(args);
1073 if (string == NULL)
1074 goto out_nomem;
1075 rc = strict_strtoul(string, 10, &option);
1076 kfree(string);
1077 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001078 goto out_invalid_value;
1079 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001080 break;
1081 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001082 string = match_strdup(args);
1083 if (string == NULL)
1084 goto out_nomem;
1085 rc = strict_strtoul(string, 10, &option);
1086 kfree(string);
1087 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001088 goto out_invalid_value;
1089 mnt->acregmin = mnt->acregmax =
1090 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001091 break;
1092 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001093 string = match_strdup(args);
1094 if (string == NULL)
1095 goto out_nomem;
1096 rc = strict_strtoul(string, 10, &option);
1097 kfree(string);
1098 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001099 goto out_invalid_value;
1100 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 break;
1102 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001103 string = match_strdup(args);
1104 if (string == NULL)
1105 goto out_nomem;
1106 rc = strict_strtoul(string, 10, &option);
1107 kfree(string);
1108 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001109 goto out_invalid_value;
1110 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001111 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001112 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001113 string = match_strdup(args);
1114 if (string == NULL)
1115 goto out_nomem;
1116 rc = strict_strtoul(string, 10, &option);
1117 kfree(string);
1118 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001119 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001120 option > NFS_MNT3_VERSION)
1121 goto out_invalid_value;
1122 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001123 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001124 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001125 string = match_strdup(args);
1126 if (string == NULL)
1127 goto out_nomem;
1128 rc = strict_strtoul(string, 10, &option);
1129 kfree(string);
1130 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001131 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001132 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001133 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001134 mnt->flags &= ~NFS_MOUNT_VER3;
1135 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001136 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001137 mnt->flags |= NFS_MOUNT_VER3;
1138 break;
1139 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001140 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001141 }
1142 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001143 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001144 string = match_strdup(args);
1145 if (string == NULL)
1146 goto out_nomem;
1147 rc = strict_strtoul(string, 10, &option);
1148 kfree(string);
1149 if (rc != 0)
1150 goto out_invalid_value;
1151 if (option > NFS4_MAX_MINOR_VERSION)
1152 goto out_invalid_value;
1153 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001154 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001155
Chuck Leverf45663c2008-06-24 19:28:02 -04001156 /*
1157 * options that take text values
1158 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001159 case Opt_sec:
1160 string = match_strdup(args);
1161 if (string == NULL)
1162 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001163 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001164 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001165 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001166 dfprintk(MOUNT, "NFS: unrecognized "
1167 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001168 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001169 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 break;
1171 case Opt_proto:
1172 string = match_strdup(args);
1173 if (string == NULL)
1174 goto out_nomem;
1175 token = match_token(string,
1176 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177
1178 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001179 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001181 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001182 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001183 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001184 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001185 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001186 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001187 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001189 case Opt_xprt_rdma:
1190 /* vector side protocols to TCP */
1191 mnt->flags |= NFS_MOUNT_TCP;
1192 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001193 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001194 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001195 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001196 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001197 dfprintk(MOUNT, "NFS: unrecognized "
1198 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001199 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 }
1201 break;
1202 case Opt_mountproto:
1203 string = match_strdup(args);
1204 if (string == NULL)
1205 goto out_nomem;
1206 token = match_token(string,
1207 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001208 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209
1210 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001211 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001212 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001213 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001214 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001215 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001217 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001219 dfprintk(MOUNT, "NFS: unrecognized "
1220 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001221 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001222 }
1223 break;
1224 case Opt_addr:
1225 string = match_strdup(args);
1226 if (string == NULL)
1227 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001228 mnt->nfs_server.addrlen =
1229 rpc_pton(string, strlen(string),
1230 (struct sockaddr *)
1231 &mnt->nfs_server.address,
1232 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001233 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001234 if (mnt->nfs_server.addrlen == 0)
1235 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236 break;
1237 case Opt_clientaddr:
1238 string = match_strdup(args);
1239 if (string == NULL)
1240 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001241 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 mnt->client_address = string;
1243 break;
Chuck Lever33832032007-12-10 14:59:13 -05001244 case Opt_mounthost:
1245 string = match_strdup(args);
1246 if (string == NULL)
1247 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001248 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001249 mnt->mount_server.hostname = string;
1250 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001251 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 string = match_strdup(args);
1253 if (string == NULL)
1254 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001255 mnt->mount_server.addrlen =
1256 rpc_pton(string, strlen(string),
1257 (struct sockaddr *)
1258 &mnt->mount_server.address,
1259 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001260 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001261 if (mnt->mount_server.addrlen == 0)
1262 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001263 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001264 case Opt_lookupcache:
1265 string = match_strdup(args);
1266 if (string == NULL)
1267 goto out_nomem;
1268 token = match_token(string,
1269 nfs_lookupcache_tokens, args);
1270 kfree(string);
1271 switch (token) {
1272 case Opt_lookupcache_all:
1273 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1274 break;
1275 case Opt_lookupcache_positive:
1276 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1277 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1278 break;
1279 case Opt_lookupcache_none:
1280 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1281 break;
1282 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001283 dfprintk(MOUNT, "NFS: invalid "
1284 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001285 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001286 };
1287 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288
Chuck Leverf45663c2008-06-24 19:28:02 -04001289 /*
1290 * Special options
1291 */
1292 case Opt_sloppy:
1293 sloppy = 1;
1294 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1295 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296 case Opt_userspace:
1297 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001298 dfprintk(MOUNT, "NFS: ignoring mount option "
1299 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300 break;
1301
1302 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001303 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001304 dfprintk(MOUNT, "NFS: unrecognized mount option "
1305 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 }
1307 }
1308
Chuck Leverd23c45f2009-06-17 18:02:13 -07001309 if (!sloppy && invalid_option)
1310 return 0;
1311
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 return 1;
1313
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001314out_invalid_address:
1315 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1316 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001317out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001318 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001319 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001320out_nomem:
1321 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1322 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001323out_security_failure:
1324 free_secdata(secdata);
1325 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1326 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001327}
1328
1329/*
Chuck Leverec88f282009-08-09 15:09:32 -04001330 * Match the requested auth flavors with the list returned by
1331 * the server. Returns zero and sets the mount's authentication
1332 * flavor on success; returns -EACCES if server does not support
1333 * the requested flavor.
1334 */
1335static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1336 struct nfs_mount_request *request)
1337{
1338 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1339
1340 /*
1341 * We avoid sophisticated negotiating here, as there are
1342 * plenty of cases where we can get it wrong, providing
1343 * either too little or too much security.
1344 *
1345 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1346 * flavor listed first. However, some servers list
1347 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1348 * preferred default, in args->auth_flavors[0] if user
1349 * didn't specify sec= mount option.
1350 */
1351 for (i = 0; i < args->auth_flavor_len; i++)
1352 for (j = 0; j < server_authlist_len; j++)
1353 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1354 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1355 request->auth_flavs[j]);
1356 args->auth_flavors[0] = request->auth_flavs[j];
1357 return 0;
1358 }
1359
1360 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1361 nfs_umount(request);
1362 return -EACCES;
1363}
1364
1365/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001366 * Use the remote server's MOUNT service to request the NFS file handle
1367 * corresponding to the provided path.
1368 */
1369static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1370 struct nfs_fh *root_fh)
1371{
Chuck Leverec88f282009-08-09 15:09:32 -04001372 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1373 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001374 struct nfs_mount_request request = {
1375 .sap = (struct sockaddr *)
1376 &args->mount_server.address,
1377 .dirpath = args->nfs_server.export_path,
1378 .protocol = args->mount_server.protocol,
1379 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001380 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001381 .auth_flav_len = &server_authlist_len,
1382 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001383 };
Chuck Lever4c568012007-12-10 14:59:28 -05001384 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001385
1386 if (args->mount_server.version == 0) {
1387 if (args->flags & NFS_MOUNT_VER3)
1388 args->mount_server.version = NFS_MNT3_VERSION;
1389 else
1390 args->mount_server.version = NFS_MNT_VERSION;
1391 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001392 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001393
Chuck Lever33832032007-12-10 14:59:13 -05001394 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001395 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001396 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001397 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001398
Chuck Lever0076d7b2007-07-01 12:13:49 -04001399 /*
1400 * Construct the mount server's address.
1401 */
Chuck Lever4c568012007-12-10 14:59:28 -05001402 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001403 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001404 args->nfs_server.addrlen);
1405 args->mount_server.addrlen = args->nfs_server.addrlen;
1406 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001407 request.salen = args->mount_server.addrlen;
Chuck Lever4c568012007-12-10 14:59:28 -05001408
James Lentiniaad70002007-09-24 17:32:49 -04001409 /*
1410 * autobind will be used if mount_server.port == 0
1411 */
Chuck Leverec6ee612009-08-09 15:09:37 -04001412 rpc_set_port(request.sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001413
1414 /*
1415 * Now ask the mount server to map our export path
1416 * to a file handle.
1417 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001418 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001419 if (status != 0) {
1420 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1421 request.hostname, status);
1422 return status;
1423 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001424
Chuck Leverec88f282009-08-09 15:09:32 -04001425 /*
1426 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1427 */
1428 if (args->mount_server.version != NFS_MNT3_VERSION)
1429 return 0;
1430 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001431}
1432
Chuck Leverd1aa0822008-06-23 12:36:45 -04001433static int nfs_parse_simple_hostname(const char *dev_name,
1434 char **hostname, size_t maxnamlen,
1435 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001436{
1437 size_t len;
1438 char *colon, *comma;
1439
1440 colon = strchr(dev_name, ':');
1441 if (colon == NULL)
1442 goto out_bad_devname;
1443
1444 len = colon - dev_name;
1445 if (len > maxnamlen)
1446 goto out_hostname;
1447
1448 /* N.B. caller will free nfs_server.hostname in all cases */
1449 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1450 if (!*hostname)
1451 goto out_nomem;
1452
1453 /* kill possible hostname list: not supported */
1454 comma = strchr(*hostname, ',');
1455 if (comma != NULL) {
1456 if (comma == *hostname)
1457 goto out_bad_devname;
1458 *comma = '\0';
1459 }
1460
1461 colon++;
1462 len = strlen(colon);
1463 if (len > maxpathlen)
1464 goto out_path;
1465 *export_path = kstrndup(colon, len, GFP_KERNEL);
1466 if (!*export_path)
1467 goto out_nomem;
1468
1469 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1470 return 0;
1471
1472out_bad_devname:
1473 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1474 return -EINVAL;
1475
1476out_nomem:
1477 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1478 return -ENOMEM;
1479
1480out_hostname:
1481 dfprintk(MOUNT, "NFS: server hostname too long\n");
1482 return -ENAMETOOLONG;
1483
1484out_path:
1485 dfprintk(MOUNT, "NFS: export pathname too long\n");
1486 return -ENAMETOOLONG;
1487}
1488
1489/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001490 * Hostname has square brackets around it because it contains one or
1491 * more colons. We look for the first closing square bracket, and a
1492 * colon must follow it.
1493 */
1494static int nfs_parse_protected_hostname(const char *dev_name,
1495 char **hostname, size_t maxnamlen,
1496 char **export_path, size_t maxpathlen)
1497{
1498 size_t len;
1499 char *start, *end;
1500
1501 start = (char *)(dev_name + 1);
1502
1503 end = strchr(start, ']');
1504 if (end == NULL)
1505 goto out_bad_devname;
1506 if (*(end + 1) != ':')
1507 goto out_bad_devname;
1508
1509 len = end - start;
1510 if (len > maxnamlen)
1511 goto out_hostname;
1512
1513 /* N.B. caller will free nfs_server.hostname in all cases */
1514 *hostname = kstrndup(start, len, GFP_KERNEL);
1515 if (*hostname == NULL)
1516 goto out_nomem;
1517
1518 end += 2;
1519 len = strlen(end);
1520 if (len > maxpathlen)
1521 goto out_path;
1522 *export_path = kstrndup(end, len, GFP_KERNEL);
1523 if (!*export_path)
1524 goto out_nomem;
1525
1526 return 0;
1527
1528out_bad_devname:
1529 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1530 return -EINVAL;
1531
1532out_nomem:
1533 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1534 return -ENOMEM;
1535
1536out_hostname:
1537 dfprintk(MOUNT, "NFS: server hostname too long\n");
1538 return -ENAMETOOLONG;
1539
1540out_path:
1541 dfprintk(MOUNT, "NFS: export pathname too long\n");
1542 return -ENAMETOOLONG;
1543}
1544
1545/*
1546 * Split "dev_name" into "hostname:export_path".
1547 *
1548 * The leftmost colon demarks the split between the server's hostname
1549 * and the export path. If the hostname starts with a left square
1550 * bracket, then it may contain colons.
1551 *
1552 * Note: caller frees hostname and export path, even on error.
1553 */
1554static int nfs_parse_devname(const char *dev_name,
1555 char **hostname, size_t maxnamlen,
1556 char **export_path, size_t maxpathlen)
1557{
1558 if (*dev_name == '[')
1559 return nfs_parse_protected_hostname(dev_name,
1560 hostname, maxnamlen,
1561 export_path, maxpathlen);
1562
1563 return nfs_parse_simple_hostname(dev_name,
1564 hostname, maxnamlen,
1565 export_path, maxpathlen);
1566}
1567
1568/*
David Howells54ceac42006-08-22 20:06:13 -04001569 * Validate the NFS2/NFS3 mount data
1570 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001571 *
1572 * For option strings, user space handles the following behaviors:
1573 *
1574 * + DNS: mapping server host name to IP address ("addr=" option)
1575 *
1576 * + failure mode: how to behave if a mount request can't be handled
1577 * immediately ("fg/bg" option)
1578 *
1579 * + retry: how often to retry a mount request ("retry=" option)
1580 *
1581 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1582 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001583 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001584static int nfs_validate_mount_data(void *options,
1585 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001586 struct nfs_fh *mntfh,
1587 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001588{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001589 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001590
Chuck Lever5df36e72007-07-01 12:12:56 -04001591 if (data == NULL)
1592 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001593
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001594 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1595 args->rsize = NFS_MAX_FILE_IO_SIZE;
1596 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001597 args->acregmin = NFS_DEF_ACREGMIN;
1598 args->acregmax = NFS_DEF_ACREGMAX;
1599 args->acdirmin = NFS_DEF_ACDIRMIN;
1600 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001601 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001602 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001603 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001604 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04001605 args->auth_flavor_len = 1;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001606
David Howellsf7b422b2006-06-09 09:34:33 -04001607 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001608 case 1:
1609 data->namlen = 0;
1610 case 2:
1611 data->bsize = 0;
1612 case 3:
1613 if (data->flags & NFS_MOUNT_VER3)
1614 goto out_no_v3;
1615 data->root.size = NFS2_FHSIZE;
1616 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1617 case 4:
1618 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1619 goto out_no_sec;
1620 case 5:
1621 memset(data->context, 0, sizeof(data->context));
1622 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001623 if (data->flags & NFS_MOUNT_VER3) {
1624 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1625 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001626 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001627 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001628 mntfh->size = NFS2_FHSIZE;
1629
Chuck Lever5df36e72007-07-01 12:12:56 -04001630
1631 memcpy(mntfh->data, data->root.data, mntfh->size);
1632 if (mntfh->size < sizeof(mntfh->data))
1633 memset(mntfh->data + mntfh->size, 0,
1634 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001635
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001636 /*
1637 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1638 * can deal with.
1639 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001640 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001641 args->rsize = data->rsize;
1642 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001643 args->timeo = data->timeo;
1644 args->retrans = data->retrans;
1645 args->acregmin = data->acregmin;
1646 args->acregmax = data->acregmax;
1647 args->acdirmin = data->acdirmin;
1648 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001649
1650 memcpy(&args->nfs_server.address, &data->addr,
1651 sizeof(data->addr));
1652 args->nfs_server.addrlen = sizeof(data->addr);
1653 if (!nfs_verify_server_address((struct sockaddr *)
1654 &args->nfs_server.address))
1655 goto out_no_address;
1656
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001657 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001658 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001659 /* N.B. caller will free nfs_server.hostname in all cases */
1660 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1661 args->namlen = data->namlen;
1662 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001663
1664 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1665 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001666 if (!args->nfs_server.hostname)
1667 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001668
1669 /*
1670 * The legacy version 6 binary mount data from userspace has a
1671 * field used only to transport selinux information into the
1672 * the kernel. To continue to support that functionality we
1673 * have a touch of selinux knowledge here in the NFS code. The
1674 * userspace code converted context=blah to just blah so we are
1675 * converting back to the full string selinux understands.
1676 */
1677 if (data->context[0]){
1678#ifdef CONFIG_SECURITY_SELINUX
1679 int rc;
1680 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1681 if (!opts_str)
1682 return -ENOMEM;
1683 strcpy(opts_str, "context=");
1684 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1685 strcat(opts_str, &data->context[0]);
1686 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1687 kfree(opts_str);
1688 if (rc)
1689 return rc;
1690#else
1691 return -EINVAL;
1692#endif
1693 }
1694
Chuck Lever5df36e72007-07-01 12:12:56 -04001695 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001696 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001697 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001698
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001699 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001700 return -EINVAL;
1701
Chuck Lever6e88e062007-09-24 15:39:50 -04001702 if (!nfs_verify_server_address((struct sockaddr *)
1703 &args->nfs_server.address))
1704 goto out_no_address;
1705
Chuck Leverec6ee612009-08-09 15:09:37 -04001706 rpc_set_port((struct sockaddr *)&args->nfs_server.address,
Chuck Levered596a82008-06-26 17:47:05 -04001707 args->nfs_server.port);
1708
Trond Myklebust259875e2008-07-02 14:43:47 -04001709 nfs_set_mount_transport_protocol(args);
1710
Chuck Leverdc045892008-06-23 12:36:37 -04001711 status = nfs_parse_devname(dev_name,
1712 &args->nfs_server.hostname,
1713 PAGE_SIZE,
1714 &args->nfs_server.export_path,
1715 NFS_MAXPATHLEN);
1716 if (!status)
1717 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001718
Chuck Leverdc045892008-06-23 12:36:37 -04001719 kfree(args->nfs_server.export_path);
1720 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001721
Chuck Lever136d5582007-07-01 12:13:54 -04001722 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001723 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001724
Chuck Lever136d5582007-07-01 12:13:54 -04001725 break;
1726 }
David Howellsf7b422b2006-06-09 09:34:33 -04001727 }
David Howells54ceac42006-08-22 20:06:13 -04001728
David Howellsf7b422b2006-06-09 09:34:33 -04001729#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001730 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001731 goto out_v3_not_compiled;
1732#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001733
David Howells54ceac42006-08-22 20:06:13 -04001734 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001735
1736out_no_data:
1737 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1738 return -EINVAL;
1739
1740out_no_v3:
1741 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1742 data->version);
1743 return -EINVAL;
1744
1745out_no_sec:
1746 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1747 return -EINVAL;
1748
Chuck Lever5df36e72007-07-01 12:12:56 -04001749#ifndef CONFIG_NFS_V3
1750out_v3_not_compiled:
1751 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1752 return -EPROTONOSUPPORT;
1753#endif /* !CONFIG_NFS_V3 */
1754
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001755out_nomem:
1756 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1757 return -ENOMEM;
1758
Chuck Lever5df36e72007-07-01 12:12:56 -04001759out_no_address:
1760 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1761 return -EINVAL;
1762
1763out_invalid_fh:
1764 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1765 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001766}
1767
Jeff Layton48b605f2008-06-10 15:38:39 -04001768static int
1769nfs_compare_remount_data(struct nfs_server *nfss,
1770 struct nfs_parsed_mount_data *data)
1771{
1772 if (data->flags != nfss->flags ||
1773 data->rsize != nfss->rsize ||
1774 data->wsize != nfss->wsize ||
1775 data->retrans != nfss->client->cl_timeout->to_retries ||
1776 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1777 data->acregmin != nfss->acregmin / HZ ||
1778 data->acregmax != nfss->acregmax / HZ ||
1779 data->acdirmin != nfss->acdirmin / HZ ||
1780 data->acdirmax != nfss->acdirmax / HZ ||
1781 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1782 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1783 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1784 data->nfs_server.addrlen) != 0)
1785 return -EINVAL;
1786
1787 return 0;
1788}
1789
1790static int
1791nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1792{
1793 int error;
1794 struct nfs_server *nfss = sb->s_fs_info;
1795 struct nfs_parsed_mount_data *data;
1796 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1797 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001798 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001799
1800 /*
1801 * Userspace mount programs that send binary options generally send
1802 * them populated with default values. We have no way to know which
1803 * ones were explicitly specified. Fall back to legacy behavior and
1804 * just return success.
1805 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001806 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1807 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1808 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001809 return 0;
1810
1811 data = kzalloc(sizeof(*data), GFP_KERNEL);
1812 if (data == NULL)
1813 return -ENOMEM;
1814
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001815 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001816 /* fill out struct with values from existing mount */
1817 data->flags = nfss->flags;
1818 data->rsize = nfss->rsize;
1819 data->wsize = nfss->wsize;
1820 data->retrans = nfss->client->cl_timeout->to_retries;
1821 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1822 data->acregmin = nfss->acregmin / HZ;
1823 data->acregmax = nfss->acregmax / HZ;
1824 data->acdirmin = nfss->acdirmin / HZ;
1825 data->acdirmax = nfss->acdirmax / HZ;
1826 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1827 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1828 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1829 data->nfs_server.addrlen);
1830
1831 /* overwrite those values with any that were specified */
1832 error = nfs_parse_mount_options((char *)options, data);
1833 if (error < 0)
1834 goto out;
1835
1836 /* compare new mount options with old ones */
1837 error = nfs_compare_remount_data(nfss, data);
1838out:
1839 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001840 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001841 return error;
1842}
1843
David Howells54ceac42006-08-22 20:06:13 -04001844/*
1845 * Initialise the common bits of the superblock
1846 */
1847static inline void nfs_initialise_sb(struct super_block *sb)
1848{
1849 struct nfs_server *server = NFS_SB(sb);
1850
1851 sb->s_magic = NFS_SUPER_MAGIC;
1852
1853 /* We probably want something more informative here */
1854 snprintf(sb->s_id, sizeof(sb->s_id),
1855 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1856
1857 if (sb->s_blocksize == 0)
1858 sb->s_blocksize = nfs_block_bits(server->wsize,
1859 &sb->s_blocksize_bits);
1860
1861 if (server->flags & NFS_MOUNT_NOAC)
1862 sb->s_flags |= MS_SYNCHRONOUS;
1863
1864 nfs_super_set_maxbytes(sb, server->maxfilesize);
1865}
1866
1867/*
1868 * Finish setting up an NFS2/3 superblock
1869 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001870static void nfs_fill_super(struct super_block *sb,
1871 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001872{
1873 struct nfs_server *server = NFS_SB(sb);
1874
1875 sb->s_blocksize_bits = 0;
1876 sb->s_blocksize = 0;
1877 if (data->bsize)
1878 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1879
1880 if (server->flags & NFS_MOUNT_VER3) {
1881 /* The VFS shouldn't apply the umask to mode bits. We will do
1882 * so ourselves when necessary.
1883 */
1884 sb->s_flags |= MS_POSIXACL;
1885 sb->s_time_gran = 1;
1886 }
1887
1888 sb->s_op = &nfs_sops;
1889 nfs_initialise_sb(sb);
1890}
1891
1892/*
1893 * Finish setting up a cloned NFS2/3 superblock
1894 */
1895static void nfs_clone_super(struct super_block *sb,
1896 const struct super_block *old_sb)
1897{
1898 struct nfs_server *server = NFS_SB(sb);
1899
1900 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1901 sb->s_blocksize = old_sb->s_blocksize;
1902 sb->s_maxbytes = old_sb->s_maxbytes;
1903
1904 if (server->flags & NFS_MOUNT_VER3) {
1905 /* The VFS shouldn't apply the umask to mode bits. We will do
1906 * so ourselves when necessary.
1907 */
1908 sb->s_flags |= MS_POSIXACL;
1909 sb->s_time_gran = 1;
1910 }
1911
1912 sb->s_op = old_sb->s_op;
1913 nfs_initialise_sb(sb);
1914}
1915
Trond Myklebust275a5d22007-05-16 16:53:28 -04001916static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1917{
1918 const struct nfs_server *a = s->s_fs_info;
1919 const struct rpc_clnt *clnt_a = a->client;
1920 const struct rpc_clnt *clnt_b = b->client;
1921
1922 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1923 goto Ebusy;
1924 if (a->nfs_client != b->nfs_client)
1925 goto Ebusy;
1926 if (a->flags != b->flags)
1927 goto Ebusy;
1928 if (a->wsize != b->wsize)
1929 goto Ebusy;
1930 if (a->rsize != b->rsize)
1931 goto Ebusy;
1932 if (a->acregmin != b->acregmin)
1933 goto Ebusy;
1934 if (a->acregmax != b->acregmax)
1935 goto Ebusy;
1936 if (a->acdirmin != b->acdirmin)
1937 goto Ebusy;
1938 if (a->acdirmax != b->acdirmax)
1939 goto Ebusy;
1940 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1941 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001942 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001943Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001944 return 0;
1945}
1946
1947struct nfs_sb_mountdata {
1948 struct nfs_server *server;
1949 int mntflags;
1950};
1951
1952static int nfs_set_super(struct super_block *s, void *data)
1953{
1954 struct nfs_sb_mountdata *sb_mntdata = data;
1955 struct nfs_server *server = sb_mntdata->server;
1956 int ret;
1957
1958 s->s_flags = sb_mntdata->mntflags;
1959 s->s_fs_info = server;
1960 ret = set_anon_super(s, server);
1961 if (ret == 0)
1962 server->s_dev = s->s_dev;
1963 return ret;
1964}
1965
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001966static int nfs_compare_super_address(struct nfs_server *server1,
1967 struct nfs_server *server2)
1968{
1969 struct sockaddr *sap1, *sap2;
1970
1971 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1972 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1973
1974 if (sap1->sa_family != sap2->sa_family)
1975 return 0;
1976
1977 switch (sap1->sa_family) {
1978 case AF_INET: {
1979 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1980 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1981 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1982 return 0;
1983 if (sin1->sin_port != sin2->sin_port)
1984 return 0;
1985 break;
1986 }
1987 case AF_INET6: {
1988 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1989 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1990 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1991 return 0;
1992 if (sin1->sin6_port != sin2->sin6_port)
1993 return 0;
1994 break;
1995 }
1996 default:
1997 return 0;
1998 }
1999
2000 return 1;
2001}
2002
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002003static int nfs_compare_super(struct super_block *sb, void *data)
2004{
2005 struct nfs_sb_mountdata *sb_mntdata = data;
2006 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2007 int mntflags = sb_mntdata->mntflags;
2008
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002009 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002010 return 0;
2011 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2012 if (old->flags & NFS_MOUNT_UNSHARED)
2013 return 0;
2014 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2015 return 0;
2016 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002017}
2018
Miklos Szeredifa799752008-04-30 00:54:33 -07002019static int nfs_bdi_register(struct nfs_server *server)
2020{
2021 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2022}
2023
David Howells54ceac42006-08-22 20:06:13 -04002024static int nfs_get_sb(struct file_system_type *fs_type,
2025 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2026{
2027 struct nfs_server *server = NULL;
2028 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002029 struct nfs_parsed_mount_data *data;
2030 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002031 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002032 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002033 struct nfs_sb_mountdata sb_mntdata = {
2034 .mntflags = flags,
2035 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002036 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002037
Trond Myklebust33852a12008-06-19 14:20:11 -04002038 data = kzalloc(sizeof(*data), GFP_KERNEL);
2039 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2040 if (data == NULL || mntfh == NULL)
2041 goto out_free_fh;
2042
2043 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002044
David Howells54ceac42006-08-22 20:06:13 -04002045 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002046 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002047 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002048 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002049
2050 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002051 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002052 if (IS_ERR(server)) {
2053 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002054 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002055 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002056 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002057
Trond Myklebust75180df2007-05-16 16:53:28 -04002058 if (server->flags & NFS_MOUNT_UNSHARED)
2059 compare_super = NULL;
2060
David Howells54ceac42006-08-22 20:06:13 -04002061 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002062 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002063 if (IS_ERR(s)) {
2064 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002065 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002066 }
2067
David Howells54ceac42006-08-22 20:06:13 -04002068 if (s->s_fs_info != server) {
2069 nfs_free_server(server);
2070 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002071 } else {
2072 error = nfs_bdi_register(server);
2073 if (error)
2074 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002075 }
David Howells54ceac42006-08-22 20:06:13 -04002076
2077 if (!s->s_root) {
2078 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002079 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002080 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002081 }
2082
Trond Myklebust33852a12008-06-19 14:20:11 -04002083 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002084 if (IS_ERR(mntroot)) {
2085 error = PTR_ERR(mntroot);
2086 goto error_splat_super;
2087 }
2088
Trond Myklebust33852a12008-06-19 14:20:11 -04002089 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002090 if (error)
2091 goto error_splat_root;
2092
David Howellsf7b422b2006-06-09 09:34:33 -04002093 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002094 mnt->mnt_sb = s;
2095 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002096 error = 0;
2097
2098out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002099 kfree(data->nfs_server.hostname);
2100 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002101 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002102 security_free_mnt_opts(&data->lsm_opts);
2103out_free_fh:
2104 kfree(mntfh);
2105 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002106 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002107
David Howells54ceac42006-08-22 20:06:13 -04002108out_err_nosb:
2109 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002110 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002111
Eric Parisf9c3a382008-03-05 14:20:18 -05002112error_splat_root:
2113 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002114error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002115 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002116 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002117}
2118
David Howells54ceac42006-08-22 20:06:13 -04002119/*
2120 * Destroy an NFS2/3 superblock
2121 */
David Howellsf7b422b2006-06-09 09:34:33 -04002122static void nfs_kill_super(struct super_block *s)
2123{
2124 struct nfs_server *server = NFS_SB(s);
2125
Miklos Szeredifa799752008-04-30 00:54:33 -07002126 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002127 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002128 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002129 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002130}
2131
David Howells54ceac42006-08-22 20:06:13 -04002132/*
2133 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2134 */
2135static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2136 const char *dev_name, void *raw_data,
2137 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002138{
2139 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002140 struct super_block *s;
2141 struct nfs_server *server;
2142 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002143 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002144 struct nfs_sb_mountdata sb_mntdata = {
2145 .mntflags = flags,
2146 };
David Howells54ceac42006-08-22 20:06:13 -04002147 int error;
2148
2149 dprintk("--> nfs_xdev_get_sb()\n");
2150
2151 /* create a new volume representation */
2152 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2153 if (IS_ERR(server)) {
2154 error = PTR_ERR(server);
2155 goto out_err_noserver;
2156 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002157 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002158
Trond Myklebust75180df2007-05-16 16:53:28 -04002159 if (server->flags & NFS_MOUNT_UNSHARED)
2160 compare_super = NULL;
2161
David Howells54ceac42006-08-22 20:06:13 -04002162 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002163 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002164 if (IS_ERR(s)) {
2165 error = PTR_ERR(s);
2166 goto out_err_nosb;
2167 }
2168
2169 if (s->s_fs_info != server) {
2170 nfs_free_server(server);
2171 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002172 } else {
2173 error = nfs_bdi_register(server);
2174 if (error)
2175 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002176 }
2177
2178 if (!s->s_root) {
2179 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002180 nfs_clone_super(s, data->sb);
2181 }
2182
2183 mntroot = nfs_get_root(s, data->fh);
2184 if (IS_ERR(mntroot)) {
2185 error = PTR_ERR(mntroot);
2186 goto error_splat_super;
2187 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002188 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002189 dput(mntroot);
2190 error = -ESTALE;
2191 goto error_splat_super;
2192 }
David Howells54ceac42006-08-22 20:06:13 -04002193
2194 s->s_flags |= MS_ACTIVE;
2195 mnt->mnt_sb = s;
2196 mnt->mnt_root = mntroot;
2197
Eric Parisf9c3a382008-03-05 14:20:18 -05002198 /* clone any lsm security options from the parent to the new sb */
2199 security_sb_clone_mnt_opts(data->sb, s);
2200
David Howells54ceac42006-08-22 20:06:13 -04002201 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2202 return 0;
2203
2204out_err_nosb:
2205 nfs_free_server(server);
2206out_err_noserver:
2207 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2208 return error;
2209
2210error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002211 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002212 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2213 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002214}
2215
2216#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002217
2218/*
2219 * Finish setting up a cloned NFS4 superblock
2220 */
2221static void nfs4_clone_super(struct super_block *sb,
2222 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002223{
David Howells54ceac42006-08-22 20:06:13 -04002224 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2225 sb->s_blocksize = old_sb->s_blocksize;
2226 sb->s_maxbytes = old_sb->s_maxbytes;
2227 sb->s_time_gran = 1;
2228 sb->s_op = old_sb->s_op;
2229 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002230}
2231
2232/*
2233 * Set up an NFS4 superblock
2234 */
David Howells54ceac42006-08-22 20:06:13 -04002235static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002236{
David Howellsf7b422b2006-06-09 09:34:33 -04002237 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002238 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002239 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002240}
2241
Trond Myklebust01c3f052009-06-17 13:22:58 -07002242static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2243{
2244 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2245}
2246
David Howells54ceac42006-08-22 20:06:13 -04002247/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002248 * Validate NFSv4 mount options
2249 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002250static int nfs4_validate_mount_data(void *options,
2251 struct nfs_parsed_mount_data *args,
2252 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002253{
Chuck Lever4c568012007-12-10 14:59:28 -05002254 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002255 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002256 char *c;
2257
2258 if (data == NULL)
2259 goto out_no_data;
2260
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002261 args->rsize = NFS_MAX_FILE_IO_SIZE;
2262 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002263 args->acregmin = NFS_DEF_ACREGMIN;
2264 args->acregmax = NFS_DEF_ACREGMAX;
2265 args->acdirmin = NFS_DEF_ACDIRMIN;
2266 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002267 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002268 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04002269 args->auth_flavor_len = 1;
Mike Sager3fd5be92009-04-01 09:21:48 -04002270 args->minorversion = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002271
Chuck Leverf0768eb2007-07-01 12:13:01 -04002272 switch (data->version) {
2273 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002274 ap = (struct sockaddr_in *)&args->nfs_server.address;
2275 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002276 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002277 if (data->host_addrlen == 0)
2278 goto out_no_address;
2279 args->nfs_server.addrlen = data->host_addrlen;
2280 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002281 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002282 if (!nfs_verify_server_address((struct sockaddr *)
2283 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002284 goto out_no_address;
2285
Chuck Lever6738b252008-06-24 16:33:54 -04002286 if (data->auth_flavourlen) {
2287 if (data->auth_flavourlen > 1)
2288 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002289 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002290 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002291 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002292 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002293 }
2294
2295 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2296 if (IS_ERR(c))
2297 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002298 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002299
2300 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2301 if (IS_ERR(c))
2302 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002303 args->nfs_server.export_path = c;
2304 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002305
2306 c = strndup_user(data->client_addr.data, 16);
2307 if (IS_ERR(c))
2308 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002309 args->client_address = c;
2310
2311 /*
2312 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2313 * can deal with.
2314 */
2315
2316 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2317 args->rsize = data->rsize;
2318 args->wsize = data->wsize;
2319 args->timeo = data->timeo;
2320 args->retrans = data->retrans;
2321 args->acregmin = data->acregmin;
2322 args->acregmax = data->acregmax;
2323 args->acdirmin = data->acdirmin;
2324 args->acdirmax = data->acdirmax;
2325 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002326 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002327
2328 break;
Chuck Lever80071222007-07-01 12:13:59 -04002329 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002330 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002331
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002332 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002333 return -EINVAL;
2334
2335 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002336 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002337 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002338
Chuck Leverec6ee612009-08-09 15:09:37 -04002339 rpc_set_port((struct sockaddr *)&args->nfs_server.address,
Chuck Levered596a82008-06-26 17:47:05 -04002340 args->nfs_server.port);
2341
Trond Myklebust259875e2008-07-02 14:43:47 -04002342 nfs_validate_transport_protocol(args);
2343
Trond Myklebust01c3f052009-06-17 13:22:58 -07002344 nfs4_validate_mount_flags(args);
2345
Chuck Lever6738b252008-06-24 16:33:54 -04002346 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002347 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002348
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002349 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002350 goto out_no_client_address;
2351
Chuck Leverdc045892008-06-23 12:36:37 -04002352 status = nfs_parse_devname(dev_name,
2353 &args->nfs_server.hostname,
2354 NFS4_MAXNAMLEN,
2355 &args->nfs_server.export_path,
2356 NFS4_MAXPATHLEN);
2357 if (status < 0)
2358 return status;
2359
Chuck Lever80071222007-07-01 12:13:59 -04002360 break;
2361 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002362 }
2363
2364 return 0;
2365
2366out_no_data:
2367 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2368 return -EINVAL;
2369
2370out_inval_auth:
2371 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2372 data->auth_flavourlen);
2373 return -EINVAL;
2374
2375out_no_address:
2376 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2377 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002378
2379out_no_client_address:
2380 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2381 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002382}
2383
2384/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002385 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002386 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002387static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002388 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002389{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002390 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002391 struct super_block *s;
2392 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002393 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002394 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002395 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002396 struct nfs_sb_mountdata sb_mntdata = {
2397 .mntflags = flags,
2398 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002399 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002400
Trond Myklebust33852a12008-06-19 14:20:11 -04002401 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2402 if (data == NULL || mntfh == NULL)
2403 goto out_free_fh;
2404
2405 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002406
David Howells54ceac42006-08-22 20:06:13 -04002407 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002408 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002409 if (IS_ERR(server)) {
2410 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002411 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002412 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002413 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002414
Trond Myklebust75180df2007-05-16 16:53:28 -04002415 if (server->flags & NFS4_MOUNT_UNSHARED)
2416 compare_super = NULL;
2417
David Howells54ceac42006-08-22 20:06:13 -04002418 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002419 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002420 if (IS_ERR(s)) {
2421 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002422 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002423 }
2424
Trond Myklebust5dd31772006-08-24 01:03:05 -04002425 if (s->s_fs_info != server) {
2426 nfs_free_server(server);
2427 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002428 } else {
2429 error = nfs_bdi_register(server);
2430 if (error)
2431 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002432 }
2433
David Howells54ceac42006-08-22 20:06:13 -04002434 if (!s->s_root) {
2435 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002436 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002437 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002438 }
David Howellsf7b422b2006-06-09 09:34:33 -04002439
Trond Myklebust33852a12008-06-19 14:20:11 -04002440 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002441 if (IS_ERR(mntroot)) {
2442 error = PTR_ERR(mntroot);
2443 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002444 }
David Howells54ceac42006-08-22 20:06:13 -04002445
Trond Myklebust33852a12008-06-19 14:20:11 -04002446 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002447 if (error)
2448 goto error_splat_root;
2449
David Howellsf7b422b2006-06-09 09:34:33 -04002450 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002451 mnt->mnt_sb = s;
2452 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002453 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002454
Chuck Lever29eb9812007-07-01 12:12:30 -04002455out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002456 security_free_mnt_opts(&data->lsm_opts);
2457out_free_fh:
2458 kfree(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002459 return error;
David Howells54ceac42006-08-22 20:06:13 -04002460
Chuck Lever29eb9812007-07-01 12:12:30 -04002461out_free:
2462 nfs_free_server(server);
2463 goto out;
2464
Eric Paris46c8ac72008-05-02 13:42:42 -07002465error_splat_root:
2466 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002467error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002468 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002469 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002470}
2471
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002472static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2473 int flags, void *data, const char *hostname)
2474{
2475 struct vfsmount *root_mnt;
2476 char *root_devname;
2477 size_t len;
2478
2479 len = strlen(hostname) + 3;
2480 root_devname = kmalloc(len, GFP_KERNEL);
2481 if (root_devname == NULL)
2482 return ERR_PTR(-ENOMEM);
2483 snprintf(root_devname, len, "%s:/", hostname);
2484 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2485 kfree(root_devname);
2486 return root_mnt;
2487}
2488
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002489static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2490{
2491 char *page = (char *) __get_free_page(GFP_KERNEL);
2492 char *devname, *tmp;
2493
2494 if (page == NULL)
2495 return;
2496 devname = nfs_path(path->mnt->mnt_devname,
2497 path->mnt->mnt_root, path->dentry,
2498 page, PAGE_SIZE);
2499 if (devname == NULL)
2500 goto out_freepage;
2501 tmp = kstrdup(devname, GFP_KERNEL);
2502 if (tmp == NULL)
2503 goto out_freepage;
2504 kfree(mnt->mnt_devname);
2505 mnt->mnt_devname = tmp;
2506out_freepage:
2507 free_page((unsigned long)page);
2508}
2509
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002510static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2511 const char *export_path, struct vfsmount *mnt_target)
2512{
2513 struct mnt_namespace *ns_private;
2514 struct nameidata nd;
2515 struct super_block *s;
2516 int ret;
2517
2518 ns_private = create_mnt_ns(root_mnt);
2519 ret = PTR_ERR(ns_private);
2520 if (IS_ERR(ns_private))
2521 goto out_mntput;
2522
2523 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2524 export_path, LOOKUP_FOLLOW, &nd);
2525
2526 put_mnt_ns(ns_private);
2527
2528 if (ret != 0)
2529 goto out_err;
2530
2531 s = nd.path.mnt->mnt_sb;
2532 atomic_inc(&s->s_active);
2533 mnt_target->mnt_sb = s;
2534 mnt_target->mnt_root = dget(nd.path.dentry);
2535
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002536 /* Correct the device pathname */
2537 nfs_fix_devname(&nd.path, mnt_target);
2538
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002539 path_put(&nd.path);
2540 down_write(&s->s_umount);
2541 return 0;
2542out_mntput:
2543 mntput(root_mnt);
2544out_err:
2545 return ret;
2546}
2547
2548/*
2549 * Get the superblock for an NFS4 mountpoint
2550 */
2551static int nfs4_get_sb(struct file_system_type *fs_type,
2552 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2553{
2554 struct nfs_parsed_mount_data *data;
2555 char *export_path;
2556 struct vfsmount *root_mnt;
2557 int error = -ENOMEM;
2558
2559 data = kzalloc(sizeof(*data), GFP_KERNEL);
2560 if (data == NULL)
2561 goto out_free_data;
2562
2563 /* Validate the mount data */
2564 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2565 if (error < 0)
2566 goto out;
2567
2568 export_path = data->nfs_server.export_path;
2569 data->nfs_server.export_path = "/";
2570 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2571 data->nfs_server.hostname);
2572 data->nfs_server.export_path = export_path;
2573
2574 error = PTR_ERR(root_mnt);
2575 if (IS_ERR(root_mnt))
2576 goto out;
2577
2578 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2579
2580out:
2581 kfree(data->client_address);
2582 kfree(data->nfs_server.export_path);
2583 kfree(data->nfs_server.hostname);
2584 kfree(data->fscache_uniq);
2585out_free_data:
2586 kfree(data);
2587 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2588 error != 0 ? " [error]" : "");
2589 return error;
2590}
2591
David Howellsf7b422b2006-06-09 09:34:33 -04002592static void nfs4_kill_super(struct super_block *sb)
2593{
2594 struct nfs_server *server = NFS_SB(sb);
2595
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002596 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002597 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002598 kill_anon_super(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002599 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002600 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002601 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002602 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002603}
2604
2605/*
David Howells54ceac42006-08-22 20:06:13 -04002606 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002607 */
David Howells54ceac42006-08-22 20:06:13 -04002608static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2609 const char *dev_name, void *raw_data,
2610 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002611{
2612 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002613 struct super_block *s;
2614 struct nfs_server *server;
2615 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002616 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002617 struct nfs_sb_mountdata sb_mntdata = {
2618 .mntflags = flags,
2619 };
David Howells54ceac42006-08-22 20:06:13 -04002620 int error;
2621
2622 dprintk("--> nfs4_xdev_get_sb()\n");
2623
2624 /* create a new volume representation */
2625 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2626 if (IS_ERR(server)) {
2627 error = PTR_ERR(server);
2628 goto out_err_noserver;
2629 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002630 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002631
Trond Myklebust75180df2007-05-16 16:53:28 -04002632 if (server->flags & NFS4_MOUNT_UNSHARED)
2633 compare_super = NULL;
2634
David Howells54ceac42006-08-22 20:06:13 -04002635 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002636 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002637 if (IS_ERR(s)) {
2638 error = PTR_ERR(s);
2639 goto out_err_nosb;
2640 }
2641
2642 if (s->s_fs_info != server) {
2643 nfs_free_server(server);
2644 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002645 } else {
2646 error = nfs_bdi_register(server);
2647 if (error)
2648 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002649 }
2650
2651 if (!s->s_root) {
2652 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002653 nfs4_clone_super(s, data->sb);
2654 }
2655
2656 mntroot = nfs4_get_root(s, data->fh);
2657 if (IS_ERR(mntroot)) {
2658 error = PTR_ERR(mntroot);
2659 goto error_splat_super;
2660 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002661 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2662 dput(mntroot);
2663 error = -ESTALE;
2664 goto error_splat_super;
2665 }
David Howells54ceac42006-08-22 20:06:13 -04002666
2667 s->s_flags |= MS_ACTIVE;
2668 mnt->mnt_sb = s;
2669 mnt->mnt_root = mntroot;
2670
Eric Paris46c8ac72008-05-02 13:42:42 -07002671 security_sb_clone_mnt_opts(data->sb, s);
2672
David Howells54ceac42006-08-22 20:06:13 -04002673 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2674 return 0;
2675
2676out_err_nosb:
2677 nfs_free_server(server);
2678out_err_noserver:
2679 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2680 return error;
2681
2682error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002683 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002684 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2685 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002686}
2687
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002688static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2689 int flags, const char *dev_name, void *raw_data,
2690 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002691{
2692 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002693 struct super_block *s;
2694 struct nfs_server *server;
2695 struct dentry *mntroot;
2696 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002697 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002698 struct nfs_sb_mountdata sb_mntdata = {
2699 .mntflags = flags,
2700 };
David Howells54ceac42006-08-22 20:06:13 -04002701 int error;
2702
2703 dprintk("--> nfs4_referral_get_sb()\n");
2704
2705 /* create a new volume representation */
2706 server = nfs4_create_referral_server(data, &mntfh);
2707 if (IS_ERR(server)) {
2708 error = PTR_ERR(server);
2709 goto out_err_noserver;
2710 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002711 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002712
Trond Myklebust75180df2007-05-16 16:53:28 -04002713 if (server->flags & NFS4_MOUNT_UNSHARED)
2714 compare_super = NULL;
2715
David Howells54ceac42006-08-22 20:06:13 -04002716 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002717 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002718 if (IS_ERR(s)) {
2719 error = PTR_ERR(s);
2720 goto out_err_nosb;
2721 }
2722
2723 if (s->s_fs_info != server) {
2724 nfs_free_server(server);
2725 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002726 } else {
2727 error = nfs_bdi_register(server);
2728 if (error)
2729 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002730 }
2731
2732 if (!s->s_root) {
2733 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002734 nfs4_fill_super(s);
2735 }
2736
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002737 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002738 if (IS_ERR(mntroot)) {
2739 error = PTR_ERR(mntroot);
2740 goto error_splat_super;
2741 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002742 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2743 dput(mntroot);
2744 error = -ESTALE;
2745 goto error_splat_super;
2746 }
David Howells54ceac42006-08-22 20:06:13 -04002747
2748 s->s_flags |= MS_ACTIVE;
2749 mnt->mnt_sb = s;
2750 mnt->mnt_root = mntroot;
2751
Eric Paris46c8ac72008-05-02 13:42:42 -07002752 security_sb_clone_mnt_opts(data->sb, s);
2753
David Howells54ceac42006-08-22 20:06:13 -04002754 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2755 return 0;
2756
2757out_err_nosb:
2758 nfs_free_server(server);
2759out_err_noserver:
2760 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2761 return error;
2762
2763error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002764 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002765 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2766 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002767}
2768
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002769/*
2770 * Create an NFS4 server record on referral traversal
2771 */
2772static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2773 int flags, const char *dev_name, void *raw_data,
2774 struct vfsmount *mnt)
2775{
2776 struct nfs_clone_mount *data = raw_data;
2777 char *export_path;
2778 struct vfsmount *root_mnt;
2779 int error;
2780
2781 dprintk("--> nfs4_referral_get_sb()\n");
2782
2783 export_path = data->mnt_path;
2784 data->mnt_path = "/";
2785
2786 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2787 flags, data, data->hostname);
2788 data->mnt_path = export_path;
2789
2790 error = PTR_ERR(root_mnt);
2791 if (IS_ERR(root_mnt))
2792 goto out;
2793
2794 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2795out:
2796 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2797 error != 0 ? " [error]" : "");
2798 return error;
2799}
2800
David Howells54ceac42006-08-22 20:06:13 -04002801#endif /* CONFIG_NFS_V4 */