blob: 4100630c9a5b65f47bb5379ee2bc62f78e60284e [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>
David Howellsf7b422b2006-06-09 09:34:33 -040042#include <linux/seq_file.h>
43#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040044#include <linux/mnt_namespace.h>
45#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040046#include <linux/nfs_idmap.h>
47#include <linux/vfs.h>
48#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050049#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050051#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
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +020069#ifdef CONFIG_NFS_V3
70#define NFS_DEFAULT_VERSION 3
71#else
72#define NFS_DEFAULT_VERSION 2
73#endif
74
Chuck Leverbf0fd762007-07-01 12:13:44 -040075enum {
76 /* Mount options that take no arguments */
77 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078 Opt_posix, Opt_noposix,
79 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040082 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040083 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040086 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050087 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010088 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take integer arguments */
91 Opt_port,
92 Opt_rsize, Opt_wsize, Opt_bsize,
93 Opt_timeo, Opt_retrans,
94 Opt_acregmin, Opt_acregmax,
95 Opt_acdirmin, Opt_acdirmax,
96 Opt_actimeo,
97 Opt_namelen,
98 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040099 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -0400100 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -0400101 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400102
103 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -0500104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400105 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400106 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100107 Opt_fscache_uniq,
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400108 Opt_local_lock,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109
Chuck Leverf45663c2008-06-24 19:28:02 -0400110 /* Special mount options */
111 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400112
113 Opt_err
114};
115
Steven Whitehousea447c092008-10-13 10:46:57 +0100116static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_userspace, "bg" },
118 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400119 { Opt_userspace, "retry=%s" },
120
Chuck Leverf45663c2008-06-24 19:28:02 -0400121 { Opt_sloppy, "sloppy" },
122
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_soft, "soft" },
124 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400125 { Opt_deprecated, "intr" },
126 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127 { Opt_posix, "posix" },
128 { Opt_noposix, "noposix" },
129 { Opt_cto, "cto" },
130 { Opt_nocto, "nocto" },
131 { Opt_ac, "ac" },
132 { Opt_noac, "noac" },
133 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400137 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400138 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400140 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_acl, "acl" },
142 { Opt_noacl, "noacl" },
143 { Opt_rdirplus, "rdirplus" },
144 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400145 { Opt_sharecache, "sharecache" },
146 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500147 { Opt_resvport, "resvport" },
148 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100149 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100150 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
Chuck Levera5a16ba2009-06-17 18:02:14 -0700152 { Opt_port, "port=%s" },
153 { Opt_rsize, "rsize=%s" },
154 { Opt_wsize, "wsize=%s" },
155 { Opt_bsize, "bsize=%s" },
156 { Opt_timeo, "timeo=%s" },
157 { Opt_retrans, "retrans=%s" },
158 { Opt_acregmin, "acregmin=%s" },
159 { Opt_acregmax, "acregmax=%s" },
160 { Opt_acdirmin, "acdirmin=%s" },
161 { Opt_acdirmax, "acdirmax=%s" },
162 { Opt_actimeo, "actimeo=%s" },
163 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" },
166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400168 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400169
170 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" },
172 { Opt_mountproto, "mountproto=%s" },
173 { Opt_addr, "addr=%s" },
174 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500175 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400176 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400177
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400178 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400179 { Opt_fscache_uniq, "fsc=%s" },
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400180 { Opt_local_lock, "local_lock=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400181
Chuck Leverbf0fd762007-07-01 12:13:44 -0400182 { Opt_err, NULL }
183};
184
185enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500186 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187
188 Opt_xprt_err
189};
190
Steven Whitehousea447c092008-10-13 10:46:57 +0100191static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400192 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500193 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400194 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500195 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400196 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197
198 { Opt_xprt_err, NULL }
199};
200
201enum {
202 Opt_sec_none, Opt_sec_sys,
203 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
204 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
205 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
206
207 Opt_sec_err
208};
209
Steven Whitehousea447c092008-10-13 10:46:57 +0100210static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400211 { Opt_sec_none, "none" },
212 { Opt_sec_none, "null" },
213 { Opt_sec_sys, "sys" },
214
215 { Opt_sec_krb5, "krb5" },
216 { Opt_sec_krb5i, "krb5i" },
217 { Opt_sec_krb5p, "krb5p" },
218
219 { Opt_sec_lkey, "lkey" },
220 { Opt_sec_lkeyi, "lkeyi" },
221 { Opt_sec_lkeyp, "lkeyp" },
222
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500223 { Opt_sec_spkm, "spkm3" },
224 { Opt_sec_spkmi, "spkm3i" },
225 { Opt_sec_spkmp, "spkm3p" },
226
Chuck Leverbf0fd762007-07-01 12:13:44 -0400227 { Opt_sec_err, NULL }
228};
229
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400230enum {
231 Opt_lookupcache_all, Opt_lookupcache_positive,
232 Opt_lookupcache_none,
233
234 Opt_lookupcache_err
235};
236
237static match_table_t nfs_lookupcache_tokens = {
238 { Opt_lookupcache_all, "all" },
239 { Opt_lookupcache_positive, "pos" },
240 { Opt_lookupcache_positive, "positive" },
241 { Opt_lookupcache_none, "none" },
242
243 { Opt_lookupcache_err, NULL }
244};
245
Suresh Jayaraman5eebde22010-09-23 08:55:58 -0400246enum {
247 Opt_local_lock_all, Opt_local_lock_flock, Opt_local_lock_posix,
248 Opt_local_lock_none,
249
250 Opt_local_lock_err
251};
252
253static match_table_t nfs_local_lock_tokens = {
254 { Opt_local_lock_all, "all" },
255 { Opt_local_lock_flock, "flock" },
256 { Opt_local_lock_posix, "posix" },
257 { Opt_local_lock_none, "none" },
258
259 { Opt_local_lock_err, NULL }
260};
261
Chuck Leverbf0fd762007-07-01 12:13:44 -0400262
Al Viro42faad92008-04-24 07:21:56 -0400263static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400264static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400265static int nfs_show_options(struct seq_file *, struct vfsmount *);
266static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400267static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
Al Viro31f43472010-10-29 03:38:12 -0400268static struct dentry *nfs_xdev_mount(struct file_system_type *fs_type,
269 int flags, const char *dev_name, void *raw_data);
Trond Myklebust387c1492010-02-03 08:27:35 -0500270static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400271static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400272static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400273
274static struct file_system_type nfs_fs_type = {
275 .owner = THIS_MODULE,
276 .name = "nfs",
277 .get_sb = nfs_get_sb,
278 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700279 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400280};
281
David Howells54ceac42006-08-22 20:06:13 -0400282struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400283 .owner = THIS_MODULE,
284 .name = "nfs",
Al Viro31f43472010-10-29 03:38:12 -0400285 .mount = nfs_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400286 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700287 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400288};
289
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800290static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400291 .alloc_inode = nfs_alloc_inode,
292 .destroy_inode = nfs_destroy_inode,
293 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500294 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400295 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400296 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400297 .umount_begin = nfs_umount_begin,
298 .show_options = nfs_show_options,
299 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400300 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400301};
302
303#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400304static int nfs4_validate_text_mount_data(void *options,
305 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400306static int nfs4_try_mount(int flags, const char *dev_name,
307 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400308static int nfs4_get_sb(struct file_system_type *fs_type,
309 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400310static struct dentry *nfs4_remote_mount(struct file_system_type *fs_type,
311 int flags, const char *dev_name, void *raw_data);
312static struct dentry *nfs4_xdev_mount(struct file_system_type *fs_type,
313 int flags, const char *dev_name, void *raw_data);
David Howells54ceac42006-08-22 20:06:13 -0400314static int nfs4_referral_get_sb(struct file_system_type *fs_type,
315 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Al Viro31f43472010-10-29 03:38:12 -0400316static struct dentry *nfs4_remote_referral_mount(struct file_system_type *fs_type,
317 int flags, const char *dev_name, void *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400318static void nfs4_kill_super(struct super_block *sb);
319
320static struct file_system_type nfs4_fs_type = {
321 .owner = THIS_MODULE,
322 .name = "nfs4",
323 .get_sb = nfs4_get_sb,
324 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700325 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400326};
327
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400328static struct file_system_type nfs4_remote_fs_type = {
329 .owner = THIS_MODULE,
330 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400331 .mount = nfs4_remote_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400332 .kill_sb = nfs4_kill_super,
333 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
334};
335
David Howells54ceac42006-08-22 20:06:13 -0400336struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400337 .owner = THIS_MODULE,
338 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400339 .mount = nfs4_xdev_mount,
David Howellsf7b422b2006-06-09 09:34:33 -0400340 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700341 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400342};
343
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400344static struct file_system_type nfs4_remote_referral_fs_type = {
345 .owner = THIS_MODULE,
346 .name = "nfs4",
Al Viro31f43472010-10-29 03:38:12 -0400347 .mount = nfs4_remote_referral_mount,
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400348 .kill_sb = nfs4_kill_super,
349 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
350};
351
David Howells54ceac42006-08-22 20:06:13 -0400352struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400353 .owner = THIS_MODULE,
354 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400355 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400356 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700357 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400358};
359
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800360static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400361 .alloc_inode = nfs_alloc_inode,
362 .destroy_inode = nfs_destroy_inode,
363 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500364 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400365 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400366 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400367 .umount_begin = nfs_umount_begin,
368 .show_options = nfs_show_options,
369 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400370 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400371};
372#endif
373
Rusty Russell8e1f9362007-07-17 04:03:17 -0700374static struct shrinker acl_shrinker = {
375 .shrink = nfs_access_cache_shrinker,
376 .seeks = DEFAULT_SEEKS,
377};
Trond Myklebust979df722006-07-25 11:28:19 -0400378
David Howellsf7b422b2006-06-09 09:34:33 -0400379/*
380 * Register the NFS filesystems
381 */
382int __init register_nfs_fs(void)
383{
384 int ret;
385
386 ret = register_filesystem(&nfs_fs_type);
387 if (ret < 0)
388 goto error_0;
389
David Howellsf7b422b2006-06-09 09:34:33 -0400390 ret = nfs_register_sysctl();
391 if (ret < 0)
392 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800393#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400394 ret = register_filesystem(&nfs4_fs_type);
395 if (ret < 0)
396 goto error_2;
397#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700398 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400399 return 0;
400
401#ifdef CONFIG_NFS_V4
402error_2:
403 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800404#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400405error_1:
406 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400407error_0:
408 return ret;
409}
410
411/*
412 * Unregister the NFS filesystems
413 */
414void __exit unregister_nfs_fs(void)
415{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700416 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400417#ifdef CONFIG_NFS_V4
418 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400419#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700420 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400421 unregister_filesystem(&nfs_fs_type);
422}
423
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400424void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500425{
426 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400427
428 if (atomic_inc_return(&server->active) == 1)
429 atomic_inc(&sb->s_active);
430}
431
432void nfs_sb_deactive(struct super_block *sb)
433{
434 struct nfs_server *server = NFS_SB(sb);
435
436 if (atomic_dec_and_test(&server->active))
437 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500438}
439
David Howellsf7b422b2006-06-09 09:34:33 -0400440/*
441 * Deliver file system statistics to userspace
442 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400443static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400444{
David Howells0c7d90c2006-08-22 20:06:10 -0400445 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400446 unsigned char blockbits;
447 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400448 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400449 struct nfs_fsstat res;
450 int error = -ENOMEM;
451
452 res.fattr = nfs_alloc_fattr();
453 if (res.fattr == NULL)
454 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400455
David Howells8fa5c002006-08-22 20:06:12 -0400456 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400457 if (unlikely(error == -ESTALE)) {
458 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400459
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400460 pd_dentry = dget_parent(dentry);
461 if (pd_dentry != NULL) {
462 nfs_zap_caches(pd_dentry->d_inode);
463 dput(pd_dentry);
464 }
465 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400466 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400467 if (error < 0)
468 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400469
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700470 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400471
472 /*
473 * Current versions of glibc do not correctly handle the
474 * case where f_frsize != f_bsize. Eventually we want to
475 * report the value of wtmult in this field.
476 */
David Howells0c7d90c2006-08-22 20:06:10 -0400477 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400478
479 /*
480 * On most *nix systems, f_blocks, f_bfree, and f_bavail
481 * are reported in units of f_frsize. Linux hasn't had
482 * an f_frsize field in its statfs struct until recently,
483 * thus historically Linux's sys_statfs reports these
484 * fields in units of f_bsize.
485 */
David Howells0c7d90c2006-08-22 20:06:10 -0400486 buf->f_bsize = dentry->d_sb->s_blocksize;
487 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400488 blockres = (1 << blockbits) - 1;
489 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
490 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
491 buf->f_bavail = (res.abytes + blockres) >> blockbits;
492
493 buf->f_files = res.tfiles;
494 buf->f_ffree = res.afiles;
495
496 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700497
David Howellsf7b422b2006-06-09 09:34:33 -0400498 return 0;
499
500 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700501 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700502 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400503}
504
David Howells7d4e2742006-08-22 20:06:07 -0400505/*
506 * Map the security flavour number to a name
507 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400508static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
509{
David Howells7d4e2742006-08-22 20:06:07 -0400510 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400511 rpc_authflavor_t flavour;
512 const char *str;
513 } sec_flavours[] = {
514 { RPC_AUTH_NULL, "null" },
515 { RPC_AUTH_UNIX, "sys" },
516 { RPC_AUTH_GSS_KRB5, "krb5" },
517 { RPC_AUTH_GSS_KRB5I, "krb5i" },
518 { RPC_AUTH_GSS_KRB5P, "krb5p" },
519 { RPC_AUTH_GSS_LKEY, "lkey" },
520 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
521 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
522 { RPC_AUTH_GSS_SPKM, "spkm" },
523 { RPC_AUTH_GSS_SPKMI, "spkmi" },
524 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400525 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400526 };
527 int i;
528
Chuck Lever4d81cd12007-07-01 12:12:40 -0400529 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400530 if (sec_flavours[i].flavour == flavour)
531 break;
532 }
533 return sec_flavours[i].str;
534}
535
Jeff Laytonee671b02009-12-03 15:58:56 -0500536static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
537 int showdefaults)
538{
539 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
540
541 seq_printf(m, ",mountproto=");
542 switch (sap->sa_family) {
543 case AF_INET:
544 switch (nfss->mountd_protocol) {
545 case IPPROTO_UDP:
546 seq_printf(m, RPCBIND_NETID_UDP);
547 break;
548 case IPPROTO_TCP:
549 seq_printf(m, RPCBIND_NETID_TCP);
550 break;
551 default:
552 if (showdefaults)
553 seq_printf(m, "auto");
554 }
555 break;
556 case AF_INET6:
557 switch (nfss->mountd_protocol) {
558 case IPPROTO_UDP:
559 seq_printf(m, RPCBIND_NETID_UDP6);
560 break;
561 case IPPROTO_TCP:
562 seq_printf(m, RPCBIND_NETID_TCP6);
563 break;
564 default:
565 if (showdefaults)
566 seq_printf(m, "auto");
567 }
568 break;
569 default:
570 if (showdefaults)
571 seq_printf(m, "auto");
572 }
573}
574
Chuck Lever82d101d2008-03-14 14:10:37 -0400575static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
576 int showdefaults)
577{
578 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
579
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400580 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
581 return;
582
Chuck Lever82d101d2008-03-14 14:10:37 -0400583 switch (sap->sa_family) {
584 case AF_INET: {
585 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700586 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400587 break;
588 }
589 case AF_INET6: {
590 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500591 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400592 break;
593 }
594 default:
595 if (showdefaults)
596 seq_printf(m, ",mountaddr=unspecified");
597 }
598
599 if (nfss->mountd_version || showdefaults)
600 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
601 if (nfss->mountd_port || showdefaults)
602 seq_printf(m, ",mountport=%u", nfss->mountd_port);
603
Jeff Laytonee671b02009-12-03 15:58:56 -0500604 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400605}
606
Trond Myklebust0be81892010-06-18 12:23:58 -0400607#ifdef CONFIG_NFS_V4
608static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
609 int showdefaults)
610{
611 struct nfs_client *clp = nfss->nfs_client;
612
613 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
614 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
615}
616#else
617static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
618 int showdefaults)
619{
620}
621#endif
622
David Howellsf7b422b2006-06-09 09:34:33 -0400623/*
624 * Describe the mount options in force on this server representation
625 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400626static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
627 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400628{
David Howells509de812006-08-22 20:06:11 -0400629 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400630 int flag;
David Howells509de812006-08-22 20:06:11 -0400631 const char *str;
632 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400633 } nfs_info[] = {
634 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400635 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400636 { NFS_MOUNT_NOCTO, ",nocto", "" },
637 { NFS_MOUNT_NOAC, ",noac", "" },
638 { NFS_MOUNT_NONLM, ",nolock", "" },
639 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400640 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500641 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
642 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400643 { 0, NULL, NULL }
644 };
David Howells509de812006-08-22 20:06:11 -0400645 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400646 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400647 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400648 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400649
Chuck Lever82d101d2008-03-14 14:10:37 -0400650 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400651 seq_printf(m, ",rsize=%u", nfss->rsize);
652 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400653 if (nfss->bsize != 0)
654 seq_printf(m, ",bsize=%u", nfss->bsize);
655 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400656 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400657 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400658 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400659 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400660 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400661 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400662 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400663 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400664 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
665 if (nfss->flags & nfs_infop->flag)
666 seq_puts(m, nfs_infop->str);
667 else
668 seq_puts(m, nfs_infop->nostr);
669 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400670 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500671 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400672 if (version == 4) {
673 if (nfss->port != NFS_PORT)
674 seq_printf(m, ",port=%u", nfss->port);
675 } else
676 if (nfss->port)
677 seq_printf(m, ",port=%u", nfss->port);
678
Trond Myklebust33170232007-12-20 16:03:59 -0500679 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
680 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400681 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400682
683 if (version != 4)
684 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400685 else
686 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400687
David Howellsb797cac2009-04-03 16:42:48 +0100688 if (nfss->options & NFS_OPTION_FSCACHE)
689 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400690
691 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
692 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
693 seq_printf(m, ",lookupcache=none");
694 else
695 seq_printf(m, ",lookupcache=pos");
696 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400697
698 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
699 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
700
701 if (!local_flock && !local_fcntl)
702 seq_printf(m, ",local_lock=none");
703 else if (local_flock && local_fcntl)
704 seq_printf(m, ",local_lock=all");
705 else if (local_flock)
706 seq_printf(m, ",local_lock=flock");
707 else
708 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400709}
710
711/*
712 * Describe the mount options on this VFS mountpoint
713 */
714static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
715{
716 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
717
718 nfs_show_mount_options(m, nfss, 0);
719
Chuck Lever5d8515c2007-12-10 14:57:16 -0500720 seq_printf(m, ",addr=%s",
721 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
722 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400723
724 return 0;
725}
726
727/*
728 * Present statistical information for this VFS mountpoint
729 */
730static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
731{
732 int i, cpu;
733 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
734 struct rpc_auth *auth = nfss->client->cl_auth;
735 struct nfs_iostats totals = { };
736
737 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
738
739 /*
740 * Display all mount option settings
741 */
742 seq_printf(m, "\n\topts:\t");
743 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
744 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
745 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
746 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
747 nfs_show_mount_options(m, nfss, 1);
748
749 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
750
751 seq_printf(m, "\n\tcaps:\t");
752 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400753 seq_printf(m, ",wtmult=%u", nfss->wtmult);
754 seq_printf(m, ",dtsize=%u", nfss->dtsize);
755 seq_printf(m, ",bsize=%u", nfss->bsize);
756 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400757
758#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500759 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400760 seq_printf(m, "\n\tnfsv4:\t");
761 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
762 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
763 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
764 }
765#endif
766
767 /*
768 * Display security flavor in effect for this mount
769 */
Chuck Lever2d767432008-03-14 14:10:08 -0400770 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400771 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400772 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400773
774 /*
775 * Display superblock I/O counters
776 */
777 for_each_possible_cpu(cpu) {
778 struct nfs_iostats *stats;
779
780 preempt_disable();
781 stats = per_cpu_ptr(nfss->io_stats, cpu);
782
783 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
784 totals.events[i] += stats->events[i];
785 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
786 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100787#ifdef CONFIG_NFS_FSCACHE
788 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
789 totals.fscache[i] += stats->fscache[i];
790#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400791
792 preempt_enable();
793 }
794
795 seq_printf(m, "\n\tevents:\t");
796 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
797 seq_printf(m, "%lu ", totals.events[i]);
798 seq_printf(m, "\n\tbytes:\t");
799 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
800 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100801#ifdef CONFIG_NFS_FSCACHE
802 if (nfss->options & NFS_OPTION_FSCACHE) {
803 seq_printf(m, "\n\tfsc:\t");
804 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
805 seq_printf(m, "%Lu ", totals.bytes[i]);
806 }
807#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400808 seq_printf(m, "\n");
809
810 rpc_print_iostats(m, nfss->client);
811
812 return 0;
813}
814
815/*
816 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400817 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400818 */
Al Viro42faad92008-04-24 07:21:56 -0400819static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400820{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200821 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400822 struct rpc_clnt *rpc;
823
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200824 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400825 /* -EIO all pending I/O */
826 rpc = server->client_acl;
827 if (!IS_ERR(rpc))
828 rpc_killall_tasks(rpc);
829 rpc = server->client;
830 if (!IS_ERR(rpc))
831 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400832}
833
Trond Myklebustc5811db2009-10-06 15:40:15 -0400834static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400835{
836 struct nfs_parsed_mount_data *data;
837
838 data = kzalloc(sizeof(*data), GFP_KERNEL);
839 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400840 data->acregmin = NFS_DEF_ACREGMIN;
841 data->acregmax = NFS_DEF_ACREGMAX;
842 data->acdirmin = NFS_DEF_ACDIRMIN;
843 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400844 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400845 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400846 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400847 data->auth_flavors[0] = RPC_AUTH_UNIX;
848 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400849 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400850 data->minorversion = 0;
851 }
852 return data;
853}
854
David Howellsf7b422b2006-06-09 09:34:33 -0400855/*
Chuck Levercdcd7f9a2007-12-10 14:57:45 -0500856 * Sanity-check a server address provided by the mount command.
857 *
858 * Address family must be initialized, and address must not be
859 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400860 */
861static int nfs_verify_server_address(struct sockaddr *addr)
862{
863 switch (addr->sa_family) {
864 case AF_INET: {
Chuck Levercdcd7f9a2007-12-10 14:57:45 -0500865 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700866 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f9a2007-12-10 14:57:45 -0500867 }
868 case AF_INET6: {
869 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
870 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400871 }
872 }
873
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400874 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400875 return 0;
876}
877
Chuck Lever9412b922007-12-10 14:59:21 -0500878/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400879 * Select between a default port value and a user-specified port value.
880 * If a zero value is set, then autobind will be used.
881 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400882static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400883 const unsigned short default_port)
884{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400885 if (*port == NFS_UNSPEC_PORT)
886 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400887
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400888 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400889}
890
891/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400892 * Sanity check the NFS transport protocol.
893 *
894 */
895static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
896{
897 switch (mnt->nfs_server.protocol) {
898 case XPRT_TRANSPORT_UDP:
899 case XPRT_TRANSPORT_TCP:
900 case XPRT_TRANSPORT_RDMA:
901 break;
902 default:
903 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
904 }
905}
906
907/*
908 * For text based NFSv2/v3 mounts, the mount protocol transport default
909 * settings should depend upon the specified NFS transport.
910 */
911static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
912{
913 nfs_validate_transport_protocol(mnt);
914
915 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
916 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
917 return;
918 switch (mnt->nfs_server.protocol) {
919 case XPRT_TRANSPORT_UDP:
920 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
921 break;
922 case XPRT_TRANSPORT_TCP:
923 case XPRT_TRANSPORT_RDMA:
924 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
925 }
926}
927
928/*
Chuck Lever01060c82008-06-24 16:33:38 -0400929 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400930 */
931static int nfs_parse_security_flavors(char *value,
932 struct nfs_parsed_mount_data *mnt)
933{
934 substring_t args[MAX_OPT_ARGS];
935
936 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
937
938 switch (match_token(value, nfs_secflavor_tokens, args)) {
939 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400940 mnt->auth_flavors[0] = RPC_AUTH_NULL;
941 break;
942 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400943 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
944 break;
945 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400946 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
947 break;
948 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400949 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
950 break;
951 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400952 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
953 break;
954 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400955 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
956 break;
957 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400958 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
959 break;
960 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400961 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
962 break;
963 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400964 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
965 break;
966 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400967 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
968 break;
969 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400970 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
971 break;
972 default:
973 return 0;
974 }
975
Chuck Lever059f90b2009-08-09 15:09:31 -0400976 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400977 return 1;
978}
979
980/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400981 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400982 * a data structure. The whole mount string is processed; bad options are
983 * skipped as they are encountered. If there were no errors, return 1;
984 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400985 */
986static int nfs_parse_mount_options(char *raw,
987 struct nfs_parsed_mount_data *mnt)
988{
Eric Parisf9c3a382008-03-05 14:20:18 -0500989 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700990 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -0500991 unsigned short protofamily = AF_UNSPEC;
992 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400993
994 if (!raw) {
995 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
996 return 1;
997 }
998 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
999
Eric Parisf9c3a382008-03-05 14:20:18 -05001000 secdata = alloc_secdata();
1001 if (!secdata)
1002 goto out_nomem;
1003
1004 rc = security_sb_copy_data(raw, secdata);
1005 if (rc)
1006 goto out_security_failure;
1007
1008 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1009 if (rc)
1010 goto out_security_failure;
1011
1012 free_secdata(secdata);
1013
Chuck Leverbf0fd762007-07-01 12:13:44 -04001014 while ((p = strsep(&raw, ",")) != NULL) {
1015 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001016 unsigned long option;
1017 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001018
1019 if (!*p)
1020 continue;
1021
1022 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1023
1024 token = match_token(p, nfs_mount_option_tokens, args);
1025 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001026
1027 /*
1028 * boolean options: foo/nofoo
1029 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001030 case Opt_soft:
1031 mnt->flags |= NFS_MOUNT_SOFT;
1032 break;
1033 case Opt_hard:
1034 mnt->flags &= ~NFS_MOUNT_SOFT;
1035 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001036 case Opt_posix:
1037 mnt->flags |= NFS_MOUNT_POSIX;
1038 break;
1039 case Opt_noposix:
1040 mnt->flags &= ~NFS_MOUNT_POSIX;
1041 break;
1042 case Opt_cto:
1043 mnt->flags &= ~NFS_MOUNT_NOCTO;
1044 break;
1045 case Opt_nocto:
1046 mnt->flags |= NFS_MOUNT_NOCTO;
1047 break;
1048 case Opt_ac:
1049 mnt->flags &= ~NFS_MOUNT_NOAC;
1050 break;
1051 case Opt_noac:
1052 mnt->flags |= NFS_MOUNT_NOAC;
1053 break;
1054 case Opt_lock:
1055 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001056 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1057 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001058 break;
1059 case Opt_nolock:
1060 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001061 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1062 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001063 break;
1064 case Opt_v2:
1065 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001066 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001067 break;
1068 case Opt_v3:
1069 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001070 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001071 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001072 case Opt_v4:
1073 mnt->flags &= ~NFS_MOUNT_VER3;
1074 mnt->version = 4;
1075 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001076 case Opt_udp:
1077 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001078 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001079 break;
1080 case Opt_tcp:
1081 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001082 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001083 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001084 case Opt_rdma:
1085 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1086 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001087 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001088 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001089 case Opt_acl:
1090 mnt->flags &= ~NFS_MOUNT_NOACL;
1091 break;
1092 case Opt_noacl:
1093 mnt->flags |= NFS_MOUNT_NOACL;
1094 break;
1095 case Opt_rdirplus:
1096 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1097 break;
1098 case Opt_nordirplus:
1099 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1100 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001101 case Opt_sharecache:
1102 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1103 break;
1104 case Opt_nosharecache:
1105 mnt->flags |= NFS_MOUNT_UNSHARED;
1106 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001107 case Opt_resvport:
1108 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1109 break;
1110 case Opt_noresvport:
1111 mnt->flags |= NFS_MOUNT_NORESVPORT;
1112 break;
David Howellsb797cac2009-04-03 16:42:48 +01001113 case Opt_fscache:
1114 mnt->options |= NFS_OPTION_FSCACHE;
1115 kfree(mnt->fscache_uniq);
1116 mnt->fscache_uniq = NULL;
1117 break;
1118 case Opt_nofscache:
1119 mnt->options &= ~NFS_OPTION_FSCACHE;
1120 kfree(mnt->fscache_uniq);
1121 mnt->fscache_uniq = NULL;
1122 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001123
Chuck Leverf45663c2008-06-24 19:28:02 -04001124 /*
1125 * options that take numeric values
1126 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001127 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001128 string = match_strdup(args);
1129 if (string == NULL)
1130 goto out_nomem;
1131 rc = strict_strtoul(string, 10, &option);
1132 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001133 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001134 goto out_invalid_value;
1135 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001136 break;
1137 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001138 string = match_strdup(args);
1139 if (string == NULL)
1140 goto out_nomem;
1141 rc = strict_strtoul(string, 10, &option);
1142 kfree(string);
1143 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001144 goto out_invalid_value;
1145 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001146 break;
1147 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001148 string = match_strdup(args);
1149 if (string == NULL)
1150 goto out_nomem;
1151 rc = strict_strtoul(string, 10, &option);
1152 kfree(string);
1153 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001154 goto out_invalid_value;
1155 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001156 break;
1157 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001158 string = match_strdup(args);
1159 if (string == NULL)
1160 goto out_nomem;
1161 rc = strict_strtoul(string, 10, &option);
1162 kfree(string);
1163 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001164 goto out_invalid_value;
1165 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 break;
1167 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001168 string = match_strdup(args);
1169 if (string == NULL)
1170 goto out_nomem;
1171 rc = strict_strtoul(string, 10, &option);
1172 kfree(string);
1173 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001174 goto out_invalid_value;
1175 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176 break;
1177 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001178 string = match_strdup(args);
1179 if (string == NULL)
1180 goto out_nomem;
1181 rc = strict_strtoul(string, 10, &option);
1182 kfree(string);
1183 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001184 goto out_invalid_value;
1185 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001186 break;
1187 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001188 string = match_strdup(args);
1189 if (string == NULL)
1190 goto out_nomem;
1191 rc = strict_strtoul(string, 10, &option);
1192 kfree(string);
1193 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001194 goto out_invalid_value;
1195 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001196 break;
1197 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001198 string = match_strdup(args);
1199 if (string == NULL)
1200 goto out_nomem;
1201 rc = strict_strtoul(string, 10, &option);
1202 kfree(string);
1203 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001204 goto out_invalid_value;
1205 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 break;
1207 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001208 string = match_strdup(args);
1209 if (string == NULL)
1210 goto out_nomem;
1211 rc = strict_strtoul(string, 10, &option);
1212 kfree(string);
1213 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001214 goto out_invalid_value;
1215 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
1217 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001218 string = match_strdup(args);
1219 if (string == NULL)
1220 goto out_nomem;
1221 rc = strict_strtoul(string, 10, &option);
1222 kfree(string);
1223 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001224 goto out_invalid_value;
1225 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001226 break;
1227 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001228 string = match_strdup(args);
1229 if (string == NULL)
1230 goto out_nomem;
1231 rc = strict_strtoul(string, 10, &option);
1232 kfree(string);
1233 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001234 goto out_invalid_value;
1235 mnt->acregmin = mnt->acregmax =
1236 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001237 break;
1238 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001239 string = match_strdup(args);
1240 if (string == NULL)
1241 goto out_nomem;
1242 rc = strict_strtoul(string, 10, &option);
1243 kfree(string);
1244 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001245 goto out_invalid_value;
1246 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001247 break;
1248 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001249 string = match_strdup(args);
1250 if (string == NULL)
1251 goto out_nomem;
1252 rc = strict_strtoul(string, 10, &option);
1253 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001254 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001255 goto out_invalid_value;
1256 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001257 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001258 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001259 string = match_strdup(args);
1260 if (string == NULL)
1261 goto out_nomem;
1262 rc = strict_strtoul(string, 10, &option);
1263 kfree(string);
1264 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001265 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001266 option > NFS_MNT3_VERSION)
1267 goto out_invalid_value;
1268 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001269 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001271 string = match_strdup(args);
1272 if (string == NULL)
1273 goto out_nomem;
1274 rc = strict_strtoul(string, 10, &option);
1275 kfree(string);
1276 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001277 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001278 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001279 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001280 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001281 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001283 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001284 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001285 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001286 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001287 case NFS4_VERSION:
1288 mnt->flags &= ~NFS_MOUNT_VER3;
1289 mnt->version = 4;
1290 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001291 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001292 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001293 }
1294 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001295 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001296 string = match_strdup(args);
1297 if (string == NULL)
1298 goto out_nomem;
1299 rc = strict_strtoul(string, 10, &option);
1300 kfree(string);
1301 if (rc != 0)
1302 goto out_invalid_value;
1303 if (option > NFS4_MAX_MINOR_VERSION)
1304 goto out_invalid_value;
1305 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001306 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001307
Chuck Leverf45663c2008-06-24 19:28:02 -04001308 /*
1309 * options that take text values
1310 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 case Opt_sec:
1312 string = match_strdup(args);
1313 if (string == NULL)
1314 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001315 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001316 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001317 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001318 dfprintk(MOUNT, "NFS: unrecognized "
1319 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001320 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001321 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 break;
1323 case Opt_proto:
1324 string = match_strdup(args);
1325 if (string == NULL)
1326 goto out_nomem;
1327 token = match_token(string,
1328 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001329
Jeff Laytonee671b02009-12-03 15:58:56 -05001330 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001332 case Opt_xprt_udp6:
1333 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001334 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001335 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001336 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001337 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001338 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001339 case Opt_xprt_tcp6:
1340 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001341 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001343 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001344 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001345 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001346 case Opt_xprt_rdma:
1347 /* vector side protocols to TCP */
1348 mnt->flags |= NFS_MOUNT_TCP;
1349 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001350 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001351 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001352 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001353 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001354 dfprintk(MOUNT, "NFS: unrecognized "
1355 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001356 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001357 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001358 }
1359 break;
1360 case Opt_mountproto:
1361 string = match_strdup(args);
1362 if (string == NULL)
1363 goto out_nomem;
1364 token = match_token(string,
1365 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001366 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001367
Jeff Laytonee671b02009-12-03 15:58:56 -05001368 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001369 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001370 case Opt_xprt_udp6:
1371 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001372 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001373 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001374 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001375 case Opt_xprt_tcp6:
1376 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001377 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001378 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001380 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001381 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001382 dfprintk(MOUNT, "NFS: unrecognized "
1383 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001384 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001385 }
1386 break;
1387 case Opt_addr:
1388 string = match_strdup(args);
1389 if (string == NULL)
1390 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001391 mnt->nfs_server.addrlen =
1392 rpc_pton(string, strlen(string),
1393 (struct sockaddr *)
1394 &mnt->nfs_server.address,
1395 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001396 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001397 if (mnt->nfs_server.addrlen == 0)
1398 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 break;
1400 case Opt_clientaddr:
1401 string = match_strdup(args);
1402 if (string == NULL)
1403 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001404 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001405 mnt->client_address = string;
1406 break;
Chuck Lever33832032007-12-10 14:59:13 -05001407 case Opt_mounthost:
1408 string = match_strdup(args);
1409 if (string == NULL)
1410 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001411 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001412 mnt->mount_server.hostname = string;
1413 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001414 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001415 string = match_strdup(args);
1416 if (string == NULL)
1417 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001418 mnt->mount_server.addrlen =
1419 rpc_pton(string, strlen(string),
1420 (struct sockaddr *)
1421 &mnt->mount_server.address,
1422 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001424 if (mnt->mount_server.addrlen == 0)
1425 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001426 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001427 case Opt_lookupcache:
1428 string = match_strdup(args);
1429 if (string == NULL)
1430 goto out_nomem;
1431 token = match_token(string,
1432 nfs_lookupcache_tokens, args);
1433 kfree(string);
1434 switch (token) {
1435 case Opt_lookupcache_all:
1436 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1437 break;
1438 case Opt_lookupcache_positive:
1439 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1440 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1441 break;
1442 case Opt_lookupcache_none:
1443 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1444 break;
1445 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001446 dfprintk(MOUNT, "NFS: invalid "
1447 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001448 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001449 };
1450 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001451 case Opt_fscache_uniq:
1452 string = match_strdup(args);
1453 if (string == NULL)
1454 goto out_nomem;
1455 kfree(mnt->fscache_uniq);
1456 mnt->fscache_uniq = string;
1457 mnt->options |= NFS_OPTION_FSCACHE;
1458 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001459 case Opt_local_lock:
1460 string = match_strdup(args);
1461 if (string == NULL)
1462 goto out_nomem;
1463 token = match_token(string, nfs_local_lock_tokens,
1464 args);
1465 kfree(string);
1466 switch (token) {
1467 case Opt_local_lock_all:
1468 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1469 NFS_MOUNT_LOCAL_FCNTL);
1470 break;
1471 case Opt_local_lock_flock:
1472 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1473 break;
1474 case Opt_local_lock_posix:
1475 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1476 break;
1477 case Opt_local_lock_none:
1478 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1479 NFS_MOUNT_LOCAL_FCNTL);
1480 break;
1481 default:
1482 dfprintk(MOUNT, "NFS: invalid "
1483 "local_lock argument\n");
1484 return 0;
1485 };
1486 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001487
Chuck Leverf45663c2008-06-24 19:28:02 -04001488 /*
1489 * Special options
1490 */
1491 case Opt_sloppy:
1492 sloppy = 1;
1493 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1494 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001495 case Opt_userspace:
1496 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001497 dfprintk(MOUNT, "NFS: ignoring mount option "
1498 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001499 break;
1500
1501 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001502 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001503 dfprintk(MOUNT, "NFS: unrecognized mount option "
1504 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001505 }
1506 }
1507
Chuck Leverd23c45f2009-06-17 18:02:13 -07001508 if (!sloppy && invalid_option)
1509 return 0;
1510
Jeff Laytonee671b02009-12-03 15:58:56 -05001511 /*
1512 * verify that any proto=/mountproto= options match the address
1513 * familiies in the addr=/mountaddr= options.
1514 */
1515 if (protofamily != AF_UNSPEC &&
1516 protofamily != mnt->nfs_server.address.ss_family)
1517 goto out_proto_mismatch;
1518
1519 if (mountfamily != AF_UNSPEC) {
1520 if (mnt->mount_server.addrlen) {
1521 if (mountfamily != mnt->mount_server.address.ss_family)
1522 goto out_mountproto_mismatch;
1523 } else {
1524 if (mountfamily != mnt->nfs_server.address.ss_family)
1525 goto out_mountproto_mismatch;
1526 }
1527 }
1528
Chuck Leverbf0fd762007-07-01 12:13:44 -04001529 return 1;
1530
Jeff Laytonee671b02009-12-03 15:58:56 -05001531out_mountproto_mismatch:
1532 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1533 "option\n");
1534 return 0;
1535out_proto_mismatch:
1536 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1537 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001538out_invalid_address:
1539 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1540 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001541out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001542 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001543 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001544out_nomem:
1545 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1546 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001547out_security_failure:
1548 free_secdata(secdata);
1549 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1550 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001551}
1552
1553/*
Chuck Leverec88f282009-08-09 15:09:32 -04001554 * Match the requested auth flavors with the list returned by
1555 * the server. Returns zero and sets the mount's authentication
1556 * flavor on success; returns -EACCES if server does not support
1557 * the requested flavor.
1558 */
1559static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1560 struct nfs_mount_request *request)
1561{
1562 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1563
1564 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001565 * Certain releases of Linux's mountd return an empty
1566 * flavor list. To prevent behavioral regression with
1567 * these servers (ie. rejecting mounts that used to
1568 * succeed), revert to pre-2.6.32 behavior (no checking)
1569 * if the returned flavor list is empty.
1570 */
1571 if (server_authlist_len == 0)
1572 return 0;
1573
1574 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001575 * We avoid sophisticated negotiating here, as there are
1576 * plenty of cases where we can get it wrong, providing
1577 * either too little or too much security.
1578 *
1579 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1580 * flavor listed first. However, some servers list
1581 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1582 * preferred default, in args->auth_flavors[0] if user
1583 * didn't specify sec= mount option.
1584 */
1585 for (i = 0; i < args->auth_flavor_len; i++)
1586 for (j = 0; j < server_authlist_len; j++)
1587 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1588 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1589 request->auth_flavs[j]);
1590 args->auth_flavors[0] = request->auth_flavs[j];
1591 return 0;
1592 }
1593
1594 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1595 nfs_umount(request);
1596 return -EACCES;
1597}
1598
1599/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001600 * Use the remote server's MOUNT service to request the NFS file handle
1601 * corresponding to the provided path.
1602 */
1603static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1604 struct nfs_fh *root_fh)
1605{
Chuck Leverec88f282009-08-09 15:09:32 -04001606 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1607 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001608 struct nfs_mount_request request = {
1609 .sap = (struct sockaddr *)
1610 &args->mount_server.address,
1611 .dirpath = args->nfs_server.export_path,
1612 .protocol = args->mount_server.protocol,
1613 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001614 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001615 .auth_flav_len = &server_authlist_len,
1616 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001617 };
Chuck Lever4c568012007-12-10 14:59:28 -05001618 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001619
1620 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001621 switch (args->version) {
1622 default:
1623 args->mount_server.version = NFS_MNT3_VERSION;
1624 break;
1625 case 2:
1626 args->mount_server.version = NFS_MNT_VERSION;
1627 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001628 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001629 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001630
Chuck Lever33832032007-12-10 14:59:13 -05001631 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001632 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001633 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001634 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001635
Chuck Lever0076d7b2007-07-01 12:13:49 -04001636 /*
1637 * Construct the mount server's address.
1638 */
Chuck Lever4c568012007-12-10 14:59:28 -05001639 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001640 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001641 args->nfs_server.addrlen);
1642 args->mount_server.addrlen = args->nfs_server.addrlen;
1643 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001644 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001645 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001646
1647 /*
1648 * Now ask the mount server to map our export path
1649 * to a file handle.
1650 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001651 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001652 if (status != 0) {
1653 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1654 request.hostname, status);
1655 return status;
1656 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001657
Chuck Leverec88f282009-08-09 15:09:32 -04001658 /*
1659 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1660 */
1661 if (args->mount_server.version != NFS_MNT3_VERSION)
1662 return 0;
1663 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001664}
1665
Chuck Leverd1aa0822008-06-23 12:36:45 -04001666static int nfs_parse_simple_hostname(const char *dev_name,
1667 char **hostname, size_t maxnamlen,
1668 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001669{
1670 size_t len;
1671 char *colon, *comma;
1672
1673 colon = strchr(dev_name, ':');
1674 if (colon == NULL)
1675 goto out_bad_devname;
1676
1677 len = colon - dev_name;
1678 if (len > maxnamlen)
1679 goto out_hostname;
1680
1681 /* N.B. caller will free nfs_server.hostname in all cases */
1682 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1683 if (!*hostname)
1684 goto out_nomem;
1685
1686 /* kill possible hostname list: not supported */
1687 comma = strchr(*hostname, ',');
1688 if (comma != NULL) {
1689 if (comma == *hostname)
1690 goto out_bad_devname;
1691 *comma = '\0';
1692 }
1693
1694 colon++;
1695 len = strlen(colon);
1696 if (len > maxpathlen)
1697 goto out_path;
1698 *export_path = kstrndup(colon, len, GFP_KERNEL);
1699 if (!*export_path)
1700 goto out_nomem;
1701
1702 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1703 return 0;
1704
1705out_bad_devname:
1706 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1707 return -EINVAL;
1708
1709out_nomem:
1710 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1711 return -ENOMEM;
1712
1713out_hostname:
1714 dfprintk(MOUNT, "NFS: server hostname too long\n");
1715 return -ENAMETOOLONG;
1716
1717out_path:
1718 dfprintk(MOUNT, "NFS: export pathname too long\n");
1719 return -ENAMETOOLONG;
1720}
1721
1722/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001723 * Hostname has square brackets around it because it contains one or
1724 * more colons. We look for the first closing square bracket, and a
1725 * colon must follow it.
1726 */
1727static int nfs_parse_protected_hostname(const char *dev_name,
1728 char **hostname, size_t maxnamlen,
1729 char **export_path, size_t maxpathlen)
1730{
1731 size_t len;
1732 char *start, *end;
1733
1734 start = (char *)(dev_name + 1);
1735
1736 end = strchr(start, ']');
1737 if (end == NULL)
1738 goto out_bad_devname;
1739 if (*(end + 1) != ':')
1740 goto out_bad_devname;
1741
1742 len = end - start;
1743 if (len > maxnamlen)
1744 goto out_hostname;
1745
1746 /* N.B. caller will free nfs_server.hostname in all cases */
1747 *hostname = kstrndup(start, len, GFP_KERNEL);
1748 if (*hostname == NULL)
1749 goto out_nomem;
1750
1751 end += 2;
1752 len = strlen(end);
1753 if (len > maxpathlen)
1754 goto out_path;
1755 *export_path = kstrndup(end, len, GFP_KERNEL);
1756 if (!*export_path)
1757 goto out_nomem;
1758
1759 return 0;
1760
1761out_bad_devname:
1762 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1763 return -EINVAL;
1764
1765out_nomem:
1766 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1767 return -ENOMEM;
1768
1769out_hostname:
1770 dfprintk(MOUNT, "NFS: server hostname too long\n");
1771 return -ENAMETOOLONG;
1772
1773out_path:
1774 dfprintk(MOUNT, "NFS: export pathname too long\n");
1775 return -ENAMETOOLONG;
1776}
1777
1778/*
1779 * Split "dev_name" into "hostname:export_path".
1780 *
1781 * The leftmost colon demarks the split between the server's hostname
1782 * and the export path. If the hostname starts with a left square
1783 * bracket, then it may contain colons.
1784 *
1785 * Note: caller frees hostname and export path, even on error.
1786 */
1787static int nfs_parse_devname(const char *dev_name,
1788 char **hostname, size_t maxnamlen,
1789 char **export_path, size_t maxpathlen)
1790{
1791 if (*dev_name == '[')
1792 return nfs_parse_protected_hostname(dev_name,
1793 hostname, maxnamlen,
1794 export_path, maxpathlen);
1795
1796 return nfs_parse_simple_hostname(dev_name,
1797 hostname, maxnamlen,
1798 export_path, maxpathlen);
1799}
1800
1801/*
David Howells54ceac42006-08-22 20:06:13 -04001802 * Validate the NFS2/NFS3 mount data
1803 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001804 *
1805 * For option strings, user space handles the following behaviors:
1806 *
1807 * + DNS: mapping server host name to IP address ("addr=" option)
1808 *
1809 * + failure mode: how to behave if a mount request can't be handled
1810 * immediately ("fg/bg" option)
1811 *
1812 * + retry: how often to retry a mount request ("retry=" option)
1813 *
1814 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1815 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001816 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001817static int nfs_validate_mount_data(void *options,
1818 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001819 struct nfs_fh *mntfh,
1820 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001821{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001822 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001823 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001824
Chuck Lever5df36e72007-07-01 12:12:56 -04001825 if (data == NULL)
1826 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001827
David Howellsf7b422b2006-06-09 09:34:33 -04001828 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001829 case 1:
1830 data->namlen = 0;
1831 case 2:
1832 data->bsize = 0;
1833 case 3:
1834 if (data->flags & NFS_MOUNT_VER3)
1835 goto out_no_v3;
1836 data->root.size = NFS2_FHSIZE;
1837 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1838 case 4:
1839 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1840 goto out_no_sec;
1841 case 5:
1842 memset(data->context, 0, sizeof(data->context));
1843 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001844 if (data->flags & NFS_MOUNT_VER3) {
1845 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1846 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001847 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001848 args->version = 3;
1849 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001850 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001851 args->version = 2;
1852 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001853
Chuck Lever5df36e72007-07-01 12:12:56 -04001854
1855 memcpy(mntfh->data, data->root.data, mntfh->size);
1856 if (mntfh->size < sizeof(mntfh->data))
1857 memset(mntfh->data + mntfh->size, 0,
1858 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001859
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001860 /*
1861 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1862 * can deal with.
1863 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001864 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001865 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001866 args->rsize = data->rsize;
1867 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001868 args->timeo = data->timeo;
1869 args->retrans = data->retrans;
1870 args->acregmin = data->acregmin;
1871 args->acregmax = data->acregmax;
1872 args->acdirmin = data->acdirmin;
1873 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001874
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001875 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001876 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001877 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001878 goto out_no_address;
1879
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001880 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001881 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001882 /* N.B. caller will free nfs_server.hostname in all cases */
1883 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1884 args->namlen = data->namlen;
1885 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001886
1887 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1888 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001889 if (!args->nfs_server.hostname)
1890 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001891
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001892 if (!(data->flags & NFS_MOUNT_NONLM))
1893 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1894 NFS_MOUNT_LOCAL_FCNTL);
1895 else
1896 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1897 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001898 /*
1899 * The legacy version 6 binary mount data from userspace has a
1900 * field used only to transport selinux information into the
1901 * the kernel. To continue to support that functionality we
1902 * have a touch of selinux knowledge here in the NFS code. The
1903 * userspace code converted context=blah to just blah so we are
1904 * converting back to the full string selinux understands.
1905 */
1906 if (data->context[0]){
1907#ifdef CONFIG_SECURITY_SELINUX
1908 int rc;
1909 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1910 if (!opts_str)
1911 return -ENOMEM;
1912 strcpy(opts_str, "context=");
1913 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1914 strcat(opts_str, &data->context[0]);
1915 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1916 kfree(opts_str);
1917 if (rc)
1918 return rc;
1919#else
1920 return -EINVAL;
1921#endif
1922 }
1923
Chuck Lever5df36e72007-07-01 12:12:56 -04001924 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001925 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001926 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001927
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001928 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001929 return -EINVAL;
1930
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001931 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001932 goto out_no_address;
1933
Chuck Lever764302c2009-09-08 19:50:03 -04001934 if (args->version == 4)
1935#ifdef CONFIG_NFS_V4
1936 return nfs4_validate_text_mount_data(options,
1937 args, dev_name);
1938#else
1939 goto out_v4_not_compiled;
1940#endif
1941
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001942 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001943
Trond Myklebust259875e2008-07-02 14:43:47 -04001944 nfs_set_mount_transport_protocol(args);
1945
Chuck Leverdc045892008-06-23 12:36:37 -04001946 status = nfs_parse_devname(dev_name,
1947 &args->nfs_server.hostname,
1948 PAGE_SIZE,
1949 &args->nfs_server.export_path,
1950 NFS_MAXPATHLEN);
1951 if (!status)
1952 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001953
Chuck Leverdc045892008-06-23 12:36:37 -04001954 kfree(args->nfs_server.export_path);
1955 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001956
Chuck Lever136d5582007-07-01 12:13:54 -04001957 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001958 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001959
Chuck Lever136d5582007-07-01 12:13:54 -04001960 break;
1961 }
David Howellsf7b422b2006-06-09 09:34:33 -04001962 }
David Howells54ceac42006-08-22 20:06:13 -04001963
David Howellsf7b422b2006-06-09 09:34:33 -04001964#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001965 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001966 goto out_v3_not_compiled;
1967#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001968
David Howells54ceac42006-08-22 20:06:13 -04001969 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001970
1971out_no_data:
1972 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1973 return -EINVAL;
1974
1975out_no_v3:
1976 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1977 data->version);
1978 return -EINVAL;
1979
1980out_no_sec:
1981 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1982 return -EINVAL;
1983
Chuck Lever5df36e72007-07-01 12:12:56 -04001984#ifndef CONFIG_NFS_V3
1985out_v3_not_compiled:
1986 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1987 return -EPROTONOSUPPORT;
1988#endif /* !CONFIG_NFS_V3 */
1989
Chuck Lever764302c2009-09-08 19:50:03 -04001990#ifndef CONFIG_NFS_V4
1991out_v4_not_compiled:
1992 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1993 return -EPROTONOSUPPORT;
1994#endif /* !CONFIG_NFS_V4 */
1995
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001996out_nomem:
1997 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1998 return -ENOMEM;
1999
Chuck Lever5df36e72007-07-01 12:12:56 -04002000out_no_address:
2001 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
2002 return -EINVAL;
2003
2004out_invalid_fh:
2005 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
2006 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04002007}
2008
Jeff Layton48b605f2008-06-10 15:38:39 -04002009static int
2010nfs_compare_remount_data(struct nfs_server *nfss,
2011 struct nfs_parsed_mount_data *data)
2012{
2013 if (data->flags != nfss->flags ||
2014 data->rsize != nfss->rsize ||
2015 data->wsize != nfss->wsize ||
2016 data->retrans != nfss->client->cl_timeout->to_retries ||
2017 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
2018 data->acregmin != nfss->acregmin / HZ ||
2019 data->acregmax != nfss->acregmax / HZ ||
2020 data->acdirmin != nfss->acdirmin / HZ ||
2021 data->acdirmax != nfss->acdirmax / HZ ||
2022 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002023 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04002024 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04002025 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
2026 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04002027 return -EINVAL;
2028
2029 return 0;
2030}
2031
2032static int
2033nfs_remount(struct super_block *sb, int *flags, char *raw_data)
2034{
2035 int error;
2036 struct nfs_server *nfss = sb->s_fs_info;
2037 struct nfs_parsed_mount_data *data;
2038 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
2039 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04002040 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04002041
2042 /*
2043 * Userspace mount programs that send binary options generally send
2044 * them populated with default values. We have no way to know which
2045 * ones were explicitly specified. Fall back to legacy behavior and
2046 * just return success.
2047 */
Marc Zyngier31c94462008-07-17 13:21:55 +02002048 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
2049 (nfsvers <= 3 && (!options || (options->version >= 1 &&
2050 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04002051 return 0;
2052
2053 data = kzalloc(sizeof(*data), GFP_KERNEL);
2054 if (data == NULL)
2055 return -ENOMEM;
2056
2057 /* fill out struct with values from existing mount */
2058 data->flags = nfss->flags;
2059 data->rsize = nfss->rsize;
2060 data->wsize = nfss->wsize;
2061 data->retrans = nfss->client->cl_timeout->to_retries;
2062 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
2063 data->acregmin = nfss->acregmin / HZ;
2064 data->acregmax = nfss->acregmax / HZ;
2065 data->acdirmin = nfss->acdirmin / HZ;
2066 data->acdirmax = nfss->acdirmax / HZ;
2067 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04002068 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04002069 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2070 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2071 data->nfs_server.addrlen);
2072
2073 /* overwrite those values with any that were specified */
2074 error = nfs_parse_mount_options((char *)options, data);
2075 if (error < 0)
2076 goto out;
2077
2078 /* compare new mount options with old ones */
2079 error = nfs_compare_remount_data(nfss, data);
2080out:
2081 kfree(data);
2082 return error;
2083}
2084
David Howells54ceac42006-08-22 20:06:13 -04002085/*
2086 * Initialise the common bits of the superblock
2087 */
2088static inline void nfs_initialise_sb(struct super_block *sb)
2089{
2090 struct nfs_server *server = NFS_SB(sb);
2091
2092 sb->s_magic = NFS_SUPER_MAGIC;
2093
2094 /* We probably want something more informative here */
2095 snprintf(sb->s_id, sizeof(sb->s_id),
2096 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2097
2098 if (sb->s_blocksize == 0)
2099 sb->s_blocksize = nfs_block_bits(server->wsize,
2100 &sb->s_blocksize_bits);
2101
2102 if (server->flags & NFS_MOUNT_NOAC)
2103 sb->s_flags |= MS_SYNCHRONOUS;
2104
Jens Axboe32a88aa2009-09-16 15:02:33 +02002105 sb->s_bdi = &server->backing_dev_info;
2106
David Howells54ceac42006-08-22 20:06:13 -04002107 nfs_super_set_maxbytes(sb, server->maxfilesize);
2108}
2109
2110/*
2111 * Finish setting up an NFS2/3 superblock
2112 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002113static void nfs_fill_super(struct super_block *sb,
2114 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002115{
2116 struct nfs_server *server = NFS_SB(sb);
2117
2118 sb->s_blocksize_bits = 0;
2119 sb->s_blocksize = 0;
2120 if (data->bsize)
2121 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2122
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002123 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002124 /* The VFS shouldn't apply the umask to mode bits. We will do
2125 * so ourselves when necessary.
2126 */
2127 sb->s_flags |= MS_POSIXACL;
2128 sb->s_time_gran = 1;
2129 }
2130
2131 sb->s_op = &nfs_sops;
2132 nfs_initialise_sb(sb);
2133}
2134
2135/*
2136 * Finish setting up a cloned NFS2/3 superblock
2137 */
2138static void nfs_clone_super(struct super_block *sb,
2139 const struct super_block *old_sb)
2140{
2141 struct nfs_server *server = NFS_SB(sb);
2142
2143 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2144 sb->s_blocksize = old_sb->s_blocksize;
2145 sb->s_maxbytes = old_sb->s_maxbytes;
2146
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002147 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002148 /* The VFS shouldn't apply the umask to mode bits. We will do
2149 * so ourselves when necessary.
2150 */
2151 sb->s_flags |= MS_POSIXACL;
2152 sb->s_time_gran = 1;
2153 }
2154
2155 sb->s_op = old_sb->s_op;
2156 nfs_initialise_sb(sb);
2157}
2158
Trond Myklebust275a5d22007-05-16 16:53:28 -04002159static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2160{
2161 const struct nfs_server *a = s->s_fs_info;
2162 const struct rpc_clnt *clnt_a = a->client;
2163 const struct rpc_clnt *clnt_b = b->client;
2164
2165 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2166 goto Ebusy;
2167 if (a->nfs_client != b->nfs_client)
2168 goto Ebusy;
2169 if (a->flags != b->flags)
2170 goto Ebusy;
2171 if (a->wsize != b->wsize)
2172 goto Ebusy;
2173 if (a->rsize != b->rsize)
2174 goto Ebusy;
2175 if (a->acregmin != b->acregmin)
2176 goto Ebusy;
2177 if (a->acregmax != b->acregmax)
2178 goto Ebusy;
2179 if (a->acdirmin != b->acdirmin)
2180 goto Ebusy;
2181 if (a->acdirmax != b->acdirmax)
2182 goto Ebusy;
2183 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2184 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002185 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002186Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002187 return 0;
2188}
2189
2190struct nfs_sb_mountdata {
2191 struct nfs_server *server;
2192 int mntflags;
2193};
2194
2195static int nfs_set_super(struct super_block *s, void *data)
2196{
2197 struct nfs_sb_mountdata *sb_mntdata = data;
2198 struct nfs_server *server = sb_mntdata->server;
2199 int ret;
2200
2201 s->s_flags = sb_mntdata->mntflags;
2202 s->s_fs_info = server;
2203 ret = set_anon_super(s, server);
2204 if (ret == 0)
2205 server->s_dev = s->s_dev;
2206 return ret;
2207}
2208
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002209static int nfs_compare_super_address(struct nfs_server *server1,
2210 struct nfs_server *server2)
2211{
2212 struct sockaddr *sap1, *sap2;
2213
2214 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2215 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2216
2217 if (sap1->sa_family != sap2->sa_family)
2218 return 0;
2219
2220 switch (sap1->sa_family) {
2221 case AF_INET: {
2222 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2223 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2224 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2225 return 0;
2226 if (sin1->sin_port != sin2->sin_port)
2227 return 0;
2228 break;
2229 }
2230 case AF_INET6: {
2231 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2232 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2233 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2234 return 0;
2235 if (sin1->sin6_port != sin2->sin6_port)
2236 return 0;
2237 break;
2238 }
2239 default:
2240 return 0;
2241 }
2242
2243 return 1;
2244}
2245
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002246static int nfs_compare_super(struct super_block *sb, void *data)
2247{
2248 struct nfs_sb_mountdata *sb_mntdata = data;
2249 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2250 int mntflags = sb_mntdata->mntflags;
2251
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002252 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002253 return 0;
2254 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2255 if (old->flags & NFS_MOUNT_UNSHARED)
2256 return 0;
2257 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2258 return 0;
2259 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002260}
2261
Miklos Szeredifa799752008-04-30 00:54:33 -07002262static int nfs_bdi_register(struct nfs_server *server)
2263{
2264 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2265}
2266
David Howells54ceac42006-08-22 20:06:13 -04002267static int nfs_get_sb(struct file_system_type *fs_type,
2268 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2269{
2270 struct nfs_server *server = NULL;
2271 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002272 struct nfs_parsed_mount_data *data;
2273 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002274 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002275 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002276 struct nfs_sb_mountdata sb_mntdata = {
2277 .mntflags = flags,
2278 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002279 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002280
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002281 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002282 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002283 if (data == NULL || mntfh == NULL)
2284 goto out_free_fh;
2285
2286 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002287
David Howells54ceac42006-08-22 20:06:13 -04002288 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002289 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002290 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002291 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002292
Chuck Lever764302c2009-09-08 19:50:03 -04002293#ifdef CONFIG_NFS_V4
2294 if (data->version == 4) {
2295 error = nfs4_try_mount(flags, dev_name, data, mnt);
2296 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002297 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002298 goto out;
2299 }
2300#endif /* CONFIG_NFS_V4 */
2301
David Howells54ceac42006-08-22 20:06:13 -04002302 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002303 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002304 if (IS_ERR(server)) {
2305 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002306 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002307 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002308 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002309
Trond Myklebust75180df2007-05-16 16:53:28 -04002310 if (server->flags & NFS_MOUNT_UNSHARED)
2311 compare_super = NULL;
2312
David Howells54ceac42006-08-22 20:06:13 -04002313 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002314 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002315 if (IS_ERR(s)) {
2316 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002317 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002318 }
2319
David Howells54ceac42006-08-22 20:06:13 -04002320 if (s->s_fs_info != server) {
2321 nfs_free_server(server);
2322 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002323 } else {
2324 error = nfs_bdi_register(server);
2325 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002326 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002327 }
David Howells54ceac42006-08-22 20:06:13 -04002328
2329 if (!s->s_root) {
2330 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002331 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002332 nfs_fscache_get_super_cookie(
2333 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002334 }
2335
Trond Myklebust33852a12008-06-19 14:20:11 -04002336 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002337 if (IS_ERR(mntroot)) {
2338 error = PTR_ERR(mntroot);
2339 goto error_splat_super;
2340 }
2341
Trond Myklebust33852a12008-06-19 14:20:11 -04002342 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002343 if (error)
2344 goto error_splat_root;
2345
David Howellsf7b422b2006-06-09 09:34:33 -04002346 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002347 mnt->mnt_sb = s;
2348 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002349 error = 0;
2350
2351out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002352 kfree(data->nfs_server.hostname);
2353 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002354 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002355 security_free_mnt_opts(&data->lsm_opts);
2356out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002357 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002358 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002359 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002360
David Howells54ceac42006-08-22 20:06:13 -04002361out_err_nosb:
2362 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002363 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002364
Eric Parisf9c3a382008-03-05 14:20:18 -05002365error_splat_root:
2366 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002367error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002368 if (server && !s->s_root)
2369 bdi_unregister(&server->backing_dev_info);
2370error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002371 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002372 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002373}
2374
David Howells54ceac42006-08-22 20:06:13 -04002375/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002376 * Ensure that we unregister the bdi before kill_anon_super
2377 * releases the device name
2378 */
2379static void nfs_put_super(struct super_block *s)
2380{
2381 struct nfs_server *server = NFS_SB(s);
2382
2383 bdi_unregister(&server->backing_dev_info);
2384}
2385
2386/*
David Howells54ceac42006-08-22 20:06:13 -04002387 * Destroy an NFS2/3 superblock
2388 */
David Howellsf7b422b2006-06-09 09:34:33 -04002389static void nfs_kill_super(struct super_block *s)
2390{
2391 struct nfs_server *server = NFS_SB(s);
2392
2393 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002394 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002395 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002396}
2397
David Howells54ceac42006-08-22 20:06:13 -04002398/*
2399 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2400 */
Al Viro31f43472010-10-29 03:38:12 -04002401static struct dentry *
2402nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2403 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002404{
2405 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002406 struct super_block *s;
2407 struct nfs_server *server;
2408 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002409 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002410 struct nfs_sb_mountdata sb_mntdata = {
2411 .mntflags = flags,
2412 };
David Howells54ceac42006-08-22 20:06:13 -04002413 int error;
2414
Al Viro31f43472010-10-29 03:38:12 -04002415 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002416
2417 /* create a new volume representation */
2418 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2419 if (IS_ERR(server)) {
2420 error = PTR_ERR(server);
2421 goto out_err_noserver;
2422 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002423 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002424
Trond Myklebust75180df2007-05-16 16:53:28 -04002425 if (server->flags & NFS_MOUNT_UNSHARED)
2426 compare_super = NULL;
2427
David Howells54ceac42006-08-22 20:06:13 -04002428 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002429 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002430 if (IS_ERR(s)) {
2431 error = PTR_ERR(s);
2432 goto out_err_nosb;
2433 }
2434
2435 if (s->s_fs_info != server) {
2436 nfs_free_server(server);
2437 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002438 } else {
2439 error = nfs_bdi_register(server);
2440 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002441 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002442 }
2443
2444 if (!s->s_root) {
2445 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002446 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002447 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002448 }
2449
2450 mntroot = nfs_get_root(s, data->fh);
2451 if (IS_ERR(mntroot)) {
2452 error = PTR_ERR(mntroot);
2453 goto error_splat_super;
2454 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002455 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002456 dput(mntroot);
2457 error = -ESTALE;
2458 goto error_splat_super;
2459 }
David Howells54ceac42006-08-22 20:06:13 -04002460
2461 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002462
Eric Parisf9c3a382008-03-05 14:20:18 -05002463 /* clone any lsm security options from the parent to the new sb */
2464 security_sb_clone_mnt_opts(data->sb, s);
2465
Al Viro31f43472010-10-29 03:38:12 -04002466 dprintk("<-- nfs_xdev_mount() = 0\n");
2467 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002468
2469out_err_nosb:
2470 nfs_free_server(server);
2471out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002472 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2473 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002474
2475error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002476 if (server && !s->s_root)
2477 bdi_unregister(&server->backing_dev_info);
2478error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002479 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002480 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2481 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002482}
2483
2484#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002485
2486/*
2487 * Finish setting up a cloned NFS4 superblock
2488 */
2489static void nfs4_clone_super(struct super_block *sb,
2490 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002491{
David Howells54ceac42006-08-22 20:06:13 -04002492 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2493 sb->s_blocksize = old_sb->s_blocksize;
2494 sb->s_maxbytes = old_sb->s_maxbytes;
2495 sb->s_time_gran = 1;
2496 sb->s_op = old_sb->s_op;
2497 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002498}
2499
2500/*
2501 * Set up an NFS4 superblock
2502 */
David Howells54ceac42006-08-22 20:06:13 -04002503static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002504{
David Howellsf7b422b2006-06-09 09:34:33 -04002505 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002506 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002507 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002508}
2509
Trond Myklebust01c3f052009-06-17 13:22:58 -07002510static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2511{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002512 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2513 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002514}
2515
Chuck Lever7630c852009-09-08 19:49:57 -04002516static int nfs4_validate_text_mount_data(void *options,
2517 struct nfs_parsed_mount_data *args,
2518 const char *dev_name)
2519{
2520 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2521
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002522 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002523
2524 nfs_validate_transport_protocol(args);
2525
2526 nfs4_validate_mount_flags(args);
2527
Trond Myklebust2ecda72b2009-09-08 19:50:07 -04002528 if (args->version != 4) {
2529 dfprintk(MOUNT,
2530 "NFS4: Illegal mount version\n");
2531 return -EINVAL;
2532 }
2533
Chuck Lever7630c852009-09-08 19:49:57 -04002534 if (args->auth_flavor_len > 1) {
2535 dfprintk(MOUNT,
2536 "NFS4: Too many RPC auth flavours specified\n");
2537 return -EINVAL;
2538 }
2539
2540 if (args->client_address == NULL) {
2541 dfprintk(MOUNT,
2542 "NFS4: mount program didn't pass callback address\n");
2543 return -EINVAL;
2544 }
2545
2546 return nfs_parse_devname(dev_name,
2547 &args->nfs_server.hostname,
2548 NFS4_MAXNAMLEN,
2549 &args->nfs_server.export_path,
2550 NFS4_MAXPATHLEN);
2551}
2552
David Howells54ceac42006-08-22 20:06:13 -04002553/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002554 * Validate NFSv4 mount options
2555 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002556static int nfs4_validate_mount_data(void *options,
2557 struct nfs_parsed_mount_data *args,
2558 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002559{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002560 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002561 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002562 char *c;
2563
2564 if (data == NULL)
2565 goto out_no_data;
2566
2567 switch (data->version) {
2568 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002569 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002570 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002571 if (data->host_addrlen == 0)
2572 goto out_no_address;
2573 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002574 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002575 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002576 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577 goto out_no_address;
2578
Chuck Lever6738b252008-06-24 16:33:54 -04002579 if (data->auth_flavourlen) {
2580 if (data->auth_flavourlen > 1)
2581 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002582 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002583 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002584 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002585 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002586 }
2587
2588 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2589 if (IS_ERR(c))
2590 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002591 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002592
2593 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2594 if (IS_ERR(c))
2595 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002596 args->nfs_server.export_path = c;
2597 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002598
2599 c = strndup_user(data->client_addr.data, 16);
2600 if (IS_ERR(c))
2601 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002602 args->client_address = c;
2603
2604 /*
2605 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2606 * can deal with.
2607 */
2608
2609 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2610 args->rsize = data->rsize;
2611 args->wsize = data->wsize;
2612 args->timeo = data->timeo;
2613 args->retrans = data->retrans;
2614 args->acregmin = data->acregmin;
2615 args->acregmax = data->acregmax;
2616 args->acdirmin = data->acdirmin;
2617 args->acdirmax = data->acdirmax;
2618 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002619 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002620
2621 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002622 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002623 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002624 return -EINVAL;
2625
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002626 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002627 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002628
Chuck Lever7630c852009-09-08 19:49:57 -04002629 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002630 }
2631
2632 return 0;
2633
2634out_no_data:
2635 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2636 return -EINVAL;
2637
2638out_inval_auth:
2639 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2640 data->auth_flavourlen);
2641 return -EINVAL;
2642
2643out_no_address:
2644 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2645 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002646}
2647
2648/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002649 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002650 */
Al Viro31f43472010-10-29 03:38:12 -04002651static struct dentry *
2652nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2653 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002654{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002655 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002656 struct super_block *s;
2657 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002658 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002659 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002660 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002661 struct nfs_sb_mountdata sb_mntdata = {
2662 .mntflags = flags,
2663 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002664 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002665
Trond Myklebustb157b062010-04-19 19:05:48 -04002666 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002667 if (data == NULL || mntfh == NULL)
2668 goto out_free_fh;
2669
2670 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002671
David Howells54ceac42006-08-22 20:06:13 -04002672 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002673 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002674 if (IS_ERR(server)) {
2675 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002676 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002677 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002678 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002679
Trond Myklebust75180df2007-05-16 16:53:28 -04002680 if (server->flags & NFS4_MOUNT_UNSHARED)
2681 compare_super = NULL;
2682
David Howells54ceac42006-08-22 20:06:13 -04002683 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002684 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002685 if (IS_ERR(s)) {
2686 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002687 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002688 }
2689
Trond Myklebust5dd31772006-08-24 01:03:05 -04002690 if (s->s_fs_info != server) {
2691 nfs_free_server(server);
2692 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002693 } else {
2694 error = nfs_bdi_register(server);
2695 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002696 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002697 }
2698
David Howells54ceac42006-08-22 20:06:13 -04002699 if (!s->s_root) {
2700 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002701 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002702 nfs_fscache_get_super_cookie(
2703 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002704 }
David Howellsf7b422b2006-06-09 09:34:33 -04002705
Trond Myklebust33852a12008-06-19 14:20:11 -04002706 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002707 if (IS_ERR(mntroot)) {
2708 error = PTR_ERR(mntroot);
2709 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002710 }
David Howells54ceac42006-08-22 20:06:13 -04002711
Trond Myklebust33852a12008-06-19 14:20:11 -04002712 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002713 if (error)
2714 goto error_splat_root;
2715
David Howellsf7b422b2006-06-09 09:34:33 -04002716 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002717
2718 security_free_mnt_opts(&data->lsm_opts);
2719 nfs_free_fhandle(mntfh);
2720 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002721
Chuck Lever29eb9812007-07-01 12:12:30 -04002722out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002723 security_free_mnt_opts(&data->lsm_opts);
2724out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002725 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002726 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002727
Chuck Lever29eb9812007-07-01 12:12:30 -04002728out_free:
2729 nfs_free_server(server);
2730 goto out;
2731
Eric Paris46c8ac72008-05-02 13:42:42 -07002732error_splat_root:
2733 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002734error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002735 if (server && !s->s_root)
2736 bdi_unregister(&server->backing_dev_info);
2737error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002738 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002739 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002740}
2741
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002742static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2743 int flags, void *data, const char *hostname)
2744{
2745 struct vfsmount *root_mnt;
2746 char *root_devname;
2747 size_t len;
2748
2749 len = strlen(hostname) + 3;
2750 root_devname = kmalloc(len, GFP_KERNEL);
2751 if (root_devname == NULL)
2752 return ERR_PTR(-ENOMEM);
2753 snprintf(root_devname, len, "%s:/", hostname);
2754 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2755 kfree(root_devname);
2756 return root_mnt;
2757}
2758
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002759static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2760{
2761 char *page = (char *) __get_free_page(GFP_KERNEL);
2762 char *devname, *tmp;
2763
2764 if (page == NULL)
2765 return;
2766 devname = nfs_path(path->mnt->mnt_devname,
2767 path->mnt->mnt_root, path->dentry,
2768 page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002769 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002770 goto out_freepage;
2771 tmp = kstrdup(devname, GFP_KERNEL);
2772 if (tmp == NULL)
2773 goto out_freepage;
2774 kfree(mnt->mnt_devname);
2775 mnt->mnt_devname = tmp;
2776out_freepage:
2777 free_page((unsigned long)page);
2778}
2779
Trond Myklebustce587e02010-04-16 16:22:52 -04002780struct nfs_referral_count {
2781 struct list_head list;
2782 const struct task_struct *task;
2783 unsigned int referral_count;
2784};
2785
2786static LIST_HEAD(nfs_referral_count_list);
2787static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2788
2789static struct nfs_referral_count *nfs_find_referral_count(void)
2790{
2791 struct nfs_referral_count *p;
2792
2793 list_for_each_entry(p, &nfs_referral_count_list, list) {
2794 if (p->task == current)
2795 return p;
2796 }
2797 return NULL;
2798}
2799
2800#define NFS_MAX_NESTED_REFERRALS 2
2801
2802static int nfs_referral_loop_protect(void)
2803{
2804 struct nfs_referral_count *p, *new;
2805 int ret = -ENOMEM;
2806
2807 new = kmalloc(sizeof(*new), GFP_KERNEL);
2808 if (!new)
2809 goto out;
2810 new->task = current;
2811 new->referral_count = 1;
2812
2813 ret = 0;
2814 spin_lock(&nfs_referral_count_list_lock);
2815 p = nfs_find_referral_count();
2816 if (p != NULL) {
2817 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2818 ret = -ELOOP;
2819 else
2820 p->referral_count++;
2821 } else {
2822 list_add(&new->list, &nfs_referral_count_list);
2823 new = NULL;
2824 }
2825 spin_unlock(&nfs_referral_count_list_lock);
2826 kfree(new);
2827out:
2828 return ret;
2829}
2830
2831static void nfs_referral_loop_unprotect(void)
2832{
2833 struct nfs_referral_count *p;
2834
2835 spin_lock(&nfs_referral_count_list_lock);
2836 p = nfs_find_referral_count();
2837 p->referral_count--;
2838 if (p->referral_count == 0)
2839 list_del(&p->list);
2840 else
2841 p = NULL;
2842 spin_unlock(&nfs_referral_count_list_lock);
2843 kfree(p);
2844}
2845
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002846static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2847 const char *export_path, struct vfsmount *mnt_target)
2848{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002849 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002850 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002851 struct super_block *s;
2852 int ret;
2853
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002854 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2855 if (nd == NULL)
2856 return -ENOMEM;
2857
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002858 ns_private = create_mnt_ns(root_mnt);
2859 ret = PTR_ERR(ns_private);
2860 if (IS_ERR(ns_private))
2861 goto out_mntput;
2862
Trond Myklebustce587e02010-04-16 16:22:52 -04002863 ret = nfs_referral_loop_protect();
2864 if (ret != 0)
2865 goto out_put_mnt_ns;
2866
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002867 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002868 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002869
Trond Myklebustce587e02010-04-16 16:22:52 -04002870 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002871 put_mnt_ns(ns_private);
2872
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002873 if (ret != 0)
2874 goto out_err;
2875
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002876 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002877 atomic_inc(&s->s_active);
2878 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002879 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002880
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002881 /* Correct the device pathname */
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002882 nfs_fix_devname(&nd->path, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002883
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002884 path_put(&nd->path);
2885 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002886 down_write(&s->s_umount);
2887 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002888out_put_mnt_ns:
2889 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002890out_mntput:
2891 mntput(root_mnt);
2892out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002893 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002894 return ret;
2895}
2896
Chuck Levera6fe23b2009-09-08 19:50:00 -04002897static int nfs4_try_mount(int flags, const char *dev_name,
2898 struct nfs_parsed_mount_data *data,
2899 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002900{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002901 char *export_path;
2902 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002903 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002904
Chuck Levera6fe23b2009-09-08 19:50:00 -04002905 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002906
2907 export_path = data->nfs_server.export_path;
2908 data->nfs_server.export_path = "/";
2909 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2910 data->nfs_server.hostname);
2911 data->nfs_server.export_path = export_path;
2912
2913 error = PTR_ERR(root_mnt);
2914 if (IS_ERR(root_mnt))
2915 goto out;
2916
2917 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2918
2919out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002920 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2921 error != 0 ? " [error]" : "");
2922 return error;
2923}
2924
2925/*
2926 * Get the superblock for an NFS4 mountpoint
2927 */
2928static int nfs4_get_sb(struct file_system_type *fs_type,
2929 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2930{
2931 struct nfs_parsed_mount_data *data;
2932 int error = -ENOMEM;
2933
Trond Myklebustc5811db2009-10-06 15:40:15 -04002934 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002935 if (data == NULL)
2936 goto out_free_data;
2937
2938 /* Validate the mount data */
2939 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2940 if (error < 0)
2941 goto out;
2942
2943 error = nfs4_try_mount(flags, dev_name, data, mnt);
2944
2945out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002946 kfree(data->client_address);
2947 kfree(data->nfs_server.export_path);
2948 kfree(data->nfs_server.hostname);
2949 kfree(data->fscache_uniq);
2950out_free_data:
2951 kfree(data);
2952 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2953 error != 0 ? " [error]" : "");
2954 return error;
2955}
2956
David Howellsf7b422b2006-06-09 09:34:33 -04002957static void nfs4_kill_super(struct super_block *sb)
2958{
2959 struct nfs_server *server = NFS_SB(sb);
2960
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002961 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002962 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002963 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002964 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002965 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002966 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002967}
2968
2969/*
David Howells54ceac42006-08-22 20:06:13 -04002970 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002971 */
Al Viro31f43472010-10-29 03:38:12 -04002972static struct dentry *
2973nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2974 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002975{
2976 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002977 struct super_block *s;
2978 struct nfs_server *server;
2979 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002980 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002981 struct nfs_sb_mountdata sb_mntdata = {
2982 .mntflags = flags,
2983 };
David Howells54ceac42006-08-22 20:06:13 -04002984 int error;
2985
Al Viro31f43472010-10-29 03:38:12 -04002986 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002987
2988 /* create a new volume representation */
2989 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2990 if (IS_ERR(server)) {
2991 error = PTR_ERR(server);
2992 goto out_err_noserver;
2993 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002994 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002995
Trond Myklebust75180df2007-05-16 16:53:28 -04002996 if (server->flags & NFS4_MOUNT_UNSHARED)
2997 compare_super = NULL;
2998
David Howells54ceac42006-08-22 20:06:13 -04002999 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003000 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003001 if (IS_ERR(s)) {
3002 error = PTR_ERR(s);
3003 goto out_err_nosb;
3004 }
3005
3006 if (s->s_fs_info != server) {
3007 nfs_free_server(server);
3008 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003009 } else {
3010 error = nfs_bdi_register(server);
3011 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003012 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003013 }
3014
3015 if (!s->s_root) {
3016 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003017 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04003018 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003019 }
3020
3021 mntroot = nfs4_get_root(s, data->fh);
3022 if (IS_ERR(mntroot)) {
3023 error = PTR_ERR(mntroot);
3024 goto error_splat_super;
3025 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003026 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3027 dput(mntroot);
3028 error = -ESTALE;
3029 goto error_splat_super;
3030 }
David Howells54ceac42006-08-22 20:06:13 -04003031
3032 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003033
Eric Paris46c8ac72008-05-02 13:42:42 -07003034 security_sb_clone_mnt_opts(data->sb, s);
3035
Al Viro31f43472010-10-29 03:38:12 -04003036 dprintk("<-- nfs4_xdev_mount() = 0\n");
3037 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003038
3039out_err_nosb:
3040 nfs_free_server(server);
3041out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04003042 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
3043 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003044
3045error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003046 if (server && !s->s_root)
3047 bdi_unregister(&server->backing_dev_info);
3048error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003049 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04003050 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
3051 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003052}
3053
Al Viro31f43472010-10-29 03:38:12 -04003054static struct dentry *
3055nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
3056 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04003057{
3058 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04003059 struct super_block *s;
3060 struct nfs_server *server;
3061 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04003062 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04003063 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003064 struct nfs_sb_mountdata sb_mntdata = {
3065 .mntflags = flags,
3066 };
Trond Myklebust4f727292010-04-16 16:22:48 -04003067 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04003068
3069 dprintk("--> nfs4_referral_get_sb()\n");
3070
Trond Myklebust4f727292010-04-16 16:22:48 -04003071 mntfh = nfs_alloc_fhandle();
3072 if (mntfh == NULL)
3073 goto out_err_nofh;
3074
David Howells54ceac42006-08-22 20:06:13 -04003075 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003076 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003077 if (IS_ERR(server)) {
3078 error = PTR_ERR(server);
3079 goto out_err_noserver;
3080 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003081 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003082
Trond Myklebust75180df2007-05-16 16:53:28 -04003083 if (server->flags & NFS4_MOUNT_UNSHARED)
3084 compare_super = NULL;
3085
David Howells54ceac42006-08-22 20:06:13 -04003086 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003087 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003088 if (IS_ERR(s)) {
3089 error = PTR_ERR(s);
3090 goto out_err_nosb;
3091 }
3092
3093 if (s->s_fs_info != server) {
3094 nfs_free_server(server);
3095 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003096 } else {
3097 error = nfs_bdi_register(server);
3098 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003099 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003100 }
3101
3102 if (!s->s_root) {
3103 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003104 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003105 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003106 }
3107
Trond Myklebust4f727292010-04-16 16:22:48 -04003108 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003109 if (IS_ERR(mntroot)) {
3110 error = PTR_ERR(mntroot);
3111 goto error_splat_super;
3112 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003113 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3114 dput(mntroot);
3115 error = -ESTALE;
3116 goto error_splat_super;
3117 }
David Howells54ceac42006-08-22 20:06:13 -04003118
3119 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003120
Eric Paris46c8ac72008-05-02 13:42:42 -07003121 security_sb_clone_mnt_opts(data->sb, s);
3122
Trond Myklebust4f727292010-04-16 16:22:48 -04003123 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003124 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003125 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003126
3127out_err_nosb:
3128 nfs_free_server(server);
3129out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003130 nfs_free_fhandle(mntfh);
3131out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003132 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003133 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003134
3135error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003136 if (server && !s->s_root)
3137 bdi_unregister(&server->backing_dev_info);
3138error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003139 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003140 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003141 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003142 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003143}
3144
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003145/*
3146 * Create an NFS4 server record on referral traversal
3147 */
3148static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3149 int flags, const char *dev_name, void *raw_data,
3150 struct vfsmount *mnt)
3151{
3152 struct nfs_clone_mount *data = raw_data;
3153 char *export_path;
3154 struct vfsmount *root_mnt;
3155 int error;
3156
3157 dprintk("--> nfs4_referral_get_sb()\n");
3158
3159 export_path = data->mnt_path;
3160 data->mnt_path = "/";
3161
3162 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3163 flags, data, data->hostname);
3164 data->mnt_path = export_path;
3165
3166 error = PTR_ERR(root_mnt);
3167 if (IS_ERR(root_mnt))
3168 goto out;
3169
3170 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3171out:
3172 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3173 error != 0 ? " [error]" : "");
3174 return error;
3175}
3176
David Howells54ceac42006-08-22 20:06:13 -04003177#endif /* CONFIG_NFS_V4 */