blob: 0343ebcfbbdc343c5340534ce25611cb64cfc8dc [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,
Chuck Lever764302c2009-09-08 19:50:03 -040076 Opt_v2, Opt_v3, Opt_v4,
\"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" },
Chuck Lever764302c2009-09-08 19:50:03 -0400130 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400131 { Opt_udp, "udp" },
132 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400133 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400134 { Opt_acl, "acl" },
135 { Opt_noacl, "noacl" },
136 { Opt_rdirplus, "rdirplus" },
137 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400138 { Opt_sharecache, "sharecache" },
139 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500140 { Opt_resvport, "resvport" },
141 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100142 { Opt_fscache, "fsc" },
143 { Opt_fscache_uniq, "fsc=%s" },
144 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400145
Chuck Levera5a16ba2009-06-17 18:02:14 -0700146 { Opt_port, "port=%s" },
147 { Opt_rsize, "rsize=%s" },
148 { Opt_wsize, "wsize=%s" },
149 { Opt_bsize, "bsize=%s" },
150 { Opt_timeo, "timeo=%s" },
151 { Opt_retrans, "retrans=%s" },
152 { Opt_acregmin, "acregmin=%s" },
153 { Opt_acregmax, "acregmax=%s" },
154 { Opt_acdirmin, "acdirmin=%s" },
155 { Opt_acdirmax, "acdirmax=%s" },
156 { Opt_actimeo, "actimeo=%s" },
157 { Opt_namelen, "namlen=%s" },
158 { Opt_mountport, "mountport=%s" },
159 { Opt_mountvers, "mountvers=%s" },
160 { Opt_nfsvers, "nfsvers=%s" },
161 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400162 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400163
164 { Opt_sec, "sec=%s" },
165 { Opt_proto, "proto=%s" },
166 { Opt_mountproto, "mountproto=%s" },
167 { Opt_addr, "addr=%s" },
168 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500169 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400170 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400171
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400172 { Opt_lookupcache, "lookupcache=%s" },
173
Chuck Leverbf0fd762007-07-01 12:13:44 -0400174 { Opt_err, NULL }
175};
176
177enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400178 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400179
180 Opt_xprt_err
181};
182
Steven Whitehousea447c092008-10-13 10:46:57 +0100183static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400184 { Opt_xprt_udp, "udp" },
185 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400186 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187
188 { Opt_xprt_err, NULL }
189};
190
191enum {
192 Opt_sec_none, Opt_sec_sys,
193 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
194 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
195 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
196
197 Opt_sec_err
198};
199
Steven Whitehousea447c092008-10-13 10:46:57 +0100200static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400201 { Opt_sec_none, "none" },
202 { Opt_sec_none, "null" },
203 { Opt_sec_sys, "sys" },
204
205 { Opt_sec_krb5, "krb5" },
206 { Opt_sec_krb5i, "krb5i" },
207 { Opt_sec_krb5p, "krb5p" },
208
209 { Opt_sec_lkey, "lkey" },
210 { Opt_sec_lkeyi, "lkeyi" },
211 { Opt_sec_lkeyp, "lkeyp" },
212
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500213 { Opt_sec_spkm, "spkm3" },
214 { Opt_sec_spkmi, "spkm3i" },
215 { Opt_sec_spkmp, "spkm3p" },
216
Chuck Leverbf0fd762007-07-01 12:13:44 -0400217 { Opt_sec_err, NULL }
218};
219
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400220enum {
221 Opt_lookupcache_all, Opt_lookupcache_positive,
222 Opt_lookupcache_none,
223
224 Opt_lookupcache_err
225};
226
227static match_table_t nfs_lookupcache_tokens = {
228 { Opt_lookupcache_all, "all" },
229 { Opt_lookupcache_positive, "pos" },
230 { Opt_lookupcache_positive, "positive" },
231 { Opt_lookupcache_none, "none" },
232
233 { Opt_lookupcache_err, NULL }
234};
235
Chuck Leverbf0fd762007-07-01 12:13:44 -0400236
Al Viro42faad92008-04-24 07:21:56 -0400237static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400238static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400239static int nfs_show_options(struct seq_file *, struct vfsmount *);
240static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400241static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400242static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400244static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400245static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400246
247static struct file_system_type nfs_fs_type = {
248 .owner = THIS_MODULE,
249 .name = "nfs",
250 .get_sb = nfs_get_sb,
251 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700252 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400253};
254
David Howells54ceac42006-08-22 20:06:13 -0400255struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400256 .owner = THIS_MODULE,
257 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400258 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700260 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400261};
262
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800263static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400264 .alloc_inode = nfs_alloc_inode,
265 .destroy_inode = nfs_destroy_inode,
266 .write_inode = nfs_write_inode,
267 .statfs = nfs_statfs,
268 .clear_inode = nfs_clear_inode,
269 .umount_begin = nfs_umount_begin,
270 .show_options = nfs_show_options,
271 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400272 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400273};
274
275#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400276static int nfs4_validate_text_mount_data(void *options,
277 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400278static int nfs4_try_mount(int flags, const char *dev_name,
279 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400280static int nfs4_get_sb(struct file_system_type *fs_type,
281 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400282static int nfs4_remote_get_sb(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400284static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
285 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
286static int nfs4_referral_get_sb(struct file_system_type *fs_type,
287 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400288static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
289 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400290static void nfs4_kill_super(struct super_block *sb);
291
292static struct file_system_type nfs4_fs_type = {
293 .owner = THIS_MODULE,
294 .name = "nfs4",
295 .get_sb = nfs4_get_sb,
296 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700297 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400298};
299
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400300static struct file_system_type nfs4_remote_fs_type = {
301 .owner = THIS_MODULE,
302 .name = "nfs4",
303 .get_sb = nfs4_remote_get_sb,
304 .kill_sb = nfs4_kill_super,
305 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
306};
307
David Howells54ceac42006-08-22 20:06:13 -0400308struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400309 .owner = THIS_MODULE,
310 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400311 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400312 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700313 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400314};
315
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400316static struct file_system_type nfs4_remote_referral_fs_type = {
317 .owner = THIS_MODULE,
318 .name = "nfs4",
319 .get_sb = nfs4_remote_referral_get_sb,
320 .kill_sb = nfs4_kill_super,
321 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
322};
323
David Howells54ceac42006-08-22 20:06:13 -0400324struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400325 .owner = THIS_MODULE,
326 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400327 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400328 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700329 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400330};
331
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800332static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400333 .alloc_inode = nfs_alloc_inode,
334 .destroy_inode = nfs_destroy_inode,
335 .write_inode = nfs_write_inode,
336 .statfs = nfs_statfs,
337 .clear_inode = nfs4_clear_inode,
338 .umount_begin = nfs_umount_begin,
339 .show_options = nfs_show_options,
340 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400341 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400342};
343#endif
344
Rusty Russell8e1f9362007-07-17 04:03:17 -0700345static struct shrinker acl_shrinker = {
346 .shrink = nfs_access_cache_shrinker,
347 .seeks = DEFAULT_SEEKS,
348};
Trond Myklebust979df722006-07-25 11:28:19 -0400349
David Howellsf7b422b2006-06-09 09:34:33 -0400350/*
351 * Register the NFS filesystems
352 */
353int __init register_nfs_fs(void)
354{
355 int ret;
356
357 ret = register_filesystem(&nfs_fs_type);
358 if (ret < 0)
359 goto error_0;
360
David Howellsf7b422b2006-06-09 09:34:33 -0400361 ret = nfs_register_sysctl();
362 if (ret < 0)
363 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800364#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400365 ret = register_filesystem(&nfs4_fs_type);
366 if (ret < 0)
367 goto error_2;
368#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700369 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400370 return 0;
371
372#ifdef CONFIG_NFS_V4
373error_2:
374 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800375#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400376error_1:
377 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400378error_0:
379 return ret;
380}
381
382/*
383 * Unregister the NFS filesystems
384 */
385void __exit unregister_nfs_fs(void)
386{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700387 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400388#ifdef CONFIG_NFS_V4
389 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400390#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700391 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400392 unregister_filesystem(&nfs_fs_type);
393}
394
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400395void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500396{
397 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400398
399 if (atomic_inc_return(&server->active) == 1)
400 atomic_inc(&sb->s_active);
401}
402
403void nfs_sb_deactive(struct super_block *sb)
404{
405 struct nfs_server *server = NFS_SB(sb);
406
407 if (atomic_dec_and_test(&server->active))
408 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500409}
410
David Howellsf7b422b2006-06-09 09:34:33 -0400411/*
412 * Deliver file system statistics to userspace
413 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400414static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400415{
David Howells0c7d90c2006-08-22 20:06:10 -0400416 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400417 unsigned char blockbits;
418 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400419 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400420 struct nfs_fattr fattr;
421 struct nfs_fsstat res = {
422 .fattr = &fattr,
423 };
424 int error;
425
David Howells8fa5c002006-08-22 20:06:12 -0400426 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400427 if (error < 0)
428 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700429 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400430
431 /*
432 * Current versions of glibc do not correctly handle the
433 * case where f_frsize != f_bsize. Eventually we want to
434 * report the value of wtmult in this field.
435 */
David Howells0c7d90c2006-08-22 20:06:10 -0400436 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400437
438 /*
439 * On most *nix systems, f_blocks, f_bfree, and f_bavail
440 * are reported in units of f_frsize. Linux hasn't had
441 * an f_frsize field in its statfs struct until recently,
442 * thus historically Linux's sys_statfs reports these
443 * fields in units of f_bsize.
444 */
David Howells0c7d90c2006-08-22 20:06:10 -0400445 buf->f_bsize = dentry->d_sb->s_blocksize;
446 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400447 blockres = (1 << blockbits) - 1;
448 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
449 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
450 buf->f_bavail = (res.abytes + blockres) >> blockbits;
451
452 buf->f_files = res.tfiles;
453 buf->f_ffree = res.afiles;
454
455 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700456
David Howellsf7b422b2006-06-09 09:34:33 -0400457 return 0;
458
459 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700460 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700461 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400462}
463
David Howells7d4e2742006-08-22 20:06:07 -0400464/*
465 * Map the security flavour number to a name
466 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400467static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
468{
David Howells7d4e2742006-08-22 20:06:07 -0400469 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400470 rpc_authflavor_t flavour;
471 const char *str;
472 } sec_flavours[] = {
473 { RPC_AUTH_NULL, "null" },
474 { RPC_AUTH_UNIX, "sys" },
475 { RPC_AUTH_GSS_KRB5, "krb5" },
476 { RPC_AUTH_GSS_KRB5I, "krb5i" },
477 { RPC_AUTH_GSS_KRB5P, "krb5p" },
478 { RPC_AUTH_GSS_LKEY, "lkey" },
479 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
480 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
481 { RPC_AUTH_GSS_SPKM, "spkm" },
482 { RPC_AUTH_GSS_SPKMI, "spkmi" },
483 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400484 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400485 };
486 int i;
487
Chuck Lever4d81cd12007-07-01 12:12:40 -0400488 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400489 if (sec_flavours[i].flavour == flavour)
490 break;
491 }
492 return sec_flavours[i].str;
493}
494
Chuck Lever82d101d2008-03-14 14:10:37 -0400495static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
496 int showdefaults)
497{
498 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
499
500 switch (sap->sa_family) {
501 case AF_INET: {
502 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700503 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400504 break;
505 }
506 case AF_INET6: {
507 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700508 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400509 break;
510 }
511 default:
512 if (showdefaults)
513 seq_printf(m, ",mountaddr=unspecified");
514 }
515
516 if (nfss->mountd_version || showdefaults)
517 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
518 if (nfss->mountd_port || showdefaults)
519 seq_printf(m, ",mountport=%u", nfss->mountd_port);
520
521 switch (nfss->mountd_protocol) {
522 case IPPROTO_UDP:
523 seq_printf(m, ",mountproto=udp");
524 break;
525 case IPPROTO_TCP:
526 seq_printf(m, ",mountproto=tcp");
527 break;
528 default:
529 if (showdefaults)
530 seq_printf(m, ",mountproto=auto");
531 }
532}
533
David Howellsf7b422b2006-06-09 09:34:33 -0400534/*
535 * Describe the mount options in force on this server representation
536 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400537static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
538 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400539{
David Howells509de812006-08-22 20:06:11 -0400540 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400541 int flag;
David Howells509de812006-08-22 20:06:11 -0400542 const char *str;
543 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400544 } nfs_info[] = {
545 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400546 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400547 { NFS_MOUNT_NOCTO, ",nocto", "" },
548 { NFS_MOUNT_NOAC, ",noac", "" },
549 { NFS_MOUNT_NONLM, ",nolock", "" },
550 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400551 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500552 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
553 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400554 { 0, NULL, NULL }
555 };
David Howells509de812006-08-22 20:06:11 -0400556 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400557 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400558 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400559
Chuck Lever82d101d2008-03-14 14:10:37 -0400560 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400561 seq_printf(m, ",rsize=%u", nfss->rsize);
562 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400563 if (nfss->bsize != 0)
564 seq_printf(m, ",bsize=%u", nfss->bsize);
565 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400566 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400567 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400568 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400569 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400570 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400571 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400572 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400573 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400574 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
575 if (nfss->flags & nfs_infop->flag)
576 seq_puts(m, nfs_infop->str);
577 else
578 seq_puts(m, nfs_infop->nostr);
579 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400580 seq_printf(m, ",proto=%s",
581 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400582 if (version == 4) {
583 if (nfss->port != NFS_PORT)
584 seq_printf(m, ",port=%u", nfss->port);
585 } else
586 if (nfss->port)
587 seq_printf(m, ",port=%u", nfss->port);
588
Trond Myklebust33170232007-12-20 16:03:59 -0500589 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
590 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400591 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400592
593 if (version != 4)
594 nfs_show_mountd_options(m, nfss, showdefaults);
595
596#ifdef CONFIG_NFS_V4
597 if (clp->rpc_ops->version == 4)
598 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
599#endif
David Howellsb797cac2009-04-03 16:42:48 +0100600 if (nfss->options & NFS_OPTION_FSCACHE)
601 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400602}
603
604/*
605 * Describe the mount options on this VFS mountpoint
606 */
607static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
608{
609 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
610
611 nfs_show_mount_options(m, nfss, 0);
612
Chuck Lever5d8515c2007-12-10 14:57:16 -0500613 seq_printf(m, ",addr=%s",
614 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
615 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400616
617 return 0;
618}
619
620/*
621 * Present statistical information for this VFS mountpoint
622 */
623static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
624{
625 int i, cpu;
626 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
627 struct rpc_auth *auth = nfss->client->cl_auth;
628 struct nfs_iostats totals = { };
629
630 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
631
632 /*
633 * Display all mount option settings
634 */
635 seq_printf(m, "\n\topts:\t");
636 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
637 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
638 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
639 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
640 nfs_show_mount_options(m, nfss, 1);
641
642 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
643
644 seq_printf(m, "\n\tcaps:\t");
645 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400646 seq_printf(m, ",wtmult=%u", nfss->wtmult);
647 seq_printf(m, ",dtsize=%u", nfss->dtsize);
648 seq_printf(m, ",bsize=%u", nfss->bsize);
649 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400650
651#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500652 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400653 seq_printf(m, "\n\tnfsv4:\t");
654 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
655 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
656 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
657 }
658#endif
659
660 /*
661 * Display security flavor in effect for this mount
662 */
Chuck Lever2d767432008-03-14 14:10:08 -0400663 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400664 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400665 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400666
667 /*
668 * Display superblock I/O counters
669 */
670 for_each_possible_cpu(cpu) {
671 struct nfs_iostats *stats;
672
673 preempt_disable();
674 stats = per_cpu_ptr(nfss->io_stats, cpu);
675
676 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
677 totals.events[i] += stats->events[i];
678 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
679 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100680#ifdef CONFIG_NFS_FSCACHE
681 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
682 totals.fscache[i] += stats->fscache[i];
683#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400684
685 preempt_enable();
686 }
687
688 seq_printf(m, "\n\tevents:\t");
689 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
690 seq_printf(m, "%lu ", totals.events[i]);
691 seq_printf(m, "\n\tbytes:\t");
692 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
693 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100694#ifdef CONFIG_NFS_FSCACHE
695 if (nfss->options & NFS_OPTION_FSCACHE) {
696 seq_printf(m, "\n\tfsc:\t");
697 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
698 seq_printf(m, "%Lu ", totals.bytes[i]);
699 }
700#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400701 seq_printf(m, "\n");
702
703 rpc_print_iostats(m, nfss->client);
704
705 return 0;
706}
707
708/*
709 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400710 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400711 */
Al Viro42faad92008-04-24 07:21:56 -0400712static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400713{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200714 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400715 struct rpc_clnt *rpc;
716
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200717 lock_kernel();
718
719 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400720 /* -EIO all pending I/O */
721 rpc = server->client_acl;
722 if (!IS_ERR(rpc))
723 rpc_killall_tasks(rpc);
724 rpc = server->client;
725 if (!IS_ERR(rpc))
726 rpc_killall_tasks(rpc);
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200727
728 unlock_kernel();
David Howellsf7b422b2006-06-09 09:34:33 -0400729}
730
Trond Myklebustc5811db2009-10-06 15:40:15 -0400731static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400732{
733 struct nfs_parsed_mount_data *data;
734
735 data = kzalloc(sizeof(*data), GFP_KERNEL);
736 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400737 data->rsize = NFS_MAX_FILE_IO_SIZE;
738 data->wsize = NFS_MAX_FILE_IO_SIZE;
739 data->acregmin = NFS_DEF_ACREGMIN;
740 data->acregmax = NFS_DEF_ACREGMAX;
741 data->acdirmin = NFS_DEF_ACDIRMIN;
742 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400743 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400744 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400745 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400746 data->auth_flavors[0] = RPC_AUTH_UNIX;
747 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400748 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400749 data->minorversion = 0;
750 }
751 return data;
752}
753
David Howellsf7b422b2006-06-09 09:34:33 -0400754/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500755 * Sanity-check a server address provided by the mount command.
756 *
757 * Address family must be initialized, and address must not be
758 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400759 */
760static int nfs_verify_server_address(struct sockaddr *addr)
761{
762 switch (addr->sa_family) {
763 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500764 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700765 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500766 }
767 case AF_INET6: {
768 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
769 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400770 }
771 }
772
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400773 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400774 return 0;
775}
776
Chuck Lever9412b922007-12-10 14:59:21 -0500777/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400778 * Select between a default port value and a user-specified port value.
779 * If a zero value is set, then autobind will be used.
780 */
781static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port,
782 const unsigned short default_port)
783{
784 unsigned short port = default_port;
785
786 if (parsed_port != NFS_UNSPEC_PORT)
787 port = parsed_port;
788
789 rpc_set_port(sap, port);
790}
791
792/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400793 * Sanity check the NFS transport protocol.
794 *
795 */
796static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
797{
798 switch (mnt->nfs_server.protocol) {
799 case XPRT_TRANSPORT_UDP:
800 case XPRT_TRANSPORT_TCP:
801 case XPRT_TRANSPORT_RDMA:
802 break;
803 default:
804 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
805 }
806}
807
808/*
809 * For text based NFSv2/v3 mounts, the mount protocol transport default
810 * settings should depend upon the specified NFS transport.
811 */
812static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
813{
814 nfs_validate_transport_protocol(mnt);
815
816 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
817 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
818 return;
819 switch (mnt->nfs_server.protocol) {
820 case XPRT_TRANSPORT_UDP:
821 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
822 break;
823 case XPRT_TRANSPORT_TCP:
824 case XPRT_TRANSPORT_RDMA:
825 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
826 }
827}
828
829/*
Chuck Lever01060c82008-06-24 16:33:38 -0400830 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400831 */
832static int nfs_parse_security_flavors(char *value,
833 struct nfs_parsed_mount_data *mnt)
834{
835 substring_t args[MAX_OPT_ARGS];
836
837 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
838
839 switch (match_token(value, nfs_secflavor_tokens, args)) {
840 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400841 mnt->auth_flavors[0] = RPC_AUTH_NULL;
842 break;
843 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400844 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
845 break;
846 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400847 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
848 break;
849 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400850 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
851 break;
852 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400853 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
854 break;
855 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400856 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
857 break;
858 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400859 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
860 break;
861 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400862 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
863 break;
864 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400865 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
866 break;
867 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400868 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
869 break;
870 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400871 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
872 break;
873 default:
874 return 0;
875 }
876
Chuck Lever059f90b2009-08-09 15:09:31 -0400877 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400878 return 1;
879}
880
881/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400882 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400883 * a data structure. The whole mount string is processed; bad options are
884 * skipped as they are encountered. If there were no errors, return 1;
885 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400886 */
887static int nfs_parse_mount_options(char *raw,
888 struct nfs_parsed_mount_data *mnt)
889{
Eric Parisf9c3a382008-03-05 14:20:18 -0500890 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700891 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400892
893 if (!raw) {
894 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
895 return 1;
896 }
897 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
898
Eric Parisf9c3a382008-03-05 14:20:18 -0500899 secdata = alloc_secdata();
900 if (!secdata)
901 goto out_nomem;
902
903 rc = security_sb_copy_data(raw, secdata);
904 if (rc)
905 goto out_security_failure;
906
907 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
908 if (rc)
909 goto out_security_failure;
910
911 free_secdata(secdata);
912
Chuck Leverbf0fd762007-07-01 12:13:44 -0400913 while ((p = strsep(&raw, ",")) != NULL) {
914 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700915 unsigned long option;
916 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400917
918 if (!*p)
919 continue;
920
921 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
922
923 token = match_token(p, nfs_mount_option_tokens, args);
924 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400925
926 /*
927 * boolean options: foo/nofoo
928 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400929 case Opt_soft:
930 mnt->flags |= NFS_MOUNT_SOFT;
931 break;
932 case Opt_hard:
933 mnt->flags &= ~NFS_MOUNT_SOFT;
934 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400935 case Opt_posix:
936 mnt->flags |= NFS_MOUNT_POSIX;
937 break;
938 case Opt_noposix:
939 mnt->flags &= ~NFS_MOUNT_POSIX;
940 break;
941 case Opt_cto:
942 mnt->flags &= ~NFS_MOUNT_NOCTO;
943 break;
944 case Opt_nocto:
945 mnt->flags |= NFS_MOUNT_NOCTO;
946 break;
947 case Opt_ac:
948 mnt->flags &= ~NFS_MOUNT_NOAC;
949 break;
950 case Opt_noac:
951 mnt->flags |= NFS_MOUNT_NOAC;
952 break;
953 case Opt_lock:
954 mnt->flags &= ~NFS_MOUNT_NONLM;
955 break;
956 case Opt_nolock:
957 mnt->flags |= NFS_MOUNT_NONLM;
958 break;
959 case Opt_v2:
960 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400961 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400962 break;
963 case Opt_v3:
964 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400965 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400966 break;
Chuck Lever764302c2009-09-08 19:50:03 -0400967#ifdef CONFIG_NFS_V4
968 case Opt_v4:
969 mnt->flags &= ~NFS_MOUNT_VER3;
970 mnt->version = 4;
971 break;
972#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -0400973 case Opt_udp:
974 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400975 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400976 break;
977 case Opt_tcp:
978 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400979 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400980 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400981 case Opt_rdma:
982 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
983 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -0400984 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400985 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400986 case Opt_acl:
987 mnt->flags &= ~NFS_MOUNT_NOACL;
988 break;
989 case Opt_noacl:
990 mnt->flags |= NFS_MOUNT_NOACL;
991 break;
992 case Opt_rdirplus:
993 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
994 break;
995 case Opt_nordirplus:
996 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
997 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400998 case Opt_sharecache:
999 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1000 break;
1001 case Opt_nosharecache:
1002 mnt->flags |= NFS_MOUNT_UNSHARED;
1003 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001004 case Opt_resvport:
1005 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1006 break;
1007 case Opt_noresvport:
1008 mnt->flags |= NFS_MOUNT_NORESVPORT;
1009 break;
David Howellsb797cac2009-04-03 16:42:48 +01001010 case Opt_fscache:
1011 mnt->options |= NFS_OPTION_FSCACHE;
1012 kfree(mnt->fscache_uniq);
1013 mnt->fscache_uniq = NULL;
1014 break;
1015 case Opt_nofscache:
1016 mnt->options &= ~NFS_OPTION_FSCACHE;
1017 kfree(mnt->fscache_uniq);
1018 mnt->fscache_uniq = NULL;
1019 break;
1020 case Opt_fscache_uniq:
1021 string = match_strdup(args);
1022 if (!string)
1023 goto out_nomem;
1024 kfree(mnt->fscache_uniq);
1025 mnt->fscache_uniq = string;
1026 mnt->options |= NFS_OPTION_FSCACHE;
1027 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001028
Chuck Leverf45663c2008-06-24 19:28:02 -04001029 /*
1030 * options that take numeric values
1031 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001032 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001033 string = match_strdup(args);
1034 if (string == NULL)
1035 goto out_nomem;
1036 rc = strict_strtoul(string, 10, &option);
1037 kfree(string);
1038 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001039 goto out_invalid_value;
1040 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001041 break;
1042 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001043 string = match_strdup(args);
1044 if (string == NULL)
1045 goto out_nomem;
1046 rc = strict_strtoul(string, 10, &option);
1047 kfree(string);
1048 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001049 goto out_invalid_value;
1050 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001051 break;
1052 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001053 string = match_strdup(args);
1054 if (string == NULL)
1055 goto out_nomem;
1056 rc = strict_strtoul(string, 10, &option);
1057 kfree(string);
1058 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001059 goto out_invalid_value;
1060 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001061 break;
1062 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001063 string = match_strdup(args);
1064 if (string == NULL)
1065 goto out_nomem;
1066 rc = strict_strtoul(string, 10, &option);
1067 kfree(string);
1068 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001069 goto out_invalid_value;
1070 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001071 break;
1072 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001073 string = match_strdup(args);
1074 if (string == NULL)
1075 goto out_nomem;
1076 rc = strict_strtoul(string, 10, &option);
1077 kfree(string);
1078 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001079 goto out_invalid_value;
1080 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001081 break;
1082 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001083 string = match_strdup(args);
1084 if (string == NULL)
1085 goto out_nomem;
1086 rc = strict_strtoul(string, 10, &option);
1087 kfree(string);
1088 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001089 goto out_invalid_value;
1090 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001091 break;
1092 case Opt_acregmin:
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->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 break;
1102 case Opt_acregmax:
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)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001109 goto out_invalid_value;
1110 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001111 break;
1112 case Opt_acdirmin:
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 Leverd23c45f2009-06-17 18:02:13 -07001119 goto out_invalid_value;
1120 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001121 break;
1122 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001123 string = match_strdup(args);
1124 if (string == NULL)
1125 goto out_nomem;
1126 rc = strict_strtoul(string, 10, &option);
1127 kfree(string);
1128 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001129 goto out_invalid_value;
1130 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001131 break;
1132 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001133 string = match_strdup(args);
1134 if (string == NULL)
1135 goto out_nomem;
1136 rc = strict_strtoul(string, 10, &option);
1137 kfree(string);
1138 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001139 goto out_invalid_value;
1140 mnt->acregmin = mnt->acregmax =
1141 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001142 break;
1143 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001144 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)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001150 goto out_invalid_value;
1151 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001152 break;
1153 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001154 string = match_strdup(args);
1155 if (string == NULL)
1156 goto out_nomem;
1157 rc = strict_strtoul(string, 10, &option);
1158 kfree(string);
1159 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001160 goto out_invalid_value;
1161 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001162 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001163 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001164 string = match_strdup(args);
1165 if (string == NULL)
1166 goto out_nomem;
1167 rc = strict_strtoul(string, 10, &option);
1168 kfree(string);
1169 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001170 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001171 option > NFS_MNT3_VERSION)
1172 goto out_invalid_value;
1173 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001174 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001176 string = match_strdup(args);
1177 if (string == NULL)
1178 goto out_nomem;
1179 rc = strict_strtoul(string, 10, &option);
1180 kfree(string);
1181 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001182 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001183 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001184 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001185 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001186 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001187 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001188 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001190 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001191 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001192#ifdef CONFIG_NFS_V4
1193 case NFS4_VERSION:
1194 mnt->flags &= ~NFS_MOUNT_VER3;
1195 mnt->version = 4;
1196 break;
1197#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001198 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001199 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 }
1201 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001202 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001203 string = match_strdup(args);
1204 if (string == NULL)
1205 goto out_nomem;
1206 rc = strict_strtoul(string, 10, &option);
1207 kfree(string);
1208 if (rc != 0)
1209 goto out_invalid_value;
1210 if (option > NFS4_MAX_MINOR_VERSION)
1211 goto out_invalid_value;
1212 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001213 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214
Chuck Leverf45663c2008-06-24 19:28:02 -04001215 /*
1216 * options that take text values
1217 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 case Opt_sec:
1219 string = match_strdup(args);
1220 if (string == NULL)
1221 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001222 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001223 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001224 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001225 dfprintk(MOUNT, "NFS: unrecognized "
1226 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001227 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001228 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001229 break;
1230 case Opt_proto:
1231 string = match_strdup(args);
1232 if (string == NULL)
1233 goto out_nomem;
1234 token = match_token(string,
1235 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236
1237 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001238 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001239 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001240 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001241 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001243 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001244 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001245 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001246 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001248 case Opt_xprt_rdma:
1249 /* vector side protocols to TCP */
1250 mnt->flags |= NFS_MOUNT_TCP;
1251 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001252 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001253 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001254 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001256 dfprintk(MOUNT, "NFS: unrecognized "
1257 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001258 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 }
1260 break;
1261 case Opt_mountproto:
1262 string = match_strdup(args);
1263 if (string == NULL)
1264 goto out_nomem;
1265 token = match_token(string,
1266 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001267 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001268
1269 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001270 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001271 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001273 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001274 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001276 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001278 dfprintk(MOUNT, "NFS: unrecognized "
1279 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001280 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001281 }
1282 break;
1283 case Opt_addr:
1284 string = match_strdup(args);
1285 if (string == NULL)
1286 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001287 mnt->nfs_server.addrlen =
1288 rpc_pton(string, strlen(string),
1289 (struct sockaddr *)
1290 &mnt->nfs_server.address,
1291 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001292 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001293 if (mnt->nfs_server.addrlen == 0)
1294 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295 break;
1296 case Opt_clientaddr:
1297 string = match_strdup(args);
1298 if (string == NULL)
1299 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001300 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001301 mnt->client_address = string;
1302 break;
Chuck Lever33832032007-12-10 14:59:13 -05001303 case Opt_mounthost:
1304 string = match_strdup(args);
1305 if (string == NULL)
1306 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001307 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001308 mnt->mount_server.hostname = string;
1309 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001310 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 string = match_strdup(args);
1312 if (string == NULL)
1313 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001314 mnt->mount_server.addrlen =
1315 rpc_pton(string, strlen(string),
1316 (struct sockaddr *)
1317 &mnt->mount_server.address,
1318 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001319 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001320 if (mnt->mount_server.addrlen == 0)
1321 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001323 case Opt_lookupcache:
1324 string = match_strdup(args);
1325 if (string == NULL)
1326 goto out_nomem;
1327 token = match_token(string,
1328 nfs_lookupcache_tokens, args);
1329 kfree(string);
1330 switch (token) {
1331 case Opt_lookupcache_all:
1332 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1333 break;
1334 case Opt_lookupcache_positive:
1335 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1336 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1337 break;
1338 case Opt_lookupcache_none:
1339 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1340 break;
1341 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001342 dfprintk(MOUNT, "NFS: invalid "
1343 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001344 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001345 };
1346 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347
Chuck Leverf45663c2008-06-24 19:28:02 -04001348 /*
1349 * Special options
1350 */
1351 case Opt_sloppy:
1352 sloppy = 1;
1353 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1354 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001355 case Opt_userspace:
1356 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001357 dfprintk(MOUNT, "NFS: ignoring mount option "
1358 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001359 break;
1360
1361 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001362 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001363 dfprintk(MOUNT, "NFS: unrecognized mount option "
1364 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001365 }
1366 }
1367
Chuck Leverd23c45f2009-06-17 18:02:13 -07001368 if (!sloppy && invalid_option)
1369 return 0;
1370
Chuck Leverbf0fd762007-07-01 12:13:44 -04001371 return 1;
1372
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001373out_invalid_address:
1374 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1375 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001376out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001377 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001378 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379out_nomem:
1380 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1381 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001382out_security_failure:
1383 free_secdata(secdata);
1384 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1385 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001386}
1387
1388/*
Chuck Leverec88f282009-08-09 15:09:32 -04001389 * Match the requested auth flavors with the list returned by
1390 * the server. Returns zero and sets the mount's authentication
1391 * flavor on success; returns -EACCES if server does not support
1392 * the requested flavor.
1393 */
1394static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1395 struct nfs_mount_request *request)
1396{
1397 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1398
1399 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001400 * Certain releases of Linux's mountd return an empty
1401 * flavor list. To prevent behavioral regression with
1402 * these servers (ie. rejecting mounts that used to
1403 * succeed), revert to pre-2.6.32 behavior (no checking)
1404 * if the returned flavor list is empty.
1405 */
1406 if (server_authlist_len == 0)
1407 return 0;
1408
1409 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001410 * We avoid sophisticated negotiating here, as there are
1411 * plenty of cases where we can get it wrong, providing
1412 * either too little or too much security.
1413 *
1414 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1415 * flavor listed first. However, some servers list
1416 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1417 * preferred default, in args->auth_flavors[0] if user
1418 * didn't specify sec= mount option.
1419 */
1420 for (i = 0; i < args->auth_flavor_len; i++)
1421 for (j = 0; j < server_authlist_len; j++)
1422 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1423 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1424 request->auth_flavs[j]);
1425 args->auth_flavors[0] = request->auth_flavs[j];
1426 return 0;
1427 }
1428
1429 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1430 nfs_umount(request);
1431 return -EACCES;
1432}
1433
1434/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001435 * Use the remote server's MOUNT service to request the NFS file handle
1436 * corresponding to the provided path.
1437 */
1438static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1439 struct nfs_fh *root_fh)
1440{
Chuck Leverec88f282009-08-09 15:09:32 -04001441 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1442 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001443 struct nfs_mount_request request = {
1444 .sap = (struct sockaddr *)
1445 &args->mount_server.address,
1446 .dirpath = args->nfs_server.export_path,
1447 .protocol = args->mount_server.protocol,
1448 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001449 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001450 .auth_flav_len = &server_authlist_len,
1451 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001452 };
Chuck Lever4c568012007-12-10 14:59:28 -05001453 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001454
1455 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001456 switch (args->version) {
1457 default:
1458 args->mount_server.version = NFS_MNT3_VERSION;
1459 break;
1460 case 2:
1461 args->mount_server.version = NFS_MNT_VERSION;
1462 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001463 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001464 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001465
Chuck Lever33832032007-12-10 14:59:13 -05001466 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001467 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001468 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001469 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001470
Chuck Lever0076d7b2007-07-01 12:13:49 -04001471 /*
1472 * Construct the mount server's address.
1473 */
Chuck Lever4c568012007-12-10 14:59:28 -05001474 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001475 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001476 args->nfs_server.addrlen);
1477 args->mount_server.addrlen = args->nfs_server.addrlen;
1478 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001479 request.salen = args->mount_server.addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001480 nfs_set_default_port(request.sap, args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001481
1482 /*
1483 * Now ask the mount server to map our export path
1484 * to a file handle.
1485 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001486 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001487 if (status != 0) {
1488 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1489 request.hostname, status);
1490 return status;
1491 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001492
Chuck Leverec88f282009-08-09 15:09:32 -04001493 /*
1494 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1495 */
1496 if (args->mount_server.version != NFS_MNT3_VERSION)
1497 return 0;
1498 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001499}
1500
Chuck Leverd1aa0822008-06-23 12:36:45 -04001501static int nfs_parse_simple_hostname(const char *dev_name,
1502 char **hostname, size_t maxnamlen,
1503 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001504{
1505 size_t len;
1506 char *colon, *comma;
1507
1508 colon = strchr(dev_name, ':');
1509 if (colon == NULL)
1510 goto out_bad_devname;
1511
1512 len = colon - dev_name;
1513 if (len > maxnamlen)
1514 goto out_hostname;
1515
1516 /* N.B. caller will free nfs_server.hostname in all cases */
1517 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1518 if (!*hostname)
1519 goto out_nomem;
1520
1521 /* kill possible hostname list: not supported */
1522 comma = strchr(*hostname, ',');
1523 if (comma != NULL) {
1524 if (comma == *hostname)
1525 goto out_bad_devname;
1526 *comma = '\0';
1527 }
1528
1529 colon++;
1530 len = strlen(colon);
1531 if (len > maxpathlen)
1532 goto out_path;
1533 *export_path = kstrndup(colon, len, GFP_KERNEL);
1534 if (!*export_path)
1535 goto out_nomem;
1536
1537 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1538 return 0;
1539
1540out_bad_devname:
1541 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1542 return -EINVAL;
1543
1544out_nomem:
1545 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1546 return -ENOMEM;
1547
1548out_hostname:
1549 dfprintk(MOUNT, "NFS: server hostname too long\n");
1550 return -ENAMETOOLONG;
1551
1552out_path:
1553 dfprintk(MOUNT, "NFS: export pathname too long\n");
1554 return -ENAMETOOLONG;
1555}
1556
1557/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001558 * Hostname has square brackets around it because it contains one or
1559 * more colons. We look for the first closing square bracket, and a
1560 * colon must follow it.
1561 */
1562static int nfs_parse_protected_hostname(const char *dev_name,
1563 char **hostname, size_t maxnamlen,
1564 char **export_path, size_t maxpathlen)
1565{
1566 size_t len;
1567 char *start, *end;
1568
1569 start = (char *)(dev_name + 1);
1570
1571 end = strchr(start, ']');
1572 if (end == NULL)
1573 goto out_bad_devname;
1574 if (*(end + 1) != ':')
1575 goto out_bad_devname;
1576
1577 len = end - start;
1578 if (len > maxnamlen)
1579 goto out_hostname;
1580
1581 /* N.B. caller will free nfs_server.hostname in all cases */
1582 *hostname = kstrndup(start, len, GFP_KERNEL);
1583 if (*hostname == NULL)
1584 goto out_nomem;
1585
1586 end += 2;
1587 len = strlen(end);
1588 if (len > maxpathlen)
1589 goto out_path;
1590 *export_path = kstrndup(end, len, GFP_KERNEL);
1591 if (!*export_path)
1592 goto out_nomem;
1593
1594 return 0;
1595
1596out_bad_devname:
1597 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1598 return -EINVAL;
1599
1600out_nomem:
1601 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1602 return -ENOMEM;
1603
1604out_hostname:
1605 dfprintk(MOUNT, "NFS: server hostname too long\n");
1606 return -ENAMETOOLONG;
1607
1608out_path:
1609 dfprintk(MOUNT, "NFS: export pathname too long\n");
1610 return -ENAMETOOLONG;
1611}
1612
1613/*
1614 * Split "dev_name" into "hostname:export_path".
1615 *
1616 * The leftmost colon demarks the split between the server's hostname
1617 * and the export path. If the hostname starts with a left square
1618 * bracket, then it may contain colons.
1619 *
1620 * Note: caller frees hostname and export path, even on error.
1621 */
1622static int nfs_parse_devname(const char *dev_name,
1623 char **hostname, size_t maxnamlen,
1624 char **export_path, size_t maxpathlen)
1625{
1626 if (*dev_name == '[')
1627 return nfs_parse_protected_hostname(dev_name,
1628 hostname, maxnamlen,
1629 export_path, maxpathlen);
1630
1631 return nfs_parse_simple_hostname(dev_name,
1632 hostname, maxnamlen,
1633 export_path, maxpathlen);
1634}
1635
1636/*
David Howells54ceac42006-08-22 20:06:13 -04001637 * Validate the NFS2/NFS3 mount data
1638 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001639 *
1640 * For option strings, user space handles the following behaviors:
1641 *
1642 * + DNS: mapping server host name to IP address ("addr=" option)
1643 *
1644 * + failure mode: how to behave if a mount request can't be handled
1645 * immediately ("fg/bg" option)
1646 *
1647 * + retry: how often to retry a mount request ("retry=" option)
1648 *
1649 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1650 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001651 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001652static int nfs_validate_mount_data(void *options,
1653 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001654 struct nfs_fh *mntfh,
1655 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001656{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001657 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001658 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001659
Chuck Lever5df36e72007-07-01 12:12:56 -04001660 if (data == NULL)
1661 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001662
David Howellsf7b422b2006-06-09 09:34:33 -04001663 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001664 case 1:
1665 data->namlen = 0;
1666 case 2:
1667 data->bsize = 0;
1668 case 3:
1669 if (data->flags & NFS_MOUNT_VER3)
1670 goto out_no_v3;
1671 data->root.size = NFS2_FHSIZE;
1672 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1673 case 4:
1674 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1675 goto out_no_sec;
1676 case 5:
1677 memset(data->context, 0, sizeof(data->context));
1678 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001679 if (data->flags & NFS_MOUNT_VER3) {
1680 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1681 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001682 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001683 args->version = 3;
1684 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001685 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001686 args->version = 2;
1687 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001688
Chuck Lever5df36e72007-07-01 12:12:56 -04001689
1690 memcpy(mntfh->data, data->root.data, mntfh->size);
1691 if (mntfh->size < sizeof(mntfh->data))
1692 memset(mntfh->data + mntfh->size, 0,
1693 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001694
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001695 /*
1696 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1697 * can deal with.
1698 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001699 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001700 args->rsize = data->rsize;
1701 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001702 args->timeo = data->timeo;
1703 args->retrans = data->retrans;
1704 args->acregmin = data->acregmin;
1705 args->acregmax = data->acregmax;
1706 args->acdirmin = data->acdirmin;
1707 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001708
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001709 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001710 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001711 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001712 goto out_no_address;
1713
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001714 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001715 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001716 /* N.B. caller will free nfs_server.hostname in all cases */
1717 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1718 args->namlen = data->namlen;
1719 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001720
1721 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1722 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001723 if (!args->nfs_server.hostname)
1724 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001725
1726 /*
1727 * The legacy version 6 binary mount data from userspace has a
1728 * field used only to transport selinux information into the
1729 * the kernel. To continue to support that functionality we
1730 * have a touch of selinux knowledge here in the NFS code. The
1731 * userspace code converted context=blah to just blah so we are
1732 * converting back to the full string selinux understands.
1733 */
1734 if (data->context[0]){
1735#ifdef CONFIG_SECURITY_SELINUX
1736 int rc;
1737 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1738 if (!opts_str)
1739 return -ENOMEM;
1740 strcpy(opts_str, "context=");
1741 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1742 strcat(opts_str, &data->context[0]);
1743 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1744 kfree(opts_str);
1745 if (rc)
1746 return rc;
1747#else
1748 return -EINVAL;
1749#endif
1750 }
1751
Chuck Lever5df36e72007-07-01 12:12:56 -04001752 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001753 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001754 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001755
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001756 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001757 return -EINVAL;
1758
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001759 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001760 goto out_no_address;
1761
Chuck Lever764302c2009-09-08 19:50:03 -04001762 if (args->version == 4)
1763#ifdef CONFIG_NFS_V4
1764 return nfs4_validate_text_mount_data(options,
1765 args, dev_name);
1766#else
1767 goto out_v4_not_compiled;
1768#endif
1769
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001770 nfs_set_default_port(sap, args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001771
Trond Myklebust259875e2008-07-02 14:43:47 -04001772 nfs_set_mount_transport_protocol(args);
1773
Chuck Leverdc045892008-06-23 12:36:37 -04001774 status = nfs_parse_devname(dev_name,
1775 &args->nfs_server.hostname,
1776 PAGE_SIZE,
1777 &args->nfs_server.export_path,
1778 NFS_MAXPATHLEN);
1779 if (!status)
1780 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001781
Chuck Leverdc045892008-06-23 12:36:37 -04001782 kfree(args->nfs_server.export_path);
1783 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001784
Chuck Lever136d5582007-07-01 12:13:54 -04001785 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001786 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001787
Chuck Lever136d5582007-07-01 12:13:54 -04001788 break;
1789 }
David Howellsf7b422b2006-06-09 09:34:33 -04001790 }
David Howells54ceac42006-08-22 20:06:13 -04001791
David Howellsf7b422b2006-06-09 09:34:33 -04001792#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001793 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001794 goto out_v3_not_compiled;
1795#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001796
David Howells54ceac42006-08-22 20:06:13 -04001797 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001798
1799out_no_data:
1800 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1801 return -EINVAL;
1802
1803out_no_v3:
1804 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1805 data->version);
1806 return -EINVAL;
1807
1808out_no_sec:
1809 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1810 return -EINVAL;
1811
Chuck Lever5df36e72007-07-01 12:12:56 -04001812#ifndef CONFIG_NFS_V3
1813out_v3_not_compiled:
1814 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1815 return -EPROTONOSUPPORT;
1816#endif /* !CONFIG_NFS_V3 */
1817
Chuck Lever764302c2009-09-08 19:50:03 -04001818#ifndef CONFIG_NFS_V4
1819out_v4_not_compiled:
1820 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1821 return -EPROTONOSUPPORT;
1822#endif /* !CONFIG_NFS_V4 */
1823
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001824out_nomem:
1825 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1826 return -ENOMEM;
1827
Chuck Lever5df36e72007-07-01 12:12:56 -04001828out_no_address:
1829 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1830 return -EINVAL;
1831
1832out_invalid_fh:
1833 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1834 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001835}
1836
Jeff Layton48b605f2008-06-10 15:38:39 -04001837static int
1838nfs_compare_remount_data(struct nfs_server *nfss,
1839 struct nfs_parsed_mount_data *data)
1840{
1841 if (data->flags != nfss->flags ||
1842 data->rsize != nfss->rsize ||
1843 data->wsize != nfss->wsize ||
1844 data->retrans != nfss->client->cl_timeout->to_retries ||
1845 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1846 data->acregmin != nfss->acregmin / HZ ||
1847 data->acregmax != nfss->acregmax / HZ ||
1848 data->acdirmin != nfss->acdirmin / HZ ||
1849 data->acdirmax != nfss->acdirmax / HZ ||
1850 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1851 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1852 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1853 data->nfs_server.addrlen) != 0)
1854 return -EINVAL;
1855
1856 return 0;
1857}
1858
1859static int
1860nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1861{
1862 int error;
1863 struct nfs_server *nfss = sb->s_fs_info;
1864 struct nfs_parsed_mount_data *data;
1865 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1866 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001867 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001868
1869 /*
1870 * Userspace mount programs that send binary options generally send
1871 * them populated with default values. We have no way to know which
1872 * ones were explicitly specified. Fall back to legacy behavior and
1873 * just return success.
1874 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001875 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1876 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1877 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001878 return 0;
1879
1880 data = kzalloc(sizeof(*data), GFP_KERNEL);
1881 if (data == NULL)
1882 return -ENOMEM;
1883
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001884 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001885 /* fill out struct with values from existing mount */
1886 data->flags = nfss->flags;
1887 data->rsize = nfss->rsize;
1888 data->wsize = nfss->wsize;
1889 data->retrans = nfss->client->cl_timeout->to_retries;
1890 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1891 data->acregmin = nfss->acregmin / HZ;
1892 data->acregmax = nfss->acregmax / HZ;
1893 data->acdirmin = nfss->acdirmin / HZ;
1894 data->acdirmax = nfss->acdirmax / HZ;
1895 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1896 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1897 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1898 data->nfs_server.addrlen);
1899
1900 /* overwrite those values with any that were specified */
1901 error = nfs_parse_mount_options((char *)options, data);
1902 if (error < 0)
1903 goto out;
1904
1905 /* compare new mount options with old ones */
1906 error = nfs_compare_remount_data(nfss, data);
1907out:
1908 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001909 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001910 return error;
1911}
1912
David Howells54ceac42006-08-22 20:06:13 -04001913/*
1914 * Initialise the common bits of the superblock
1915 */
1916static inline void nfs_initialise_sb(struct super_block *sb)
1917{
1918 struct nfs_server *server = NFS_SB(sb);
1919
1920 sb->s_magic = NFS_SUPER_MAGIC;
1921
1922 /* We probably want something more informative here */
1923 snprintf(sb->s_id, sizeof(sb->s_id),
1924 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1925
1926 if (sb->s_blocksize == 0)
1927 sb->s_blocksize = nfs_block_bits(server->wsize,
1928 &sb->s_blocksize_bits);
1929
1930 if (server->flags & NFS_MOUNT_NOAC)
1931 sb->s_flags |= MS_SYNCHRONOUS;
1932
Jens Axboe32a88aa2009-09-16 15:02:33 +02001933 sb->s_bdi = &server->backing_dev_info;
1934
David Howells54ceac42006-08-22 20:06:13 -04001935 nfs_super_set_maxbytes(sb, server->maxfilesize);
1936}
1937
1938/*
1939 * Finish setting up an NFS2/3 superblock
1940 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001941static void nfs_fill_super(struct super_block *sb,
1942 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001943{
1944 struct nfs_server *server = NFS_SB(sb);
1945
1946 sb->s_blocksize_bits = 0;
1947 sb->s_blocksize = 0;
1948 if (data->bsize)
1949 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1950
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001951 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04001952 /* The VFS shouldn't apply the umask to mode bits. We will do
1953 * so ourselves when necessary.
1954 */
1955 sb->s_flags |= MS_POSIXACL;
1956 sb->s_time_gran = 1;
1957 }
1958
1959 sb->s_op = &nfs_sops;
1960 nfs_initialise_sb(sb);
1961}
1962
1963/*
1964 * Finish setting up a cloned NFS2/3 superblock
1965 */
1966static void nfs_clone_super(struct super_block *sb,
1967 const struct super_block *old_sb)
1968{
1969 struct nfs_server *server = NFS_SB(sb);
1970
1971 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1972 sb->s_blocksize = old_sb->s_blocksize;
1973 sb->s_maxbytes = old_sb->s_maxbytes;
1974
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001975 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04001976 /* The VFS shouldn't apply the umask to mode bits. We will do
1977 * so ourselves when necessary.
1978 */
1979 sb->s_flags |= MS_POSIXACL;
1980 sb->s_time_gran = 1;
1981 }
1982
1983 sb->s_op = old_sb->s_op;
1984 nfs_initialise_sb(sb);
1985}
1986
Trond Myklebust275a5d22007-05-16 16:53:28 -04001987static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1988{
1989 const struct nfs_server *a = s->s_fs_info;
1990 const struct rpc_clnt *clnt_a = a->client;
1991 const struct rpc_clnt *clnt_b = b->client;
1992
1993 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1994 goto Ebusy;
1995 if (a->nfs_client != b->nfs_client)
1996 goto Ebusy;
1997 if (a->flags != b->flags)
1998 goto Ebusy;
1999 if (a->wsize != b->wsize)
2000 goto Ebusy;
2001 if (a->rsize != b->rsize)
2002 goto Ebusy;
2003 if (a->acregmin != b->acregmin)
2004 goto Ebusy;
2005 if (a->acregmax != b->acregmax)
2006 goto Ebusy;
2007 if (a->acdirmin != b->acdirmin)
2008 goto Ebusy;
2009 if (a->acdirmax != b->acdirmax)
2010 goto Ebusy;
2011 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2012 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002013 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002014Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002015 return 0;
2016}
2017
2018struct nfs_sb_mountdata {
2019 struct nfs_server *server;
2020 int mntflags;
2021};
2022
2023static int nfs_set_super(struct super_block *s, void *data)
2024{
2025 struct nfs_sb_mountdata *sb_mntdata = data;
2026 struct nfs_server *server = sb_mntdata->server;
2027 int ret;
2028
2029 s->s_flags = sb_mntdata->mntflags;
2030 s->s_fs_info = server;
2031 ret = set_anon_super(s, server);
2032 if (ret == 0)
2033 server->s_dev = s->s_dev;
2034 return ret;
2035}
2036
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002037static int nfs_compare_super_address(struct nfs_server *server1,
2038 struct nfs_server *server2)
2039{
2040 struct sockaddr *sap1, *sap2;
2041
2042 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2043 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2044
2045 if (sap1->sa_family != sap2->sa_family)
2046 return 0;
2047
2048 switch (sap1->sa_family) {
2049 case AF_INET: {
2050 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2051 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2052 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2053 return 0;
2054 if (sin1->sin_port != sin2->sin_port)
2055 return 0;
2056 break;
2057 }
2058 case AF_INET6: {
2059 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2060 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2061 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2062 return 0;
2063 if (sin1->sin6_port != sin2->sin6_port)
2064 return 0;
2065 break;
2066 }
2067 default:
2068 return 0;
2069 }
2070
2071 return 1;
2072}
2073
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002074static int nfs_compare_super(struct super_block *sb, void *data)
2075{
2076 struct nfs_sb_mountdata *sb_mntdata = data;
2077 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2078 int mntflags = sb_mntdata->mntflags;
2079
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002080 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002081 return 0;
2082 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2083 if (old->flags & NFS_MOUNT_UNSHARED)
2084 return 0;
2085 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2086 return 0;
2087 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002088}
2089
Miklos Szeredifa799752008-04-30 00:54:33 -07002090static int nfs_bdi_register(struct nfs_server *server)
2091{
2092 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2093}
2094
David Howells54ceac42006-08-22 20:06:13 -04002095static int nfs_get_sb(struct file_system_type *fs_type,
2096 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2097{
2098 struct nfs_server *server = NULL;
2099 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002100 struct nfs_parsed_mount_data *data;
2101 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002102 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002103 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002104 struct nfs_sb_mountdata sb_mntdata = {
2105 .mntflags = flags,
2106 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002107 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002108
Trond Myklebustc5811db2009-10-06 15:40:15 -04002109 data = nfs_alloc_parsed_mount_data(3);
Trond Myklebust33852a12008-06-19 14:20:11 -04002110 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2111 if (data == NULL || mntfh == NULL)
2112 goto out_free_fh;
2113
2114 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002115
David Howells54ceac42006-08-22 20:06:13 -04002116 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002117 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002118 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002119 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002120
Chuck Lever764302c2009-09-08 19:50:03 -04002121#ifdef CONFIG_NFS_V4
2122 if (data->version == 4) {
2123 error = nfs4_try_mount(flags, dev_name, data, mnt);
2124 kfree(data->client_address);
2125 goto out;
2126 }
2127#endif /* CONFIG_NFS_V4 */
2128
David Howells54ceac42006-08-22 20:06:13 -04002129 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002130 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002131 if (IS_ERR(server)) {
2132 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002133 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002134 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002135 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002136
Trond Myklebust75180df2007-05-16 16:53:28 -04002137 if (server->flags & NFS_MOUNT_UNSHARED)
2138 compare_super = NULL;
2139
David Howells54ceac42006-08-22 20:06:13 -04002140 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002141 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002142 if (IS_ERR(s)) {
2143 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002144 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002145 }
2146
David Howells54ceac42006-08-22 20:06:13 -04002147 if (s->s_fs_info != server) {
2148 nfs_free_server(server);
2149 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002150 } else {
2151 error = nfs_bdi_register(server);
2152 if (error)
2153 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002154 }
David Howells54ceac42006-08-22 20:06:13 -04002155
2156 if (!s->s_root) {
2157 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002158 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002159 nfs_fscache_get_super_cookie(
2160 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002161 }
2162
Trond Myklebust33852a12008-06-19 14:20:11 -04002163 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002164 if (IS_ERR(mntroot)) {
2165 error = PTR_ERR(mntroot);
2166 goto error_splat_super;
2167 }
2168
Trond Myklebust33852a12008-06-19 14:20:11 -04002169 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002170 if (error)
2171 goto error_splat_root;
2172
David Howellsf7b422b2006-06-09 09:34:33 -04002173 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002174 mnt->mnt_sb = s;
2175 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002176 error = 0;
2177
2178out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002179 kfree(data->nfs_server.hostname);
2180 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002181 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002182 security_free_mnt_opts(&data->lsm_opts);
2183out_free_fh:
2184 kfree(mntfh);
2185 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002186 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002187
David Howells54ceac42006-08-22 20:06:13 -04002188out_err_nosb:
2189 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002190 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002191
Eric Parisf9c3a382008-03-05 14:20:18 -05002192error_splat_root:
2193 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002194error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002195 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002196 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002197}
2198
David Howells54ceac42006-08-22 20:06:13 -04002199/*
2200 * Destroy an NFS2/3 superblock
2201 */
David Howellsf7b422b2006-06-09 09:34:33 -04002202static void nfs_kill_super(struct super_block *s)
2203{
2204 struct nfs_server *server = NFS_SB(s);
2205
2206 kill_anon_super(s);
Jens Axboe92f25052009-09-17 14:51:44 +02002207 bdi_unregister(&server->backing_dev_info);
David Howells08734042009-04-03 16:42:42 +01002208 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002209 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002210}
2211
David Howells54ceac42006-08-22 20:06:13 -04002212/*
2213 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2214 */
2215static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2216 const char *dev_name, void *raw_data,
2217 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002218{
2219 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002220 struct super_block *s;
2221 struct nfs_server *server;
2222 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002223 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002224 struct nfs_sb_mountdata sb_mntdata = {
2225 .mntflags = flags,
2226 };
David Howells54ceac42006-08-22 20:06:13 -04002227 int error;
2228
2229 dprintk("--> nfs_xdev_get_sb()\n");
2230
2231 /* create a new volume representation */
2232 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2233 if (IS_ERR(server)) {
2234 error = PTR_ERR(server);
2235 goto out_err_noserver;
2236 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002237 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002238
Trond Myklebust75180df2007-05-16 16:53:28 -04002239 if (server->flags & NFS_MOUNT_UNSHARED)
2240 compare_super = NULL;
2241
David Howells54ceac42006-08-22 20:06:13 -04002242 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002243 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002244 if (IS_ERR(s)) {
2245 error = PTR_ERR(s);
2246 goto out_err_nosb;
2247 }
2248
2249 if (s->s_fs_info != server) {
2250 nfs_free_server(server);
2251 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002252 } else {
2253 error = nfs_bdi_register(server);
2254 if (error)
2255 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002256 }
2257
2258 if (!s->s_root) {
2259 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002260 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002261 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002262 }
2263
2264 mntroot = nfs_get_root(s, data->fh);
2265 if (IS_ERR(mntroot)) {
2266 error = PTR_ERR(mntroot);
2267 goto error_splat_super;
2268 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002269 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002270 dput(mntroot);
2271 error = -ESTALE;
2272 goto error_splat_super;
2273 }
David Howells54ceac42006-08-22 20:06:13 -04002274
2275 s->s_flags |= MS_ACTIVE;
2276 mnt->mnt_sb = s;
2277 mnt->mnt_root = mntroot;
2278
Eric Parisf9c3a382008-03-05 14:20:18 -05002279 /* clone any lsm security options from the parent to the new sb */
2280 security_sb_clone_mnt_opts(data->sb, s);
2281
David Howells54ceac42006-08-22 20:06:13 -04002282 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2283 return 0;
2284
2285out_err_nosb:
2286 nfs_free_server(server);
2287out_err_noserver:
2288 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2289 return error;
2290
2291error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002292 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002293 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2294 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002295}
2296
2297#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002298
2299/*
2300 * Finish setting up a cloned NFS4 superblock
2301 */
2302static void nfs4_clone_super(struct super_block *sb,
2303 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002304{
David Howells54ceac42006-08-22 20:06:13 -04002305 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2306 sb->s_blocksize = old_sb->s_blocksize;
2307 sb->s_maxbytes = old_sb->s_maxbytes;
2308 sb->s_time_gran = 1;
2309 sb->s_op = old_sb->s_op;
2310 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002311}
2312
2313/*
2314 * Set up an NFS4 superblock
2315 */
David Howells54ceac42006-08-22 20:06:13 -04002316static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002317{
David Howellsf7b422b2006-06-09 09:34:33 -04002318 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002319 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002320 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002321}
2322
Trond Myklebust01c3f052009-06-17 13:22:58 -07002323static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2324{
2325 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2326}
2327
Chuck Lever7630c852009-09-08 19:49:57 -04002328static int nfs4_validate_text_mount_data(void *options,
2329 struct nfs_parsed_mount_data *args,
2330 const char *dev_name)
2331{
2332 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2333
2334 nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT);
2335
2336 nfs_validate_transport_protocol(args);
2337
2338 nfs4_validate_mount_flags(args);
2339
Trond Myklebust2ecda722009-09-08 19:50:07 -04002340 if (args->version != 4) {
2341 dfprintk(MOUNT,
2342 "NFS4: Illegal mount version\n");
2343 return -EINVAL;
2344 }
2345
Chuck Lever7630c852009-09-08 19:49:57 -04002346 if (args->auth_flavor_len > 1) {
2347 dfprintk(MOUNT,
2348 "NFS4: Too many RPC auth flavours specified\n");
2349 return -EINVAL;
2350 }
2351
2352 if (args->client_address == NULL) {
2353 dfprintk(MOUNT,
2354 "NFS4: mount program didn't pass callback address\n");
2355 return -EINVAL;
2356 }
2357
2358 return nfs_parse_devname(dev_name,
2359 &args->nfs_server.hostname,
2360 NFS4_MAXNAMLEN,
2361 &args->nfs_server.export_path,
2362 NFS4_MAXPATHLEN);
2363}
2364
David Howells54ceac42006-08-22 20:06:13 -04002365/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002366 * Validate NFSv4 mount options
2367 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002368static int nfs4_validate_mount_data(void *options,
2369 struct nfs_parsed_mount_data *args,
2370 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002371{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002372 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002373 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002374 char *c;
2375
2376 if (data == NULL)
2377 goto out_no_data;
2378
2379 switch (data->version) {
2380 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002381 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002382 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002383 if (data->host_addrlen == 0)
2384 goto out_no_address;
2385 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002386 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002387 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002388 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002389 goto out_no_address;
2390
Chuck Lever6738b252008-06-24 16:33:54 -04002391 if (data->auth_flavourlen) {
2392 if (data->auth_flavourlen > 1)
2393 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002394 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002395 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002396 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002397 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002398 }
2399
2400 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2401 if (IS_ERR(c))
2402 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002403 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002404
2405 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2406 if (IS_ERR(c))
2407 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002408 args->nfs_server.export_path = c;
2409 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002410
2411 c = strndup_user(data->client_addr.data, 16);
2412 if (IS_ERR(c))
2413 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002414 args->client_address = c;
2415
2416 /*
2417 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2418 * can deal with.
2419 */
2420
2421 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2422 args->rsize = data->rsize;
2423 args->wsize = data->wsize;
2424 args->timeo = data->timeo;
2425 args->retrans = data->retrans;
2426 args->acregmin = data->acregmin;
2427 args->acregmax = data->acregmax;
2428 args->acdirmin = data->acdirmin;
2429 args->acdirmax = data->acdirmax;
2430 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002431 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002432
2433 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002434 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002435 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002436 return -EINVAL;
2437
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002438 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002439 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002440
Chuck Lever7630c852009-09-08 19:49:57 -04002441 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002442 }
2443
2444 return 0;
2445
2446out_no_data:
2447 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2448 return -EINVAL;
2449
2450out_inval_auth:
2451 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2452 data->auth_flavourlen);
2453 return -EINVAL;
2454
2455out_no_address:
2456 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2457 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002458}
2459
2460/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002461 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002462 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002463static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002464 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002465{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002466 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002467 struct super_block *s;
2468 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002469 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002470 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002471 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002472 struct nfs_sb_mountdata sb_mntdata = {
2473 .mntflags = flags,
2474 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002475 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002476
Trond Myklebust33852a12008-06-19 14:20:11 -04002477 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2478 if (data == NULL || mntfh == NULL)
2479 goto out_free_fh;
2480
2481 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002482
David Howells54ceac42006-08-22 20:06:13 -04002483 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002484 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002485 if (IS_ERR(server)) {
2486 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002487 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002488 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002489 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002490
Trond Myklebust75180df2007-05-16 16:53:28 -04002491 if (server->flags & NFS4_MOUNT_UNSHARED)
2492 compare_super = NULL;
2493
David Howells54ceac42006-08-22 20:06:13 -04002494 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002495 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002496 if (IS_ERR(s)) {
2497 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002498 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002499 }
2500
Trond Myklebust5dd31772006-08-24 01:03:05 -04002501 if (s->s_fs_info != server) {
2502 nfs_free_server(server);
2503 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002504 } else {
2505 error = nfs_bdi_register(server);
2506 if (error)
2507 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002508 }
2509
David Howells54ceac42006-08-22 20:06:13 -04002510 if (!s->s_root) {
2511 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002512 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002513 nfs_fscache_get_super_cookie(
2514 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002515 }
David Howellsf7b422b2006-06-09 09:34:33 -04002516
Trond Myklebust33852a12008-06-19 14:20:11 -04002517 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002518 if (IS_ERR(mntroot)) {
2519 error = PTR_ERR(mntroot);
2520 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002521 }
David Howells54ceac42006-08-22 20:06:13 -04002522
Trond Myklebust33852a12008-06-19 14:20:11 -04002523 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002524 if (error)
2525 goto error_splat_root;
2526
David Howellsf7b422b2006-06-09 09:34:33 -04002527 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002528 mnt->mnt_sb = s;
2529 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002530 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002531
Chuck Lever29eb9812007-07-01 12:12:30 -04002532out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002533 security_free_mnt_opts(&data->lsm_opts);
2534out_free_fh:
2535 kfree(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002536 return error;
David Howells54ceac42006-08-22 20:06:13 -04002537
Chuck Lever29eb9812007-07-01 12:12:30 -04002538out_free:
2539 nfs_free_server(server);
2540 goto out;
2541
Eric Paris46c8ac72008-05-02 13:42:42 -07002542error_splat_root:
2543 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002544error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002545 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002546 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002547}
2548
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002549static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2550 int flags, void *data, const char *hostname)
2551{
2552 struct vfsmount *root_mnt;
2553 char *root_devname;
2554 size_t len;
2555
2556 len = strlen(hostname) + 3;
2557 root_devname = kmalloc(len, GFP_KERNEL);
2558 if (root_devname == NULL)
2559 return ERR_PTR(-ENOMEM);
2560 snprintf(root_devname, len, "%s:/", hostname);
2561 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2562 kfree(root_devname);
2563 return root_mnt;
2564}
2565
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002566static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2567{
2568 char *page = (char *) __get_free_page(GFP_KERNEL);
2569 char *devname, *tmp;
2570
2571 if (page == NULL)
2572 return;
2573 devname = nfs_path(path->mnt->mnt_devname,
2574 path->mnt->mnt_root, path->dentry,
2575 page, PAGE_SIZE);
2576 if (devname == NULL)
2577 goto out_freepage;
2578 tmp = kstrdup(devname, GFP_KERNEL);
2579 if (tmp == NULL)
2580 goto out_freepage;
2581 kfree(mnt->mnt_devname);
2582 mnt->mnt_devname = tmp;
2583out_freepage:
2584 free_page((unsigned long)page);
2585}
2586
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002587static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2588 const char *export_path, struct vfsmount *mnt_target)
2589{
2590 struct mnt_namespace *ns_private;
2591 struct nameidata nd;
2592 struct super_block *s;
2593 int ret;
2594
2595 ns_private = create_mnt_ns(root_mnt);
2596 ret = PTR_ERR(ns_private);
2597 if (IS_ERR(ns_private))
2598 goto out_mntput;
2599
2600 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2601 export_path, LOOKUP_FOLLOW, &nd);
2602
2603 put_mnt_ns(ns_private);
2604
2605 if (ret != 0)
2606 goto out_err;
2607
2608 s = nd.path.mnt->mnt_sb;
2609 atomic_inc(&s->s_active);
2610 mnt_target->mnt_sb = s;
2611 mnt_target->mnt_root = dget(nd.path.dentry);
2612
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002613 /* Correct the device pathname */
2614 nfs_fix_devname(&nd.path, mnt_target);
2615
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002616 path_put(&nd.path);
2617 down_write(&s->s_umount);
2618 return 0;
2619out_mntput:
2620 mntput(root_mnt);
2621out_err:
2622 return ret;
2623}
2624
Chuck Levera6fe23b2009-09-08 19:50:00 -04002625static int nfs4_try_mount(int flags, const char *dev_name,
2626 struct nfs_parsed_mount_data *data,
2627 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002628{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002629 char *export_path;
2630 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002631 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002632
Chuck Levera6fe23b2009-09-08 19:50:00 -04002633 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002634
2635 export_path = data->nfs_server.export_path;
2636 data->nfs_server.export_path = "/";
2637 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2638 data->nfs_server.hostname);
2639 data->nfs_server.export_path = export_path;
2640
2641 error = PTR_ERR(root_mnt);
2642 if (IS_ERR(root_mnt))
2643 goto out;
2644
2645 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2646
2647out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002648 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2649 error != 0 ? " [error]" : "");
2650 return error;
2651}
2652
2653/*
2654 * Get the superblock for an NFS4 mountpoint
2655 */
2656static int nfs4_get_sb(struct file_system_type *fs_type,
2657 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2658{
2659 struct nfs_parsed_mount_data *data;
2660 int error = -ENOMEM;
2661
Trond Myklebustc5811db2009-10-06 15:40:15 -04002662 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002663 if (data == NULL)
2664 goto out_free_data;
2665
2666 /* Validate the mount data */
2667 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2668 if (error < 0)
2669 goto out;
2670
2671 error = nfs4_try_mount(flags, dev_name, data, mnt);
2672
2673out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002674 kfree(data->client_address);
2675 kfree(data->nfs_server.export_path);
2676 kfree(data->nfs_server.hostname);
2677 kfree(data->fscache_uniq);
2678out_free_data:
2679 kfree(data);
2680 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2681 error != 0 ? " [error]" : "");
2682 return error;
2683}
2684
David Howellsf7b422b2006-06-09 09:34:33 -04002685static void nfs4_kill_super(struct super_block *sb)
2686{
2687 struct nfs_server *server = NFS_SB(sb);
2688
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002689 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002690 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002691 kill_anon_super(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002692 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002693 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002694 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002695 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002696}
2697
2698/*
David Howells54ceac42006-08-22 20:06:13 -04002699 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002700 */
David Howells54ceac42006-08-22 20:06:13 -04002701static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2702 const char *dev_name, void *raw_data,
2703 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002704{
2705 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002706 struct super_block *s;
2707 struct nfs_server *server;
2708 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002709 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002710 struct nfs_sb_mountdata sb_mntdata = {
2711 .mntflags = flags,
2712 };
David Howells54ceac42006-08-22 20:06:13 -04002713 int error;
2714
2715 dprintk("--> nfs4_xdev_get_sb()\n");
2716
2717 /* create a new volume representation */
2718 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2719 if (IS_ERR(server)) {
2720 error = PTR_ERR(server);
2721 goto out_err_noserver;
2722 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002723 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002724
Trond Myklebust75180df2007-05-16 16:53:28 -04002725 if (server->flags & NFS4_MOUNT_UNSHARED)
2726 compare_super = NULL;
2727
David Howells54ceac42006-08-22 20:06:13 -04002728 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002729 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002730 if (IS_ERR(s)) {
2731 error = PTR_ERR(s);
2732 goto out_err_nosb;
2733 }
2734
2735 if (s->s_fs_info != server) {
2736 nfs_free_server(server);
2737 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002738 } else {
2739 error = nfs_bdi_register(server);
2740 if (error)
2741 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002742 }
2743
2744 if (!s->s_root) {
2745 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002746 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002747 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002748 }
2749
2750 mntroot = nfs4_get_root(s, data->fh);
2751 if (IS_ERR(mntroot)) {
2752 error = PTR_ERR(mntroot);
2753 goto error_splat_super;
2754 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002755 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2756 dput(mntroot);
2757 error = -ESTALE;
2758 goto error_splat_super;
2759 }
David Howells54ceac42006-08-22 20:06:13 -04002760
2761 s->s_flags |= MS_ACTIVE;
2762 mnt->mnt_sb = s;
2763 mnt->mnt_root = mntroot;
2764
Eric Paris46c8ac72008-05-02 13:42:42 -07002765 security_sb_clone_mnt_opts(data->sb, s);
2766
David Howells54ceac42006-08-22 20:06:13 -04002767 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2768 return 0;
2769
2770out_err_nosb:
2771 nfs_free_server(server);
2772out_err_noserver:
2773 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2774 return error;
2775
2776error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002777 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002778 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2779 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002780}
2781
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002782static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2783 int flags, const char *dev_name, void *raw_data,
2784 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002785{
2786 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002787 struct super_block *s;
2788 struct nfs_server *server;
2789 struct dentry *mntroot;
2790 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002791 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002792 struct nfs_sb_mountdata sb_mntdata = {
2793 .mntflags = flags,
2794 };
David Howells54ceac42006-08-22 20:06:13 -04002795 int error;
2796
2797 dprintk("--> nfs4_referral_get_sb()\n");
2798
2799 /* create a new volume representation */
2800 server = nfs4_create_referral_server(data, &mntfh);
2801 if (IS_ERR(server)) {
2802 error = PTR_ERR(server);
2803 goto out_err_noserver;
2804 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002805 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002806
Trond Myklebust75180df2007-05-16 16:53:28 -04002807 if (server->flags & NFS4_MOUNT_UNSHARED)
2808 compare_super = NULL;
2809
David Howells54ceac42006-08-22 20:06:13 -04002810 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002811 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002812 if (IS_ERR(s)) {
2813 error = PTR_ERR(s);
2814 goto out_err_nosb;
2815 }
2816
2817 if (s->s_fs_info != server) {
2818 nfs_free_server(server);
2819 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002820 } else {
2821 error = nfs_bdi_register(server);
2822 if (error)
2823 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002824 }
2825
2826 if (!s->s_root) {
2827 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002828 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002829 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002830 }
2831
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002832 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002833 if (IS_ERR(mntroot)) {
2834 error = PTR_ERR(mntroot);
2835 goto error_splat_super;
2836 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002837 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2838 dput(mntroot);
2839 error = -ESTALE;
2840 goto error_splat_super;
2841 }
David Howells54ceac42006-08-22 20:06:13 -04002842
2843 s->s_flags |= MS_ACTIVE;
2844 mnt->mnt_sb = s;
2845 mnt->mnt_root = mntroot;
2846
Eric Paris46c8ac72008-05-02 13:42:42 -07002847 security_sb_clone_mnt_opts(data->sb, s);
2848
David Howells54ceac42006-08-22 20:06:13 -04002849 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2850 return 0;
2851
2852out_err_nosb:
2853 nfs_free_server(server);
2854out_err_noserver:
2855 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2856 return error;
2857
2858error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002859 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002860 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2861 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002862}
2863
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002864/*
2865 * Create an NFS4 server record on referral traversal
2866 */
2867static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2868 int flags, const char *dev_name, void *raw_data,
2869 struct vfsmount *mnt)
2870{
2871 struct nfs_clone_mount *data = raw_data;
2872 char *export_path;
2873 struct vfsmount *root_mnt;
2874 int error;
2875
2876 dprintk("--> nfs4_referral_get_sb()\n");
2877
2878 export_path = data->mnt_path;
2879 data->mnt_path = "/";
2880
2881 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2882 flags, data, data->hostname);
2883 data->mnt_path = export_path;
2884
2885 error = PTR_ERR(root_mnt);
2886 if (IS_ERR(root_mnt))
2887 goto out;
2888
2889 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2890out:
2891 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2892 error != 0 ? " [error]" : "");
2893 return error;
2894}
2895
David Howells54ceac42006-08-22 20:06:13 -04002896#endif /* CONFIG_NFS_V4 */