blob: 867f705045313217c2bcbf40d3a78ad82cbeccb9 [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 Myklebust7973c1f12008-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 Myklebust7973c1f12008-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 Myklebust7973c1f12008-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
731/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500732 * Sanity-check a server address provided by the mount command.
733 *
734 * Address family must be initialized, and address must not be
735 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400736 */
737static int nfs_verify_server_address(struct sockaddr *addr)
738{
739 switch (addr->sa_family) {
740 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500741 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700742 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500743 }
744 case AF_INET6: {
745 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
746 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400747 }
748 }
749
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400750 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400751 return 0;
752}
753
Chuck Lever9412b922007-12-10 14:59:21 -0500754/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400755 * Select between a default port value and a user-specified port value.
756 * If a zero value is set, then autobind will be used.
757 */
758static void nfs_set_default_port(struct sockaddr *sap, const int parsed_port,
759 const unsigned short default_port)
760{
761 unsigned short port = default_port;
762
763 if (parsed_port != NFS_UNSPEC_PORT)
764 port = parsed_port;
765
766 rpc_set_port(sap, port);
767}
768
769/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400770 * Sanity check the NFS transport protocol.
771 *
772 */
773static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
774{
775 switch (mnt->nfs_server.protocol) {
776 case XPRT_TRANSPORT_UDP:
777 case XPRT_TRANSPORT_TCP:
778 case XPRT_TRANSPORT_RDMA:
779 break;
780 default:
781 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
782 }
783}
784
785/*
786 * For text based NFSv2/v3 mounts, the mount protocol transport default
787 * settings should depend upon the specified NFS transport.
788 */
789static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
790{
791 nfs_validate_transport_protocol(mnt);
792
793 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
794 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
795 return;
796 switch (mnt->nfs_server.protocol) {
797 case XPRT_TRANSPORT_UDP:
798 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
799 break;
800 case XPRT_TRANSPORT_TCP:
801 case XPRT_TRANSPORT_RDMA:
802 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
803 }
804}
805
806/*
Chuck Lever01060c82008-06-24 16:33:38 -0400807 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400808 */
809static int nfs_parse_security_flavors(char *value,
810 struct nfs_parsed_mount_data *mnt)
811{
812 substring_t args[MAX_OPT_ARGS];
813
814 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
815
816 switch (match_token(value, nfs_secflavor_tokens, args)) {
817 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400818 mnt->auth_flavors[0] = RPC_AUTH_NULL;
819 break;
820 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400821 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
822 break;
823 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400824 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
825 break;
826 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400827 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
828 break;
829 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400830 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
831 break;
832 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400833 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
834 break;
835 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400836 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
837 break;
838 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400839 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
840 break;
841 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400842 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
843 break;
844 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400845 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
846 break;
847 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400848 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
849 break;
850 default:
851 return 0;
852 }
853
Chuck Lever059f90b2009-08-09 15:09:31 -0400854 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400855 return 1;
856}
857
858/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400859 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400860 * a data structure. The whole mount string is processed; bad options are
861 * skipped as they are encountered. If there were no errors, return 1;
862 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400863 */
864static int nfs_parse_mount_options(char *raw,
865 struct nfs_parsed_mount_data *mnt)
866{
Eric Parisf9c3a382008-03-05 14:20:18 -0500867 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700868 int rc, sloppy = 0, invalid_option = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400869
870 if (!raw) {
871 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
872 return 1;
873 }
874 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
875
Eric Parisf9c3a382008-03-05 14:20:18 -0500876 secdata = alloc_secdata();
877 if (!secdata)
878 goto out_nomem;
879
880 rc = security_sb_copy_data(raw, secdata);
881 if (rc)
882 goto out_security_failure;
883
884 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
885 if (rc)
886 goto out_security_failure;
887
888 free_secdata(secdata);
889
Chuck Leverbf0fd762007-07-01 12:13:44 -0400890 while ((p = strsep(&raw, ",")) != NULL) {
891 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700892 unsigned long option;
893 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400894
895 if (!*p)
896 continue;
897
898 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
899
900 token = match_token(p, nfs_mount_option_tokens, args);
901 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400902
903 /*
904 * boolean options: foo/nofoo
905 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400906 case Opt_soft:
907 mnt->flags |= NFS_MOUNT_SOFT;
908 break;
909 case Opt_hard:
910 mnt->flags &= ~NFS_MOUNT_SOFT;
911 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400912 case Opt_posix:
913 mnt->flags |= NFS_MOUNT_POSIX;
914 break;
915 case Opt_noposix:
916 mnt->flags &= ~NFS_MOUNT_POSIX;
917 break;
918 case Opt_cto:
919 mnt->flags &= ~NFS_MOUNT_NOCTO;
920 break;
921 case Opt_nocto:
922 mnt->flags |= NFS_MOUNT_NOCTO;
923 break;
924 case Opt_ac:
925 mnt->flags &= ~NFS_MOUNT_NOAC;
926 break;
927 case Opt_noac:
928 mnt->flags |= NFS_MOUNT_NOAC;
929 break;
930 case Opt_lock:
931 mnt->flags &= ~NFS_MOUNT_NONLM;
932 break;
933 case Opt_nolock:
934 mnt->flags |= NFS_MOUNT_NONLM;
935 break;
936 case Opt_v2:
937 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400938 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400939 break;
940 case Opt_v3:
941 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400942 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400943 break;
Chuck Lever764302c2009-09-08 19:50:03 -0400944#ifdef CONFIG_NFS_V4
945 case Opt_v4:
946 mnt->flags &= ~NFS_MOUNT_VER3;
947 mnt->version = 4;
948 break;
949#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950 case Opt_udp:
951 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400952 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400953 break;
954 case Opt_tcp:
955 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400956 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400957 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400958 case Opt_rdma:
959 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
960 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -0400961 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400962 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400963 case Opt_acl:
964 mnt->flags &= ~NFS_MOUNT_NOACL;
965 break;
966 case Opt_noacl:
967 mnt->flags |= NFS_MOUNT_NOACL;
968 break;
969 case Opt_rdirplus:
970 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
971 break;
972 case Opt_nordirplus:
973 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
974 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400975 case Opt_sharecache:
976 mnt->flags &= ~NFS_MOUNT_UNSHARED;
977 break;
978 case Opt_nosharecache:
979 mnt->flags |= NFS_MOUNT_UNSHARED;
980 break;
Chuck Leverd7403512008-12-23 15:21:37 -0500981 case Opt_resvport:
982 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
983 break;
984 case Opt_noresvport:
985 mnt->flags |= NFS_MOUNT_NORESVPORT;
986 break;
David Howellsb797cac2009-04-03 16:42:48 +0100987 case Opt_fscache:
988 mnt->options |= NFS_OPTION_FSCACHE;
989 kfree(mnt->fscache_uniq);
990 mnt->fscache_uniq = NULL;
991 break;
992 case Opt_nofscache:
993 mnt->options &= ~NFS_OPTION_FSCACHE;
994 kfree(mnt->fscache_uniq);
995 mnt->fscache_uniq = NULL;
996 break;
997 case Opt_fscache_uniq:
998 string = match_strdup(args);
999 if (!string)
1000 goto out_nomem;
1001 kfree(mnt->fscache_uniq);
1002 mnt->fscache_uniq = string;
1003 mnt->options |= NFS_OPTION_FSCACHE;
1004 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001005
Chuck Leverf45663c2008-06-24 19:28:02 -04001006 /*
1007 * options that take numeric values
1008 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001009 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001010 string = match_strdup(args);
1011 if (string == NULL)
1012 goto out_nomem;
1013 rc = strict_strtoul(string, 10, &option);
1014 kfree(string);
1015 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001016 goto out_invalid_value;
1017 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001018 break;
1019 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001020 string = match_strdup(args);
1021 if (string == NULL)
1022 goto out_nomem;
1023 rc = strict_strtoul(string, 10, &option);
1024 kfree(string);
1025 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001026 goto out_invalid_value;
1027 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001028 break;
1029 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001030 string = match_strdup(args);
1031 if (string == NULL)
1032 goto out_nomem;
1033 rc = strict_strtoul(string, 10, &option);
1034 kfree(string);
1035 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001036 goto out_invalid_value;
1037 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001038 break;
1039 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001040 string = match_strdup(args);
1041 if (string == NULL)
1042 goto out_nomem;
1043 rc = strict_strtoul(string, 10, &option);
1044 kfree(string);
1045 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001046 goto out_invalid_value;
1047 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001048 break;
1049 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001050 string = match_strdup(args);
1051 if (string == NULL)
1052 goto out_nomem;
1053 rc = strict_strtoul(string, 10, &option);
1054 kfree(string);
1055 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001056 goto out_invalid_value;
1057 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001058 break;
1059 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001060 string = match_strdup(args);
1061 if (string == NULL)
1062 goto out_nomem;
1063 rc = strict_strtoul(string, 10, &option);
1064 kfree(string);
1065 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001066 goto out_invalid_value;
1067 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001068 break;
1069 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001070 string = match_strdup(args);
1071 if (string == NULL)
1072 goto out_nomem;
1073 rc = strict_strtoul(string, 10, &option);
1074 kfree(string);
1075 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001076 goto out_invalid_value;
1077 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001078 break;
1079 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001080 string = match_strdup(args);
1081 if (string == NULL)
1082 goto out_nomem;
1083 rc = strict_strtoul(string, 10, &option);
1084 kfree(string);
1085 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001086 goto out_invalid_value;
1087 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001088 break;
1089 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001090 string = match_strdup(args);
1091 if (string == NULL)
1092 goto out_nomem;
1093 rc = strict_strtoul(string, 10, &option);
1094 kfree(string);
1095 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001096 goto out_invalid_value;
1097 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001098 break;
1099 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001100 string = match_strdup(args);
1101 if (string == NULL)
1102 goto out_nomem;
1103 rc = strict_strtoul(string, 10, &option);
1104 kfree(string);
1105 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001106 goto out_invalid_value;
1107 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001108 break;
1109 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001110 string = match_strdup(args);
1111 if (string == NULL)
1112 goto out_nomem;
1113 rc = strict_strtoul(string, 10, &option);
1114 kfree(string);
1115 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001116 goto out_invalid_value;
1117 mnt->acregmin = mnt->acregmax =
1118 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001119 break;
1120 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001121 string = match_strdup(args);
1122 if (string == NULL)
1123 goto out_nomem;
1124 rc = strict_strtoul(string, 10, &option);
1125 kfree(string);
1126 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001127 goto out_invalid_value;
1128 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001129 break;
1130 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001131 string = match_strdup(args);
1132 if (string == NULL)
1133 goto out_nomem;
1134 rc = strict_strtoul(string, 10, &option);
1135 kfree(string);
1136 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001137 goto out_invalid_value;
1138 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001139 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001140 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001141 string = match_strdup(args);
1142 if (string == NULL)
1143 goto out_nomem;
1144 rc = strict_strtoul(string, 10, &option);
1145 kfree(string);
1146 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001147 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001148 option > NFS_MNT3_VERSION)
1149 goto out_invalid_value;
1150 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001151 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001152 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001153 string = match_strdup(args);
1154 if (string == NULL)
1155 goto out_nomem;
1156 rc = strict_strtoul(string, 10, &option);
1157 kfree(string);
1158 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001159 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001161 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001162 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001163 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001164 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001165 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001167 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001168 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001169#ifdef CONFIG_NFS_V4
1170 case NFS4_VERSION:
1171 mnt->flags &= ~NFS_MOUNT_VER3;
1172 mnt->version = 4;
1173 break;
1174#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001176 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 }
1178 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001179 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001180 string = match_strdup(args);
1181 if (string == NULL)
1182 goto out_nomem;
1183 rc = strict_strtoul(string, 10, &option);
1184 kfree(string);
1185 if (rc != 0)
1186 goto out_invalid_value;
1187 if (option > NFS4_MAX_MINOR_VERSION)
1188 goto out_invalid_value;
1189 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001190 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001191
Chuck Leverf45663c2008-06-24 19:28:02 -04001192 /*
1193 * options that take text values
1194 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001195 case Opt_sec:
1196 string = match_strdup(args);
1197 if (string == NULL)
1198 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001199 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001201 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001202 dfprintk(MOUNT, "NFS: unrecognized "
1203 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001204 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001205 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 break;
1207 case Opt_proto:
1208 string = match_strdup(args);
1209 if (string == NULL)
1210 goto out_nomem;
1211 token = match_token(string,
1212 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001213
1214 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001215 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001217 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001218 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001220 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001221 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001222 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001223 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001224 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001225 case Opt_xprt_rdma:
1226 /* vector side protocols to TCP */
1227 mnt->flags |= NFS_MOUNT_TCP;
1228 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001229 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001230 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001231 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001233 dfprintk(MOUNT, "NFS: unrecognized "
1234 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001235 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236 }
1237 break;
1238 case Opt_mountproto:
1239 string = match_strdup(args);
1240 if (string == NULL)
1241 goto out_nomem;
1242 token = match_token(string,
1243 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001244 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001245
1246 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001247 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001248 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001249 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001250 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001251 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001253 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001255 dfprintk(MOUNT, "NFS: unrecognized "
1256 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001257 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258 }
1259 break;
1260 case Opt_addr:
1261 string = match_strdup(args);
1262 if (string == NULL)
1263 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001264 mnt->nfs_server.addrlen =
1265 rpc_pton(string, strlen(string),
1266 (struct sockaddr *)
1267 &mnt->nfs_server.address,
1268 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001269 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001270 if (mnt->nfs_server.addrlen == 0)
1271 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001272 break;
1273 case Opt_clientaddr:
1274 string = match_strdup(args);
1275 if (string == NULL)
1276 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001277 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001278 mnt->client_address = string;
1279 break;
Chuck Lever33832032007-12-10 14:59:13 -05001280 case Opt_mounthost:
1281 string = match_strdup(args);
1282 if (string == NULL)
1283 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001284 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001285 mnt->mount_server.hostname = string;
1286 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001287 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288 string = match_strdup(args);
1289 if (string == NULL)
1290 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001291 mnt->mount_server.addrlen =
1292 rpc_pton(string, strlen(string),
1293 (struct sockaddr *)
1294 &mnt->mount_server.address,
1295 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001297 if (mnt->mount_server.addrlen == 0)
1298 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299 break;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001300 case Opt_lookupcache:
1301 string = match_strdup(args);
1302 if (string == NULL)
1303 goto out_nomem;
1304 token = match_token(string,
1305 nfs_lookupcache_tokens, args);
1306 kfree(string);
1307 switch (token) {
1308 case Opt_lookupcache_all:
1309 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1310 break;
1311 case Opt_lookupcache_positive:
1312 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1313 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1314 break;
1315 case Opt_lookupcache_none:
1316 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1317 break;
1318 default:
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001319 dfprintk(MOUNT, "NFS: invalid "
1320 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001321 return 0;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001322 };
1323 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324
Chuck Leverf45663c2008-06-24 19:28:02 -04001325 /*
1326 * Special options
1327 */
1328 case Opt_sloppy:
1329 sloppy = 1;
1330 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1331 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332 case Opt_userspace:
1333 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001334 dfprintk(MOUNT, "NFS: ignoring mount option "
1335 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001336 break;
1337
1338 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001339 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001340 dfprintk(MOUNT, "NFS: unrecognized mount option "
1341 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 }
1343 }
1344
Chuck Leverd23c45f2009-06-17 18:02:13 -07001345 if (!sloppy && invalid_option)
1346 return 0;
1347
Chuck Leverbf0fd762007-07-01 12:13:44 -04001348 return 1;
1349
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001350out_invalid_address:
1351 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1352 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001353out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001354 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001355 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001356out_nomem:
1357 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1358 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001359out_security_failure:
1360 free_secdata(secdata);
1361 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1362 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001363}
1364
1365/*
Chuck Leverec88f282009-08-09 15:09:32 -04001366 * Match the requested auth flavors with the list returned by
1367 * the server. Returns zero and sets the mount's authentication
1368 * flavor on success; returns -EACCES if server does not support
1369 * the requested flavor.
1370 */
1371static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1372 struct nfs_mount_request *request)
1373{
1374 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1375
1376 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001377 * Certain releases of Linux's mountd return an empty
1378 * flavor list. To prevent behavioral regression with
1379 * these servers (ie. rejecting mounts that used to
1380 * succeed), revert to pre-2.6.32 behavior (no checking)
1381 * if the returned flavor list is empty.
1382 */
1383 if (server_authlist_len == 0)
1384 return 0;
1385
1386 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001387 * We avoid sophisticated negotiating here, as there are
1388 * plenty of cases where we can get it wrong, providing
1389 * either too little or too much security.
1390 *
1391 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1392 * flavor listed first. However, some servers list
1393 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1394 * preferred default, in args->auth_flavors[0] if user
1395 * didn't specify sec= mount option.
1396 */
1397 for (i = 0; i < args->auth_flavor_len; i++)
1398 for (j = 0; j < server_authlist_len; j++)
1399 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1400 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1401 request->auth_flavs[j]);
1402 args->auth_flavors[0] = request->auth_flavs[j];
1403 return 0;
1404 }
1405
1406 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1407 nfs_umount(request);
1408 return -EACCES;
1409}
1410
1411/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001412 * Use the remote server's MOUNT service to request the NFS file handle
1413 * corresponding to the provided path.
1414 */
1415static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1416 struct nfs_fh *root_fh)
1417{
Chuck Leverec88f282009-08-09 15:09:32 -04001418 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1419 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001420 struct nfs_mount_request request = {
1421 .sap = (struct sockaddr *)
1422 &args->mount_server.address,
1423 .dirpath = args->nfs_server.export_path,
1424 .protocol = args->mount_server.protocol,
1425 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001426 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001427 .auth_flav_len = &server_authlist_len,
1428 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001429 };
Chuck Lever4c568012007-12-10 14:59:28 -05001430 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001431
1432 if (args->mount_server.version == 0) {
1433 if (args->flags & NFS_MOUNT_VER3)
1434 args->mount_server.version = NFS_MNT3_VERSION;
1435 else
1436 args->mount_server.version = NFS_MNT_VERSION;
1437 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001438 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001439
Chuck Lever33832032007-12-10 14:59:13 -05001440 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001441 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001442 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001443 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001444
Chuck Lever0076d7b2007-07-01 12:13:49 -04001445 /*
1446 * Construct the mount server's address.
1447 */
Chuck Lever4c568012007-12-10 14:59:28 -05001448 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001449 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001450 args->nfs_server.addrlen);
1451 args->mount_server.addrlen = args->nfs_server.addrlen;
1452 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001453 request.salen = args->mount_server.addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001454 nfs_set_default_port(request.sap, args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001455
1456 /*
1457 * Now ask the mount server to map our export path
1458 * to a file handle.
1459 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001460 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001461 if (status != 0) {
1462 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1463 request.hostname, status);
1464 return status;
1465 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001466
Chuck Leverec88f282009-08-09 15:09:32 -04001467 /*
1468 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1469 */
1470 if (args->mount_server.version != NFS_MNT3_VERSION)
1471 return 0;
1472 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001473}
1474
Chuck Leverd1aa0822008-06-23 12:36:45 -04001475static int nfs_parse_simple_hostname(const char *dev_name,
1476 char **hostname, size_t maxnamlen,
1477 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001478{
1479 size_t len;
1480 char *colon, *comma;
1481
1482 colon = strchr(dev_name, ':');
1483 if (colon == NULL)
1484 goto out_bad_devname;
1485
1486 len = colon - dev_name;
1487 if (len > maxnamlen)
1488 goto out_hostname;
1489
1490 /* N.B. caller will free nfs_server.hostname in all cases */
1491 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1492 if (!*hostname)
1493 goto out_nomem;
1494
1495 /* kill possible hostname list: not supported */
1496 comma = strchr(*hostname, ',');
1497 if (comma != NULL) {
1498 if (comma == *hostname)
1499 goto out_bad_devname;
1500 *comma = '\0';
1501 }
1502
1503 colon++;
1504 len = strlen(colon);
1505 if (len > maxpathlen)
1506 goto out_path;
1507 *export_path = kstrndup(colon, len, GFP_KERNEL);
1508 if (!*export_path)
1509 goto out_nomem;
1510
1511 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1512 return 0;
1513
1514out_bad_devname:
1515 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1516 return -EINVAL;
1517
1518out_nomem:
1519 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1520 return -ENOMEM;
1521
1522out_hostname:
1523 dfprintk(MOUNT, "NFS: server hostname too long\n");
1524 return -ENAMETOOLONG;
1525
1526out_path:
1527 dfprintk(MOUNT, "NFS: export pathname too long\n");
1528 return -ENAMETOOLONG;
1529}
1530
1531/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001532 * Hostname has square brackets around it because it contains one or
1533 * more colons. We look for the first closing square bracket, and a
1534 * colon must follow it.
1535 */
1536static int nfs_parse_protected_hostname(const char *dev_name,
1537 char **hostname, size_t maxnamlen,
1538 char **export_path, size_t maxpathlen)
1539{
1540 size_t len;
1541 char *start, *end;
1542
1543 start = (char *)(dev_name + 1);
1544
1545 end = strchr(start, ']');
1546 if (end == NULL)
1547 goto out_bad_devname;
1548 if (*(end + 1) != ':')
1549 goto out_bad_devname;
1550
1551 len = end - start;
1552 if (len > maxnamlen)
1553 goto out_hostname;
1554
1555 /* N.B. caller will free nfs_server.hostname in all cases */
1556 *hostname = kstrndup(start, len, GFP_KERNEL);
1557 if (*hostname == NULL)
1558 goto out_nomem;
1559
1560 end += 2;
1561 len = strlen(end);
1562 if (len > maxpathlen)
1563 goto out_path;
1564 *export_path = kstrndup(end, len, GFP_KERNEL);
1565 if (!*export_path)
1566 goto out_nomem;
1567
1568 return 0;
1569
1570out_bad_devname:
1571 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1572 return -EINVAL;
1573
1574out_nomem:
1575 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1576 return -ENOMEM;
1577
1578out_hostname:
1579 dfprintk(MOUNT, "NFS: server hostname too long\n");
1580 return -ENAMETOOLONG;
1581
1582out_path:
1583 dfprintk(MOUNT, "NFS: export pathname too long\n");
1584 return -ENAMETOOLONG;
1585}
1586
1587/*
1588 * Split "dev_name" into "hostname:export_path".
1589 *
1590 * The leftmost colon demarks the split between the server's hostname
1591 * and the export path. If the hostname starts with a left square
1592 * bracket, then it may contain colons.
1593 *
1594 * Note: caller frees hostname and export path, even on error.
1595 */
1596static int nfs_parse_devname(const char *dev_name,
1597 char **hostname, size_t maxnamlen,
1598 char **export_path, size_t maxpathlen)
1599{
1600 if (*dev_name == '[')
1601 return nfs_parse_protected_hostname(dev_name,
1602 hostname, maxnamlen,
1603 export_path, maxpathlen);
1604
1605 return nfs_parse_simple_hostname(dev_name,
1606 hostname, maxnamlen,
1607 export_path, maxpathlen);
1608}
1609
1610/*
David Howells54ceac42006-08-22 20:06:13 -04001611 * Validate the NFS2/NFS3 mount data
1612 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001613 *
1614 * For option strings, user space handles the following behaviors:
1615 *
1616 * + DNS: mapping server host name to IP address ("addr=" option)
1617 *
1618 * + failure mode: how to behave if a mount request can't be handled
1619 * immediately ("fg/bg" option)
1620 *
1621 * + retry: how often to retry a mount request ("retry=" option)
1622 *
1623 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1624 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001625 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001626static int nfs_validate_mount_data(void *options,
1627 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001628 struct nfs_fh *mntfh,
1629 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001630{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001631 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001632 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001633
Chuck Lever5df36e72007-07-01 12:12:56 -04001634 if (data == NULL)
1635 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001636
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001637 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1638 args->rsize = NFS_MAX_FILE_IO_SIZE;
1639 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001640 args->acregmin = NFS_DEF_ACREGMIN;
1641 args->acregmax = NFS_DEF_ACREGMAX;
1642 args->acdirmin = NFS_DEF_ACDIRMIN;
1643 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001644 args->mount_server.port = NFS_UNSPEC_PORT;
1645 args->nfs_server.port = NFS_UNSPEC_PORT;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001646 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001647 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04001648 args->auth_flavor_len = 1;
Chuck Lever764302c2009-09-08 19:50:03 -04001649 args->minorversion = 0;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001650
David Howellsf7b422b2006-06-09 09:34:33 -04001651 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001652 case 1:
1653 data->namlen = 0;
1654 case 2:
1655 data->bsize = 0;
1656 case 3:
1657 if (data->flags & NFS_MOUNT_VER3)
1658 goto out_no_v3;
1659 data->root.size = NFS2_FHSIZE;
1660 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1661 case 4:
1662 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1663 goto out_no_sec;
1664 case 5:
1665 memset(data->context, 0, sizeof(data->context));
1666 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001667 if (data->flags & NFS_MOUNT_VER3) {
1668 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1669 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001670 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001671 args->version = 3;
1672 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001673 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001674 args->version = 2;
1675 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001676
Chuck Lever5df36e72007-07-01 12:12:56 -04001677
1678 memcpy(mntfh->data, data->root.data, mntfh->size);
1679 if (mntfh->size < sizeof(mntfh->data))
1680 memset(mntfh->data + mntfh->size, 0,
1681 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001682
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001683 /*
1684 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1685 * can deal with.
1686 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001687 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001688 args->rsize = data->rsize;
1689 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001690 args->timeo = data->timeo;
1691 args->retrans = data->retrans;
1692 args->acregmin = data->acregmin;
1693 args->acregmax = data->acregmax;
1694 args->acdirmin = data->acdirmin;
1695 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001696
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001697 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001698 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001699 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001700 goto out_no_address;
1701
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001702 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001703 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001704 /* N.B. caller will free nfs_server.hostname in all cases */
1705 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1706 args->namlen = data->namlen;
1707 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001708
1709 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1710 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001711 if (!args->nfs_server.hostname)
1712 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001713
1714 /*
1715 * The legacy version 6 binary mount data from userspace has a
1716 * field used only to transport selinux information into the
1717 * the kernel. To continue to support that functionality we
1718 * have a touch of selinux knowledge here in the NFS code. The
1719 * userspace code converted context=blah to just blah so we are
1720 * converting back to the full string selinux understands.
1721 */
1722 if (data->context[0]){
1723#ifdef CONFIG_SECURITY_SELINUX
1724 int rc;
1725 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1726 if (!opts_str)
1727 return -ENOMEM;
1728 strcpy(opts_str, "context=");
1729 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1730 strcat(opts_str, &data->context[0]);
1731 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1732 kfree(opts_str);
1733 if (rc)
1734 return rc;
1735#else
1736 return -EINVAL;
1737#endif
1738 }
1739
Chuck Lever5df36e72007-07-01 12:12:56 -04001740 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001741 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001742 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001743
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001744 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001745 return -EINVAL;
1746
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001747 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001748 goto out_no_address;
1749
Chuck Lever764302c2009-09-08 19:50:03 -04001750 if (args->version == 4)
1751#ifdef CONFIG_NFS_V4
1752 return nfs4_validate_text_mount_data(options,
1753 args, dev_name);
1754#else
1755 goto out_v4_not_compiled;
1756#endif
1757
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001758 nfs_set_default_port(sap, args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001759
Trond Myklebust259875e2008-07-02 14:43:47 -04001760 nfs_set_mount_transport_protocol(args);
1761
Chuck Leverdc045892008-06-23 12:36:37 -04001762 status = nfs_parse_devname(dev_name,
1763 &args->nfs_server.hostname,
1764 PAGE_SIZE,
1765 &args->nfs_server.export_path,
1766 NFS_MAXPATHLEN);
1767 if (!status)
1768 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001769
Chuck Leverdc045892008-06-23 12:36:37 -04001770 kfree(args->nfs_server.export_path);
1771 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001772
Chuck Lever136d5582007-07-01 12:13:54 -04001773 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001774 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001775
Chuck Lever136d5582007-07-01 12:13:54 -04001776 break;
1777 }
David Howellsf7b422b2006-06-09 09:34:33 -04001778 }
David Howells54ceac42006-08-22 20:06:13 -04001779
David Howellsf7b422b2006-06-09 09:34:33 -04001780#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001781 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001782 goto out_v3_not_compiled;
1783#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001784
David Howells54ceac42006-08-22 20:06:13 -04001785 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001786
1787out_no_data:
1788 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1789 return -EINVAL;
1790
1791out_no_v3:
1792 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1793 data->version);
1794 return -EINVAL;
1795
1796out_no_sec:
1797 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1798 return -EINVAL;
1799
Chuck Lever5df36e72007-07-01 12:12:56 -04001800#ifndef CONFIG_NFS_V3
1801out_v3_not_compiled:
1802 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1803 return -EPROTONOSUPPORT;
1804#endif /* !CONFIG_NFS_V3 */
1805
Chuck Lever764302c2009-09-08 19:50:03 -04001806#ifndef CONFIG_NFS_V4
1807out_v4_not_compiled:
1808 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1809 return -EPROTONOSUPPORT;
1810#endif /* !CONFIG_NFS_V4 */
1811
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001812out_nomem:
1813 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1814 return -ENOMEM;
1815
Chuck Lever5df36e72007-07-01 12:12:56 -04001816out_no_address:
1817 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1818 return -EINVAL;
1819
1820out_invalid_fh:
1821 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1822 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001823}
1824
Jeff Layton48b605f2008-06-10 15:38:39 -04001825static int
1826nfs_compare_remount_data(struct nfs_server *nfss,
1827 struct nfs_parsed_mount_data *data)
1828{
1829 if (data->flags != nfss->flags ||
1830 data->rsize != nfss->rsize ||
1831 data->wsize != nfss->wsize ||
1832 data->retrans != nfss->client->cl_timeout->to_retries ||
1833 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1834 data->acregmin != nfss->acregmin / HZ ||
1835 data->acregmax != nfss->acregmax / HZ ||
1836 data->acdirmin != nfss->acdirmin / HZ ||
1837 data->acdirmax != nfss->acdirmax / HZ ||
1838 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1839 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1840 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1841 data->nfs_server.addrlen) != 0)
1842 return -EINVAL;
1843
1844 return 0;
1845}
1846
1847static int
1848nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1849{
1850 int error;
1851 struct nfs_server *nfss = sb->s_fs_info;
1852 struct nfs_parsed_mount_data *data;
1853 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1854 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001855 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001856
1857 /*
1858 * Userspace mount programs that send binary options generally send
1859 * them populated with default values. We have no way to know which
1860 * ones were explicitly specified. Fall back to legacy behavior and
1861 * just return success.
1862 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001863 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1864 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1865 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001866 return 0;
1867
1868 data = kzalloc(sizeof(*data), GFP_KERNEL);
1869 if (data == NULL)
1870 return -ENOMEM;
1871
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001872 lock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001873 /* fill out struct with values from existing mount */
1874 data->flags = nfss->flags;
1875 data->rsize = nfss->rsize;
1876 data->wsize = nfss->wsize;
1877 data->retrans = nfss->client->cl_timeout->to_retries;
1878 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1879 data->acregmin = nfss->acregmin / HZ;
1880 data->acregmax = nfss->acregmax / HZ;
1881 data->acdirmin = nfss->acdirmin / HZ;
1882 data->acdirmax = nfss->acdirmax / HZ;
1883 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1884 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1885 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1886 data->nfs_server.addrlen);
1887
1888 /* overwrite those values with any that were specified */
1889 error = nfs_parse_mount_options((char *)options, data);
1890 if (error < 0)
1891 goto out;
1892
1893 /* compare new mount options with old ones */
1894 error = nfs_compare_remount_data(nfss, data);
1895out:
1896 kfree(data);
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001897 unlock_kernel();
Jeff Layton48b605f2008-06-10 15:38:39 -04001898 return error;
1899}
1900
David Howells54ceac42006-08-22 20:06:13 -04001901/*
1902 * Initialise the common bits of the superblock
1903 */
1904static inline void nfs_initialise_sb(struct super_block *sb)
1905{
1906 struct nfs_server *server = NFS_SB(sb);
1907
1908 sb->s_magic = NFS_SUPER_MAGIC;
1909
1910 /* We probably want something more informative here */
1911 snprintf(sb->s_id, sizeof(sb->s_id),
1912 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1913
1914 if (sb->s_blocksize == 0)
1915 sb->s_blocksize = nfs_block_bits(server->wsize,
1916 &sb->s_blocksize_bits);
1917
1918 if (server->flags & NFS_MOUNT_NOAC)
1919 sb->s_flags |= MS_SYNCHRONOUS;
1920
1921 nfs_super_set_maxbytes(sb, server->maxfilesize);
1922}
1923
1924/*
1925 * Finish setting up an NFS2/3 superblock
1926 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001927static void nfs_fill_super(struct super_block *sb,
1928 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001929{
1930 struct nfs_server *server = NFS_SB(sb);
1931
1932 sb->s_blocksize_bits = 0;
1933 sb->s_blocksize = 0;
1934 if (data->bsize)
1935 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1936
1937 if (server->flags & NFS_MOUNT_VER3) {
1938 /* The VFS shouldn't apply the umask to mode bits. We will do
1939 * so ourselves when necessary.
1940 */
1941 sb->s_flags |= MS_POSIXACL;
1942 sb->s_time_gran = 1;
1943 }
1944
1945 sb->s_op = &nfs_sops;
1946 nfs_initialise_sb(sb);
1947}
1948
1949/*
1950 * Finish setting up a cloned NFS2/3 superblock
1951 */
1952static void nfs_clone_super(struct super_block *sb,
1953 const struct super_block *old_sb)
1954{
1955 struct nfs_server *server = NFS_SB(sb);
1956
1957 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1958 sb->s_blocksize = old_sb->s_blocksize;
1959 sb->s_maxbytes = old_sb->s_maxbytes;
1960
1961 if (server->flags & NFS_MOUNT_VER3) {
1962 /* The VFS shouldn't apply the umask to mode bits. We will do
1963 * so ourselves when necessary.
1964 */
1965 sb->s_flags |= MS_POSIXACL;
1966 sb->s_time_gran = 1;
1967 }
1968
1969 sb->s_op = old_sb->s_op;
1970 nfs_initialise_sb(sb);
1971}
1972
Trond Myklebust275a5d22007-05-16 16:53:28 -04001973static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1974{
1975 const struct nfs_server *a = s->s_fs_info;
1976 const struct rpc_clnt *clnt_a = a->client;
1977 const struct rpc_clnt *clnt_b = b->client;
1978
1979 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1980 goto Ebusy;
1981 if (a->nfs_client != b->nfs_client)
1982 goto Ebusy;
1983 if (a->flags != b->flags)
1984 goto Ebusy;
1985 if (a->wsize != b->wsize)
1986 goto Ebusy;
1987 if (a->rsize != b->rsize)
1988 goto Ebusy;
1989 if (a->acregmin != b->acregmin)
1990 goto Ebusy;
1991 if (a->acregmax != b->acregmax)
1992 goto Ebusy;
1993 if (a->acdirmin != b->acdirmin)
1994 goto Ebusy;
1995 if (a->acdirmax != b->acdirmax)
1996 goto Ebusy;
1997 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1998 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001999 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002000Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002001 return 0;
2002}
2003
2004struct nfs_sb_mountdata {
2005 struct nfs_server *server;
2006 int mntflags;
2007};
2008
2009static int nfs_set_super(struct super_block *s, void *data)
2010{
2011 struct nfs_sb_mountdata *sb_mntdata = data;
2012 struct nfs_server *server = sb_mntdata->server;
2013 int ret;
2014
2015 s->s_flags = sb_mntdata->mntflags;
2016 s->s_fs_info = server;
2017 ret = set_anon_super(s, server);
2018 if (ret == 0)
2019 server->s_dev = s->s_dev;
2020 return ret;
2021}
2022
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002023static int nfs_compare_super_address(struct nfs_server *server1,
2024 struct nfs_server *server2)
2025{
2026 struct sockaddr *sap1, *sap2;
2027
2028 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2029 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2030
2031 if (sap1->sa_family != sap2->sa_family)
2032 return 0;
2033
2034 switch (sap1->sa_family) {
2035 case AF_INET: {
2036 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2037 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2038 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2039 return 0;
2040 if (sin1->sin_port != sin2->sin_port)
2041 return 0;
2042 break;
2043 }
2044 case AF_INET6: {
2045 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2046 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2047 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2048 return 0;
2049 if (sin1->sin6_port != sin2->sin6_port)
2050 return 0;
2051 break;
2052 }
2053 default:
2054 return 0;
2055 }
2056
2057 return 1;
2058}
2059
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002060static int nfs_compare_super(struct super_block *sb, void *data)
2061{
2062 struct nfs_sb_mountdata *sb_mntdata = data;
2063 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2064 int mntflags = sb_mntdata->mntflags;
2065
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002066 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002067 return 0;
2068 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2069 if (old->flags & NFS_MOUNT_UNSHARED)
2070 return 0;
2071 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2072 return 0;
2073 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002074}
2075
Miklos Szeredifa799752008-04-30 00:54:33 -07002076static int nfs_bdi_register(struct nfs_server *server)
2077{
2078 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2079}
2080
David Howells54ceac42006-08-22 20:06:13 -04002081static int nfs_get_sb(struct file_system_type *fs_type,
2082 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2083{
2084 struct nfs_server *server = NULL;
2085 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002086 struct nfs_parsed_mount_data *data;
2087 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002088 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002089 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002090 struct nfs_sb_mountdata sb_mntdata = {
2091 .mntflags = flags,
2092 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002093 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002094
Trond Myklebust33852a12008-06-19 14:20:11 -04002095 data = kzalloc(sizeof(*data), GFP_KERNEL);
2096 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2097 if (data == NULL || mntfh == NULL)
2098 goto out_free_fh;
2099
2100 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002101
David Howells54ceac42006-08-22 20:06:13 -04002102 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002103 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002104 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002105 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002106
Chuck Lever764302c2009-09-08 19:50:03 -04002107#ifdef CONFIG_NFS_V4
2108 if (data->version == 4) {
2109 error = nfs4_try_mount(flags, dev_name, data, mnt);
2110 kfree(data->client_address);
2111 goto out;
2112 }
2113#endif /* CONFIG_NFS_V4 */
2114
David Howells54ceac42006-08-22 20:06:13 -04002115 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002116 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002117 if (IS_ERR(server)) {
2118 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002119 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002120 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002121 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002122
Trond Myklebust75180df2007-05-16 16:53:28 -04002123 if (server->flags & NFS_MOUNT_UNSHARED)
2124 compare_super = NULL;
2125
David Howells54ceac42006-08-22 20:06:13 -04002126 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002127 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002128 if (IS_ERR(s)) {
2129 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002130 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002131 }
2132
David Howells54ceac42006-08-22 20:06:13 -04002133 if (s->s_fs_info != server) {
2134 nfs_free_server(server);
2135 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002136 } else {
2137 error = nfs_bdi_register(server);
2138 if (error)
2139 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002140 }
David Howells54ceac42006-08-22 20:06:13 -04002141
2142 if (!s->s_root) {
2143 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002144 nfs_fill_super(s, data);
David Howells08734042009-04-03 16:42:42 +01002145 nfs_fscache_get_super_cookie(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002146 }
2147
Trond Myklebust33852a12008-06-19 14:20:11 -04002148 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002149 if (IS_ERR(mntroot)) {
2150 error = PTR_ERR(mntroot);
2151 goto error_splat_super;
2152 }
2153
Trond Myklebust33852a12008-06-19 14:20:11 -04002154 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002155 if (error)
2156 goto error_splat_root;
2157
David Howellsf7b422b2006-06-09 09:34:33 -04002158 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002159 mnt->mnt_sb = s;
2160 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002161 error = 0;
2162
2163out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002164 kfree(data->nfs_server.hostname);
2165 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002166 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002167 security_free_mnt_opts(&data->lsm_opts);
2168out_free_fh:
2169 kfree(mntfh);
2170 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002171 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002172
David Howells54ceac42006-08-22 20:06:13 -04002173out_err_nosb:
2174 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002175 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002176
Eric Parisf9c3a382008-03-05 14:20:18 -05002177error_splat_root:
2178 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002179error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002180 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002181 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002182}
2183
David Howells54ceac42006-08-22 20:06:13 -04002184/*
2185 * Destroy an NFS2/3 superblock
2186 */
David Howellsf7b422b2006-06-09 09:34:33 -04002187static void nfs_kill_super(struct super_block *s)
2188{
2189 struct nfs_server *server = NFS_SB(s);
2190
Miklos Szeredifa799752008-04-30 00:54:33 -07002191 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002192 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002193 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002194 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002195}
2196
David Howells54ceac42006-08-22 20:06:13 -04002197/*
2198 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2199 */
2200static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2201 const char *dev_name, void *raw_data,
2202 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002203{
2204 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002205 struct super_block *s;
2206 struct nfs_server *server;
2207 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002208 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002209 struct nfs_sb_mountdata sb_mntdata = {
2210 .mntflags = flags,
2211 };
David Howells54ceac42006-08-22 20:06:13 -04002212 int error;
2213
2214 dprintk("--> nfs_xdev_get_sb()\n");
2215
2216 /* create a new volume representation */
2217 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2218 if (IS_ERR(server)) {
2219 error = PTR_ERR(server);
2220 goto out_err_noserver;
2221 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002222 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002223
Trond Myklebust75180df2007-05-16 16:53:28 -04002224 if (server->flags & NFS_MOUNT_UNSHARED)
2225 compare_super = NULL;
2226
David Howells54ceac42006-08-22 20:06:13 -04002227 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002228 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002229 if (IS_ERR(s)) {
2230 error = PTR_ERR(s);
2231 goto out_err_nosb;
2232 }
2233
2234 if (s->s_fs_info != server) {
2235 nfs_free_server(server);
2236 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002237 } else {
2238 error = nfs_bdi_register(server);
2239 if (error)
2240 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002241 }
2242
2243 if (!s->s_root) {
2244 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002245 nfs_clone_super(s, data->sb);
2246 }
2247
2248 mntroot = nfs_get_root(s, data->fh);
2249 if (IS_ERR(mntroot)) {
2250 error = PTR_ERR(mntroot);
2251 goto error_splat_super;
2252 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002253 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002254 dput(mntroot);
2255 error = -ESTALE;
2256 goto error_splat_super;
2257 }
David Howells54ceac42006-08-22 20:06:13 -04002258
2259 s->s_flags |= MS_ACTIVE;
2260 mnt->mnt_sb = s;
2261 mnt->mnt_root = mntroot;
2262
Eric Parisf9c3a382008-03-05 14:20:18 -05002263 /* clone any lsm security options from the parent to the new sb */
2264 security_sb_clone_mnt_opts(data->sb, s);
2265
David Howells54ceac42006-08-22 20:06:13 -04002266 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2267 return 0;
2268
2269out_err_nosb:
2270 nfs_free_server(server);
2271out_err_noserver:
2272 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2273 return error;
2274
2275error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002276 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002277 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2278 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002279}
2280
2281#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002282
2283/*
2284 * Finish setting up a cloned NFS4 superblock
2285 */
2286static void nfs4_clone_super(struct super_block *sb,
2287 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002288{
David Howells54ceac42006-08-22 20:06:13 -04002289 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2290 sb->s_blocksize = old_sb->s_blocksize;
2291 sb->s_maxbytes = old_sb->s_maxbytes;
2292 sb->s_time_gran = 1;
2293 sb->s_op = old_sb->s_op;
2294 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002295}
2296
2297/*
2298 * Set up an NFS4 superblock
2299 */
David Howells54ceac42006-08-22 20:06:13 -04002300static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002301{
David Howellsf7b422b2006-06-09 09:34:33 -04002302 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002303 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002304 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002305}
2306
Trond Myklebust01c3f052009-06-17 13:22:58 -07002307static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2308{
2309 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2310}
2311
Chuck Lever7630c852009-09-08 19:49:57 -04002312static int nfs4_validate_text_mount_data(void *options,
2313 struct nfs_parsed_mount_data *args,
2314 const char *dev_name)
2315{
2316 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2317
2318 nfs_set_default_port(sap, args->nfs_server.port, NFS_PORT);
2319
2320 nfs_validate_transport_protocol(args);
2321
2322 nfs4_validate_mount_flags(args);
2323
Trond Myklebust2ecda722009-09-08 19:50:07 -04002324 if (args->version != 4) {
2325 dfprintk(MOUNT,
2326 "NFS4: Illegal mount version\n");
2327 return -EINVAL;
2328 }
2329
Chuck Lever7630c852009-09-08 19:49:57 -04002330 if (args->auth_flavor_len > 1) {
2331 dfprintk(MOUNT,
2332 "NFS4: Too many RPC auth flavours specified\n");
2333 return -EINVAL;
2334 }
2335
2336 if (args->client_address == NULL) {
2337 dfprintk(MOUNT,
2338 "NFS4: mount program didn't pass callback address\n");
2339 return -EINVAL;
2340 }
2341
2342 return nfs_parse_devname(dev_name,
2343 &args->nfs_server.hostname,
2344 NFS4_MAXNAMLEN,
2345 &args->nfs_server.export_path,
2346 NFS4_MAXPATHLEN);
2347}
2348
David Howells54ceac42006-08-22 20:06:13 -04002349/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002350 * Validate NFSv4 mount options
2351 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002352static int nfs4_validate_mount_data(void *options,
2353 struct nfs_parsed_mount_data *args,
2354 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002355{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002356 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002357 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002358 char *c;
2359
2360 if (data == NULL)
2361 goto out_no_data;
2362
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002363 args->rsize = NFS_MAX_FILE_IO_SIZE;
2364 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002365 args->acregmin = NFS_DEF_ACREGMIN;
2366 args->acregmax = NFS_DEF_ACREGMAX;
2367 args->acdirmin = NFS_DEF_ACDIRMIN;
2368 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002369 args->nfs_server.port = NFS_UNSPEC_PORT;
Chuck Lever6738b252008-06-24 16:33:54 -04002370 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever059f90b2009-08-09 15:09:31 -04002371 args->auth_flavor_len = 1;
Chuck Lever764302c2009-09-08 19:50:03 -04002372 args->version = 4;
Mike Sager3fd5be92009-04-01 09:21:48 -04002373 args->minorversion = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002374
Chuck Leverf0768eb2007-07-01 12:13:01 -04002375 switch (data->version) {
2376 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002377 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002378 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002379 if (data->host_addrlen == 0)
2380 goto out_no_address;
2381 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002382 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002383 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002384 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002385 goto out_no_address;
2386
Chuck Lever6738b252008-06-24 16:33:54 -04002387 if (data->auth_flavourlen) {
2388 if (data->auth_flavourlen > 1)
2389 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002390 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002391 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002392 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002393 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002394 }
2395
2396 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2397 if (IS_ERR(c))
2398 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002399 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002400
2401 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2402 if (IS_ERR(c))
2403 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002404 args->nfs_server.export_path = c;
2405 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002406
2407 c = strndup_user(data->client_addr.data, 16);
2408 if (IS_ERR(c))
2409 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002410 args->client_address = c;
2411
2412 /*
2413 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2414 * can deal with.
2415 */
2416
2417 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2418 args->rsize = data->rsize;
2419 args->wsize = data->wsize;
2420 args->timeo = data->timeo;
2421 args->retrans = data->retrans;
2422 args->acregmin = data->acregmin;
2423 args->acregmax = data->acregmax;
2424 args->acdirmin = data->acdirmin;
2425 args->acdirmax = data->acdirmax;
2426 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002427 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002428
2429 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002430 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002431 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002432 return -EINVAL;
2433
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002434 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002435 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002436
Chuck Lever7630c852009-09-08 19:49:57 -04002437 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002438 }
2439
2440 return 0;
2441
2442out_no_data:
2443 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2444 return -EINVAL;
2445
2446out_inval_auth:
2447 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2448 data->auth_flavourlen);
2449 return -EINVAL;
2450
2451out_no_address:
2452 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2453 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002454}
2455
2456/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002457 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002458 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002459static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002460 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002461{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002462 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002463 struct super_block *s;
2464 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002465 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002466 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002467 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002468 struct nfs_sb_mountdata sb_mntdata = {
2469 .mntflags = flags,
2470 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002471 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002472
Trond Myklebust33852a12008-06-19 14:20:11 -04002473 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2474 if (data == NULL || mntfh == NULL)
2475 goto out_free_fh;
2476
2477 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002478
David Howells54ceac42006-08-22 20:06:13 -04002479 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002480 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002481 if (IS_ERR(server)) {
2482 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002483 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002484 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002485 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002486
Trond Myklebust75180df2007-05-16 16:53:28 -04002487 if (server->flags & NFS4_MOUNT_UNSHARED)
2488 compare_super = NULL;
2489
David Howells54ceac42006-08-22 20:06:13 -04002490 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002491 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002492 if (IS_ERR(s)) {
2493 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002494 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002495 }
2496
Trond Myklebust5dd31772006-08-24 01:03:05 -04002497 if (s->s_fs_info != server) {
2498 nfs_free_server(server);
2499 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002500 } else {
2501 error = nfs_bdi_register(server);
2502 if (error)
2503 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002504 }
2505
David Howells54ceac42006-08-22 20:06:13 -04002506 if (!s->s_root) {
2507 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002508 nfs4_fill_super(s);
David Howells08734042009-04-03 16:42:42 +01002509 nfs_fscache_get_super_cookie(s, data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002510 }
David Howellsf7b422b2006-06-09 09:34:33 -04002511
Trond Myklebust33852a12008-06-19 14:20:11 -04002512 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002513 if (IS_ERR(mntroot)) {
2514 error = PTR_ERR(mntroot);
2515 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002516 }
David Howells54ceac42006-08-22 20:06:13 -04002517
Trond Myklebust33852a12008-06-19 14:20:11 -04002518 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002519 if (error)
2520 goto error_splat_root;
2521
David Howellsf7b422b2006-06-09 09:34:33 -04002522 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002523 mnt->mnt_sb = s;
2524 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002525 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002526
Chuck Lever29eb9812007-07-01 12:12:30 -04002527out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002528 security_free_mnt_opts(&data->lsm_opts);
2529out_free_fh:
2530 kfree(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002531 return error;
David Howells54ceac42006-08-22 20:06:13 -04002532
Chuck Lever29eb9812007-07-01 12:12:30 -04002533out_free:
2534 nfs_free_server(server);
2535 goto out;
2536
Eric Paris46c8ac72008-05-02 13:42:42 -07002537error_splat_root:
2538 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002539error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002540 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002541 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002542}
2543
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002544static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2545 int flags, void *data, const char *hostname)
2546{
2547 struct vfsmount *root_mnt;
2548 char *root_devname;
2549 size_t len;
2550
2551 len = strlen(hostname) + 3;
2552 root_devname = kmalloc(len, GFP_KERNEL);
2553 if (root_devname == NULL)
2554 return ERR_PTR(-ENOMEM);
2555 snprintf(root_devname, len, "%s:/", hostname);
2556 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2557 kfree(root_devname);
2558 return root_mnt;
2559}
2560
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002561static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2562{
2563 char *page = (char *) __get_free_page(GFP_KERNEL);
2564 char *devname, *tmp;
2565
2566 if (page == NULL)
2567 return;
2568 devname = nfs_path(path->mnt->mnt_devname,
2569 path->mnt->mnt_root, path->dentry,
2570 page, PAGE_SIZE);
2571 if (devname == NULL)
2572 goto out_freepage;
2573 tmp = kstrdup(devname, GFP_KERNEL);
2574 if (tmp == NULL)
2575 goto out_freepage;
2576 kfree(mnt->mnt_devname);
2577 mnt->mnt_devname = tmp;
2578out_freepage:
2579 free_page((unsigned long)page);
2580}
2581
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002582static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2583 const char *export_path, struct vfsmount *mnt_target)
2584{
2585 struct mnt_namespace *ns_private;
2586 struct nameidata nd;
2587 struct super_block *s;
2588 int ret;
2589
2590 ns_private = create_mnt_ns(root_mnt);
2591 ret = PTR_ERR(ns_private);
2592 if (IS_ERR(ns_private))
2593 goto out_mntput;
2594
2595 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2596 export_path, LOOKUP_FOLLOW, &nd);
2597
2598 put_mnt_ns(ns_private);
2599
2600 if (ret != 0)
2601 goto out_err;
2602
2603 s = nd.path.mnt->mnt_sb;
2604 atomic_inc(&s->s_active);
2605 mnt_target->mnt_sb = s;
2606 mnt_target->mnt_root = dget(nd.path.dentry);
2607
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002608 /* Correct the device pathname */
2609 nfs_fix_devname(&nd.path, mnt_target);
2610
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002611 path_put(&nd.path);
2612 down_write(&s->s_umount);
2613 return 0;
2614out_mntput:
2615 mntput(root_mnt);
2616out_err:
2617 return ret;
2618}
2619
Chuck Levera6fe23b2009-09-08 19:50:00 -04002620static int nfs4_try_mount(int flags, const char *dev_name,
2621 struct nfs_parsed_mount_data *data,
2622 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002623{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002624 char *export_path;
2625 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002626 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002627
Chuck Levera6fe23b2009-09-08 19:50:00 -04002628 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002629
2630 export_path = data->nfs_server.export_path;
2631 data->nfs_server.export_path = "/";
2632 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2633 data->nfs_server.hostname);
2634 data->nfs_server.export_path = export_path;
2635
2636 error = PTR_ERR(root_mnt);
2637 if (IS_ERR(root_mnt))
2638 goto out;
2639
2640 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2641
2642out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002643 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2644 error != 0 ? " [error]" : "");
2645 return error;
2646}
2647
2648/*
2649 * Get the superblock for an NFS4 mountpoint
2650 */
2651static int nfs4_get_sb(struct file_system_type *fs_type,
2652 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2653{
2654 struct nfs_parsed_mount_data *data;
2655 int error = -ENOMEM;
2656
2657 data = kzalloc(sizeof(*data), GFP_KERNEL);
2658 if (data == NULL)
2659 goto out_free_data;
2660
2661 /* Validate the mount data */
2662 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2663 if (error < 0)
2664 goto out;
2665
2666 error = nfs4_try_mount(flags, dev_name, data, mnt);
2667
2668out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002669 kfree(data->client_address);
2670 kfree(data->nfs_server.export_path);
2671 kfree(data->nfs_server.hostname);
2672 kfree(data->fscache_uniq);
2673out_free_data:
2674 kfree(data);
2675 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2676 error != 0 ? " [error]" : "");
2677 return error;
2678}
2679
David Howellsf7b422b2006-06-09 09:34:33 -04002680static void nfs4_kill_super(struct super_block *sb)
2681{
2682 struct nfs_server *server = NFS_SB(sb);
2683
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002684 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002685 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002686 kill_anon_super(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002687 nfs4_renewd_prepare_shutdown(server);
David Howells08734042009-04-03 16:42:42 +01002688 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002689 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002690 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002691}
2692
2693/*
David Howells54ceac42006-08-22 20:06:13 -04002694 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002695 */
David Howells54ceac42006-08-22 20:06:13 -04002696static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2697 const char *dev_name, void *raw_data,
2698 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002699{
2700 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002701 struct super_block *s;
2702 struct nfs_server *server;
2703 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002704 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002705 struct nfs_sb_mountdata sb_mntdata = {
2706 .mntflags = flags,
2707 };
David Howells54ceac42006-08-22 20:06:13 -04002708 int error;
2709
2710 dprintk("--> nfs4_xdev_get_sb()\n");
2711
2712 /* create a new volume representation */
2713 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2714 if (IS_ERR(server)) {
2715 error = PTR_ERR(server);
2716 goto out_err_noserver;
2717 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002718 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002719
Trond Myklebust75180df2007-05-16 16:53:28 -04002720 if (server->flags & NFS4_MOUNT_UNSHARED)
2721 compare_super = NULL;
2722
David Howells54ceac42006-08-22 20:06:13 -04002723 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002724 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002725 if (IS_ERR(s)) {
2726 error = PTR_ERR(s);
2727 goto out_err_nosb;
2728 }
2729
2730 if (s->s_fs_info != server) {
2731 nfs_free_server(server);
2732 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002733 } else {
2734 error = nfs_bdi_register(server);
2735 if (error)
2736 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002737 }
2738
2739 if (!s->s_root) {
2740 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002741 nfs4_clone_super(s, data->sb);
2742 }
2743
2744 mntroot = nfs4_get_root(s, data->fh);
2745 if (IS_ERR(mntroot)) {
2746 error = PTR_ERR(mntroot);
2747 goto error_splat_super;
2748 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002749 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2750 dput(mntroot);
2751 error = -ESTALE;
2752 goto error_splat_super;
2753 }
David Howells54ceac42006-08-22 20:06:13 -04002754
2755 s->s_flags |= MS_ACTIVE;
2756 mnt->mnt_sb = s;
2757 mnt->mnt_root = mntroot;
2758
Eric Paris46c8ac72008-05-02 13:42:42 -07002759 security_sb_clone_mnt_opts(data->sb, s);
2760
David Howells54ceac42006-08-22 20:06:13 -04002761 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2762 return 0;
2763
2764out_err_nosb:
2765 nfs_free_server(server);
2766out_err_noserver:
2767 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2768 return error;
2769
2770error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002771 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002772 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2773 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002774}
2775
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002776static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2777 int flags, const char *dev_name, void *raw_data,
2778 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002779{
2780 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002781 struct super_block *s;
2782 struct nfs_server *server;
2783 struct dentry *mntroot;
2784 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002785 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002786 struct nfs_sb_mountdata sb_mntdata = {
2787 .mntflags = flags,
2788 };
David Howells54ceac42006-08-22 20:06:13 -04002789 int error;
2790
2791 dprintk("--> nfs4_referral_get_sb()\n");
2792
2793 /* create a new volume representation */
2794 server = nfs4_create_referral_server(data, &mntfh);
2795 if (IS_ERR(server)) {
2796 error = PTR_ERR(server);
2797 goto out_err_noserver;
2798 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002799 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002800
Trond Myklebust75180df2007-05-16 16:53:28 -04002801 if (server->flags & NFS4_MOUNT_UNSHARED)
2802 compare_super = NULL;
2803
David Howells54ceac42006-08-22 20:06:13 -04002804 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002805 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002806 if (IS_ERR(s)) {
2807 error = PTR_ERR(s);
2808 goto out_err_nosb;
2809 }
2810
2811 if (s->s_fs_info != server) {
2812 nfs_free_server(server);
2813 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002814 } else {
2815 error = nfs_bdi_register(server);
2816 if (error)
2817 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002818 }
2819
2820 if (!s->s_root) {
2821 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002822 nfs4_fill_super(s);
2823 }
2824
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002825 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002826 if (IS_ERR(mntroot)) {
2827 error = PTR_ERR(mntroot);
2828 goto error_splat_super;
2829 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002830 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2831 dput(mntroot);
2832 error = -ESTALE;
2833 goto error_splat_super;
2834 }
David Howells54ceac42006-08-22 20:06:13 -04002835
2836 s->s_flags |= MS_ACTIVE;
2837 mnt->mnt_sb = s;
2838 mnt->mnt_root = mntroot;
2839
Eric Paris46c8ac72008-05-02 13:42:42 -07002840 security_sb_clone_mnt_opts(data->sb, s);
2841
David Howells54ceac42006-08-22 20:06:13 -04002842 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2843 return 0;
2844
2845out_err_nosb:
2846 nfs_free_server(server);
2847out_err_noserver:
2848 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2849 return error;
2850
2851error_splat_super:
Al Viro6f5bbff2009-05-06 01:34:22 -04002852 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002853 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2854 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002855}
2856
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002857/*
2858 * Create an NFS4 server record on referral traversal
2859 */
2860static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2861 int flags, const char *dev_name, void *raw_data,
2862 struct vfsmount *mnt)
2863{
2864 struct nfs_clone_mount *data = raw_data;
2865 char *export_path;
2866 struct vfsmount *root_mnt;
2867 int error;
2868
2869 dprintk("--> nfs4_referral_get_sb()\n");
2870
2871 export_path = data->mnt_path;
2872 data->mnt_path = "/";
2873
2874 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2875 flags, data, data->hostname);
2876 data->mnt_path = export_path;
2877
2878 error = PTR_ERR(root_mnt);
2879 if (IS_ERR(root_mnt))
2880 goto out;
2881
2882 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2883out:
2884 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2885 error != 0 ? " [error]" : "");
2886 return error;
2887}
2888
David Howells54ceac42006-08-22 20:06:13 -04002889#endif /* CONFIG_NFS_V4 */