blob: 7e13e1a6b3918a11bb26b9ce63db70dbf332d105 [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 Myklebust7973c1f12008-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 Myklebust7973c1f12008-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 Myklebust7973c1f12008-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 Myklebust7973c1f12008-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);
Stanislav Kinsburskyaa699472010-12-08 12:40:13 +0300601 if ((nfss->mountd_port &&
602 nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
603 showdefaults)
Chuck Lever82d101d2008-03-14 14:10:37 -0400604 seq_printf(m, ",mountport=%u", nfss->mountd_port);
605
Jeff Laytonee671b02009-12-03 15:58:56 -0500606 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400607}
608
Trond Myklebust0be81892010-06-18 12:23:58 -0400609#ifdef CONFIG_NFS_V4
610static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
611 int showdefaults)
612{
613 struct nfs_client *clp = nfss->nfs_client;
614
615 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
616 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
617}
618#else
619static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
620 int showdefaults)
621{
622}
623#endif
624
David Howellsf7b422b2006-06-09 09:34:33 -0400625/*
626 * Describe the mount options in force on this server representation
627 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400628static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
629 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400630{
David Howells509de812006-08-22 20:06:11 -0400631 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400632 int flag;
David Howells509de812006-08-22 20:06:11 -0400633 const char *str;
634 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400635 } nfs_info[] = {
636 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400637 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400638 { NFS_MOUNT_NOCTO, ",nocto", "" },
639 { NFS_MOUNT_NOAC, ",noac", "" },
640 { NFS_MOUNT_NONLM, ",nolock", "" },
641 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400642 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500643 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
644 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400645 { 0, NULL, NULL }
646 };
David Howells509de812006-08-22 20:06:11 -0400647 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400648 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400649 u32 version = clp->rpc_ops->version;
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400650 int local_flock, local_fcntl;
David Howellsf7b422b2006-06-09 09:34:33 -0400651
Chuck Lever82d101d2008-03-14 14:10:37 -0400652 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400653 seq_printf(m, ",rsize=%u", nfss->rsize);
654 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400655 if (nfss->bsize != 0)
656 seq_printf(m, ",bsize=%u", nfss->bsize);
657 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400658 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400659 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400660 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400661 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400662 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400663 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400664 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400665 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400666 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
667 if (nfss->flags & nfs_infop->flag)
668 seq_puts(m, nfs_infop->str);
669 else
670 seq_puts(m, nfs_infop->nostr);
671 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400672 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500673 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400674 if (version == 4) {
675 if (nfss->port != NFS_PORT)
676 seq_printf(m, ",port=%u", nfss->port);
677 } else
678 if (nfss->port)
679 seq_printf(m, ",port=%u", nfss->port);
680
Trond Myklebust33170232007-12-20 16:03:59 -0500681 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
682 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400683 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400684
685 if (version != 4)
686 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400687 else
688 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400689
David Howellsb797cac2009-04-03 16:42:48 +0100690 if (nfss->options & NFS_OPTION_FSCACHE)
691 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400692
693 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
694 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
695 seq_printf(m, ",lookupcache=none");
696 else
697 seq_printf(m, ",lookupcache=pos");
698 }
Suresh Jayaraman7c563cc2010-09-23 14:26:48 -0400699
700 local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
701 local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
702
703 if (!local_flock && !local_fcntl)
704 seq_printf(m, ",local_lock=none");
705 else if (local_flock && local_fcntl)
706 seq_printf(m, ",local_lock=all");
707 else if (local_flock)
708 seq_printf(m, ",local_lock=flock");
709 else
710 seq_printf(m, ",local_lock=posix");
David Howellsf7b422b2006-06-09 09:34:33 -0400711}
712
713/*
714 * Describe the mount options on this VFS mountpoint
715 */
716static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
717{
718 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
719
720 nfs_show_mount_options(m, nfss, 0);
721
Chuck Lever5d8515c2007-12-10 14:57:16 -0500722 seq_printf(m, ",addr=%s",
723 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
724 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400725
726 return 0;
727}
728
729/*
730 * Present statistical information for this VFS mountpoint
731 */
732static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
733{
734 int i, cpu;
735 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
736 struct rpc_auth *auth = nfss->client->cl_auth;
737 struct nfs_iostats totals = { };
738
739 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
740
741 /*
742 * Display all mount option settings
743 */
744 seq_printf(m, "\n\topts:\t");
745 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
746 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
747 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
748 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
749 nfs_show_mount_options(m, nfss, 1);
750
751 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
752
753 seq_printf(m, "\n\tcaps:\t");
754 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400755 seq_printf(m, ",wtmult=%u", nfss->wtmult);
756 seq_printf(m, ",dtsize=%u", nfss->dtsize);
757 seq_printf(m, ",bsize=%u", nfss->bsize);
758 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400759
760#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500761 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400762 seq_printf(m, "\n\tnfsv4:\t");
763 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
764 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
765 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
766 }
767#endif
768
769 /*
770 * Display security flavor in effect for this mount
771 */
Chuck Lever2d767432008-03-14 14:10:08 -0400772 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400773 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400774 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400775
776 /*
777 * Display superblock I/O counters
778 */
779 for_each_possible_cpu(cpu) {
780 struct nfs_iostats *stats;
781
782 preempt_disable();
783 stats = per_cpu_ptr(nfss->io_stats, cpu);
784
785 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
786 totals.events[i] += stats->events[i];
787 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
788 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100789#ifdef CONFIG_NFS_FSCACHE
790 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
791 totals.fscache[i] += stats->fscache[i];
792#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400793
794 preempt_enable();
795 }
796
797 seq_printf(m, "\n\tevents:\t");
798 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
799 seq_printf(m, "%lu ", totals.events[i]);
800 seq_printf(m, "\n\tbytes:\t");
801 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
802 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100803#ifdef CONFIG_NFS_FSCACHE
804 if (nfss->options & NFS_OPTION_FSCACHE) {
805 seq_printf(m, "\n\tfsc:\t");
806 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
807 seq_printf(m, "%Lu ", totals.bytes[i]);
808 }
809#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400810 seq_printf(m, "\n");
811
812 rpc_print_iostats(m, nfss->client);
813
814 return 0;
815}
816
817/*
818 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400819 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400820 */
Al Viro42faad92008-04-24 07:21:56 -0400821static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400822{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200823 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400824 struct rpc_clnt *rpc;
825
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200826 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400827 /* -EIO all pending I/O */
828 rpc = server->client_acl;
829 if (!IS_ERR(rpc))
830 rpc_killall_tasks(rpc);
831 rpc = server->client;
832 if (!IS_ERR(rpc))
833 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400834}
835
Trond Myklebustc5811db2009-10-06 15:40:15 -0400836static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400837{
838 struct nfs_parsed_mount_data *data;
839
840 data = kzalloc(sizeof(*data), GFP_KERNEL);
841 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400842 data->acregmin = NFS_DEF_ACREGMIN;
843 data->acregmax = NFS_DEF_ACREGMAX;
844 data->acdirmin = NFS_DEF_ACDIRMIN;
845 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400846 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400847 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400848 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400849 data->auth_flavors[0] = RPC_AUTH_UNIX;
850 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400851 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400852 data->minorversion = 0;
853 }
854 return data;
855}
856
David Howellsf7b422b2006-06-09 09:34:33 -0400857/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500858 * Sanity-check a server address provided by the mount command.
859 *
860 * Address family must be initialized, and address must not be
861 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400862 */
863static int nfs_verify_server_address(struct sockaddr *addr)
864{
865 switch (addr->sa_family) {
866 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500867 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700868 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500869 }
870 case AF_INET6: {
871 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
872 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400873 }
874 }
875
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400876 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400877 return 0;
878}
879
Chuck Lever9412b922007-12-10 14:59:21 -0500880/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400881 * Select between a default port value and a user-specified port value.
882 * If a zero value is set, then autobind will be used.
883 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400884static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400885 const unsigned short default_port)
886{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400887 if (*port == NFS_UNSPEC_PORT)
888 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400889
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400890 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400891}
892
893/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400894 * Sanity check the NFS transport protocol.
895 *
896 */
897static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
898{
899 switch (mnt->nfs_server.protocol) {
900 case XPRT_TRANSPORT_UDP:
901 case XPRT_TRANSPORT_TCP:
902 case XPRT_TRANSPORT_RDMA:
903 break;
904 default:
905 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
906 }
907}
908
909/*
910 * For text based NFSv2/v3 mounts, the mount protocol transport default
911 * settings should depend upon the specified NFS transport.
912 */
913static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
914{
915 nfs_validate_transport_protocol(mnt);
916
917 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
918 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
919 return;
920 switch (mnt->nfs_server.protocol) {
921 case XPRT_TRANSPORT_UDP:
922 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
923 break;
924 case XPRT_TRANSPORT_TCP:
925 case XPRT_TRANSPORT_RDMA:
926 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
927 }
928}
929
930/*
Chuck Lever01060c82008-06-24 16:33:38 -0400931 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400932 */
933static int nfs_parse_security_flavors(char *value,
934 struct nfs_parsed_mount_data *mnt)
935{
936 substring_t args[MAX_OPT_ARGS];
937
938 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
939
940 switch (match_token(value, nfs_secflavor_tokens, args)) {
941 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400942 mnt->auth_flavors[0] = RPC_AUTH_NULL;
943 break;
944 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400945 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
946 break;
947 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400948 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
949 break;
950 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400951 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
952 break;
953 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400954 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
955 break;
956 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400957 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
958 break;
959 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400960 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
961 break;
962 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400963 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
964 break;
965 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400966 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
967 break;
968 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400969 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
970 break;
971 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400972 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
973 break;
974 default:
975 return 0;
976 }
977
Chuck Lever059f90b2009-08-09 15:09:31 -0400978 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400979 return 1;
980}
981
Rob Landleyc5cb09b2011-03-09 16:02:37 -0600982static int nfs_get_option_str(substring_t args[], char **option)
983{
984 kfree(*option);
985 *option = match_strdup(args);
986 return !option;
987}
988
989static int nfs_get_option_ul(substring_t args[], unsigned long *option)
990{
991 int rc;
992 char *string;
993
994 string = match_strdup(args);
995 if (string == NULL)
996 return -ENOMEM;
997 rc = strict_strtoul(string, 10, option);
998 kfree(string);
999
1000 return rc;
1001}
1002
Chuck Lever01060c82008-06-24 16:33:38 -04001003/*
Chuck Leverbf0fd762007-07-01 12:13:44 -04001004 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -04001005 * a data structure. The whole mount string is processed; bad options are
1006 * skipped as they are encountered. If there were no errors, return 1;
1007 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -04001008 */
1009static int nfs_parse_mount_options(char *raw,
1010 struct nfs_parsed_mount_data *mnt)
1011{
Eric Parisf9c3a382008-03-05 14:20:18 -05001012 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001013 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -05001014 unsigned short protofamily = AF_UNSPEC;
1015 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001016
1017 if (!raw) {
1018 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
1019 return 1;
1020 }
1021 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
1022
Eric Parisf9c3a382008-03-05 14:20:18 -05001023 secdata = alloc_secdata();
1024 if (!secdata)
1025 goto out_nomem;
1026
1027 rc = security_sb_copy_data(raw, secdata);
1028 if (rc)
1029 goto out_security_failure;
1030
1031 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
1032 if (rc)
1033 goto out_security_failure;
1034
1035 free_secdata(secdata);
1036
Chuck Leverbf0fd762007-07-01 12:13:44 -04001037 while ((p = strsep(&raw, ",")) != NULL) {
1038 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -07001039 unsigned long option;
1040 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001041
1042 if (!*p)
1043 continue;
1044
1045 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
1046
1047 token = match_token(p, nfs_mount_option_tokens, args);
1048 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001049
1050 /*
1051 * boolean options: foo/nofoo
1052 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001053 case Opt_soft:
1054 mnt->flags |= NFS_MOUNT_SOFT;
1055 break;
1056 case Opt_hard:
1057 mnt->flags &= ~NFS_MOUNT_SOFT;
1058 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001059 case Opt_posix:
1060 mnt->flags |= NFS_MOUNT_POSIX;
1061 break;
1062 case Opt_noposix:
1063 mnt->flags &= ~NFS_MOUNT_POSIX;
1064 break;
1065 case Opt_cto:
1066 mnt->flags &= ~NFS_MOUNT_NOCTO;
1067 break;
1068 case Opt_nocto:
1069 mnt->flags |= NFS_MOUNT_NOCTO;
1070 break;
1071 case Opt_ac:
1072 mnt->flags &= ~NFS_MOUNT_NOAC;
1073 break;
1074 case Opt_noac:
1075 mnt->flags |= NFS_MOUNT_NOAC;
1076 break;
1077 case Opt_lock:
1078 mnt->flags &= ~NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001079 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1080 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001081 break;
1082 case Opt_nolock:
1083 mnt->flags |= NFS_MOUNT_NONLM;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001084 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1085 NFS_MOUNT_LOCAL_FCNTL);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001086 break;
1087 case Opt_v2:
1088 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001089 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001090 break;
1091 case Opt_v3:
1092 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001093 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001094 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001095 case Opt_v4:
1096 mnt->flags &= ~NFS_MOUNT_VER3;
1097 mnt->version = 4;
1098 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001099 case Opt_udp:
1100 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001101 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001102 break;
1103 case Opt_tcp:
1104 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001105 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001106 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001107 case Opt_rdma:
1108 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1109 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001110 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001111 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001112 case Opt_acl:
1113 mnt->flags &= ~NFS_MOUNT_NOACL;
1114 break;
1115 case Opt_noacl:
1116 mnt->flags |= NFS_MOUNT_NOACL;
1117 break;
1118 case Opt_rdirplus:
1119 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1120 break;
1121 case Opt_nordirplus:
1122 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1123 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001124 case Opt_sharecache:
1125 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1126 break;
1127 case Opt_nosharecache:
1128 mnt->flags |= NFS_MOUNT_UNSHARED;
1129 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001130 case Opt_resvport:
1131 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1132 break;
1133 case Opt_noresvport:
1134 mnt->flags |= NFS_MOUNT_NORESVPORT;
1135 break;
David Howellsb797cac2009-04-03 16:42:48 +01001136 case Opt_fscache:
1137 mnt->options |= NFS_OPTION_FSCACHE;
1138 kfree(mnt->fscache_uniq);
1139 mnt->fscache_uniq = NULL;
1140 break;
1141 case Opt_nofscache:
1142 mnt->options &= ~NFS_OPTION_FSCACHE;
1143 kfree(mnt->fscache_uniq);
1144 mnt->fscache_uniq = NULL;
1145 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001146
Chuck Leverf45663c2008-06-24 19:28:02 -04001147 /*
1148 * options that take numeric values
1149 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001150 case Opt_port:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001151 if (nfs_get_option_ul(args, &option) ||
1152 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001153 goto out_invalid_value;
1154 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001155 break;
1156 case Opt_rsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001157 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001158 goto out_invalid_value;
1159 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160 break;
1161 case Opt_wsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001162 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001163 goto out_invalid_value;
1164 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 break;
1166 case Opt_bsize:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001167 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001168 goto out_invalid_value;
1169 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 break;
1171 case Opt_timeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001172 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001173 goto out_invalid_value;
1174 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001175 break;
1176 case Opt_retrans:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001177 if (nfs_get_option_ul(args, &option) || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001178 goto out_invalid_value;
1179 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 break;
1181 case Opt_acregmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001182 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001183 goto out_invalid_value;
1184 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001185 break;
1186 case Opt_acregmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001187 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001188 goto out_invalid_value;
1189 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001190 break;
1191 case Opt_acdirmin:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001192 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001193 goto out_invalid_value;
1194 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001195 break;
1196 case Opt_acdirmax:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001197 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001198 goto out_invalid_value;
1199 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 break;
1201 case Opt_actimeo:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001202 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001203 goto out_invalid_value;
1204 mnt->acregmin = mnt->acregmax =
1205 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001206 break;
1207 case Opt_namelen:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001208 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001209 goto out_invalid_value;
1210 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001211 break;
1212 case Opt_mountport:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001213 if (nfs_get_option_ul(args, &option) ||
1214 option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001215 goto out_invalid_value;
1216 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001217 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001218 case Opt_mountvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001219 if (nfs_get_option_ul(args, &option) ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001220 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001221 option > NFS_MNT3_VERSION)
1222 goto out_invalid_value;
1223 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001224 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 case Opt_nfsvers:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001226 if (nfs_get_option_ul(args, &option))
Chuck Leverd23c45f2009-06-17 18:02:13 -07001227 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001228 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001229 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001231 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001233 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001234 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001235 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001237 case NFS4_VERSION:
1238 mnt->flags &= ~NFS_MOUNT_VER3;
1239 mnt->version = 4;
1240 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001241 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001242 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001243 }
1244 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001245 case Opt_minorversion:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001246 if (nfs_get_option_ul(args, &option))
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001247 goto out_invalid_value;
1248 if (option > NFS4_MAX_MINOR_VERSION)
1249 goto out_invalid_value;
1250 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001251 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252
Chuck Leverf45663c2008-06-24 19:28:02 -04001253 /*
1254 * options that take text values
1255 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001256 case Opt_sec:
1257 string = match_strdup(args);
1258 if (string == NULL)
1259 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001260 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001262 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001263 dfprintk(MOUNT, "NFS: unrecognized "
1264 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001265 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001266 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 break;
1268 case Opt_proto:
1269 string = match_strdup(args);
1270 if (string == NULL)
1271 goto out_nomem;
1272 token = match_token(string,
1273 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001274
Jeff Laytonee671b02009-12-03 15:58:56 -05001275 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001276 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001277 case Opt_xprt_udp6:
1278 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001279 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001280 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001281 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001282 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001283 case Opt_xprt_tcp6:
1284 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001285 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001286 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001287 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001288 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001289 case Opt_xprt_rdma:
1290 /* vector side protocols to TCP */
1291 mnt->flags |= NFS_MOUNT_TCP;
1292 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001293 xprt_load_transport(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001294 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001296 dfprintk(MOUNT, "NFS: unrecognized "
1297 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001298 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001299 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001300 }
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001301 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001302 break;
1303 case Opt_mountproto:
1304 string = match_strdup(args);
1305 if (string == NULL)
1306 goto out_nomem;
1307 token = match_token(string,
1308 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001309 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001310
Jeff Laytonee671b02009-12-03 15:58:56 -05001311 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001313 case Opt_xprt_udp6:
1314 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001315 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001316 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001318 case Opt_xprt_tcp6:
1319 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001320 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001321 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001323 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001324 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001325 dfprintk(MOUNT, "NFS: unrecognized "
1326 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001327 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001328 }
1329 break;
1330 case Opt_addr:
1331 string = match_strdup(args);
1332 if (string == NULL)
1333 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001334 mnt->nfs_server.addrlen =
1335 rpc_pton(string, strlen(string),
1336 (struct sockaddr *)
1337 &mnt->nfs_server.address,
1338 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001339 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001340 if (mnt->nfs_server.addrlen == 0)
1341 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001342 break;
1343 case Opt_clientaddr:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001344 if (nfs_get_option_str(args, &mnt->client_address))
Chuck Leverbf0fd762007-07-01 12:13:44 -04001345 goto out_nomem;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001346 break;
Chuck Lever33832032007-12-10 14:59:13 -05001347 case Opt_mounthost:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001348 if (nfs_get_option_str(args,
1349 &mnt->mount_server.hostname))
Chuck Lever33832032007-12-10 14:59:13 -05001350 goto out_nomem;
Chuck Lever33832032007-12-10 14:59:13 -05001351 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001352 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001353 string = match_strdup(args);
1354 if (string == NULL)
1355 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001356 mnt->mount_server.addrlen =
1357 rpc_pton(string, strlen(string),
1358 (struct sockaddr *)
1359 &mnt->mount_server.address,
1360 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001361 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001362 if (mnt->mount_server.addrlen == 0)
1363 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001364 break;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001365 case Opt_lookupcache:
1366 string = match_strdup(args);
1367 if (string == NULL)
1368 goto out_nomem;
1369 token = match_token(string,
1370 nfs_lookupcache_tokens, args);
1371 kfree(string);
1372 switch (token) {
1373 case Opt_lookupcache_all:
1374 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1375 break;
1376 case Opt_lookupcache_positive:
1377 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1378 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1379 break;
1380 case Opt_lookupcache_none:
1381 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1382 break;
1383 default:
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001384 dfprintk(MOUNT, "NFS: invalid "
1385 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001386 return 0;
Trond Myklebust7973c1f12008-07-15 17:58:14 -04001387 };
1388 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001389 case Opt_fscache_uniq:
Rob Landleyc5cb09b2011-03-09 16:02:37 -06001390 if (nfs_get_option_str(args, &mnt->fscache_uniq))
Chuck Levera6d5ff62010-05-07 13:33:58 -04001391 goto out_nomem;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001392 mnt->options |= NFS_OPTION_FSCACHE;
1393 break;
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001394 case Opt_local_lock:
1395 string = match_strdup(args);
1396 if (string == NULL)
1397 goto out_nomem;
1398 token = match_token(string, nfs_local_lock_tokens,
1399 args);
1400 kfree(string);
1401 switch (token) {
1402 case Opt_local_lock_all:
1403 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1404 NFS_MOUNT_LOCAL_FCNTL);
1405 break;
1406 case Opt_local_lock_flock:
1407 mnt->flags |= NFS_MOUNT_LOCAL_FLOCK;
1408 break;
1409 case Opt_local_lock_posix:
1410 mnt->flags |= NFS_MOUNT_LOCAL_FCNTL;
1411 break;
1412 case Opt_local_lock_none:
1413 mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK |
1414 NFS_MOUNT_LOCAL_FCNTL);
1415 break;
1416 default:
1417 dfprintk(MOUNT, "NFS: invalid "
1418 "local_lock argument\n");
1419 return 0;
1420 };
1421 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001422
Chuck Leverf45663c2008-06-24 19:28:02 -04001423 /*
1424 * Special options
1425 */
1426 case Opt_sloppy:
1427 sloppy = 1;
1428 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1429 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001430 case Opt_userspace:
1431 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001432 dfprintk(MOUNT, "NFS: ignoring mount option "
1433 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001434 break;
1435
1436 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001437 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001438 dfprintk(MOUNT, "NFS: unrecognized mount option "
1439 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001440 }
1441 }
1442
Chuck Leverd23c45f2009-06-17 18:02:13 -07001443 if (!sloppy && invalid_option)
1444 return 0;
1445
Jeff Laytonee671b02009-12-03 15:58:56 -05001446 /*
1447 * verify that any proto=/mountproto= options match the address
1448 * familiies in the addr=/mountaddr= options.
1449 */
1450 if (protofamily != AF_UNSPEC &&
1451 protofamily != mnt->nfs_server.address.ss_family)
1452 goto out_proto_mismatch;
1453
1454 if (mountfamily != AF_UNSPEC) {
1455 if (mnt->mount_server.addrlen) {
1456 if (mountfamily != mnt->mount_server.address.ss_family)
1457 goto out_mountproto_mismatch;
1458 } else {
1459 if (mountfamily != mnt->nfs_server.address.ss_family)
1460 goto out_mountproto_mismatch;
1461 }
1462 }
1463
Chuck Leverbf0fd762007-07-01 12:13:44 -04001464 return 1;
1465
Jeff Laytonee671b02009-12-03 15:58:56 -05001466out_mountproto_mismatch:
1467 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1468 "option\n");
1469 return 0;
1470out_proto_mismatch:
1471 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1472 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001473out_invalid_address:
1474 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1475 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001476out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001477 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001478 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001479out_nomem:
1480 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1481 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001482out_security_failure:
1483 free_secdata(secdata);
1484 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1485 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001486}
1487
1488/*
Chuck Leverec88f282009-08-09 15:09:32 -04001489 * Match the requested auth flavors with the list returned by
1490 * the server. Returns zero and sets the mount's authentication
1491 * flavor on success; returns -EACCES if server does not support
1492 * the requested flavor.
1493 */
1494static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1495 struct nfs_mount_request *request)
1496{
1497 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1498
1499 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001500 * Certain releases of Linux's mountd return an empty
1501 * flavor list. To prevent behavioral regression with
1502 * these servers (ie. rejecting mounts that used to
1503 * succeed), revert to pre-2.6.32 behavior (no checking)
1504 * if the returned flavor list is empty.
1505 */
1506 if (server_authlist_len == 0)
1507 return 0;
1508
1509 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001510 * We avoid sophisticated negotiating here, as there are
1511 * plenty of cases where we can get it wrong, providing
1512 * either too little or too much security.
1513 *
1514 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1515 * flavor listed first. However, some servers list
1516 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1517 * preferred default, in args->auth_flavors[0] if user
1518 * didn't specify sec= mount option.
1519 */
1520 for (i = 0; i < args->auth_flavor_len; i++)
1521 for (j = 0; j < server_authlist_len; j++)
1522 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1523 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1524 request->auth_flavs[j]);
1525 args->auth_flavors[0] = request->auth_flavs[j];
1526 return 0;
1527 }
1528
1529 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1530 nfs_umount(request);
1531 return -EACCES;
1532}
1533
1534/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001535 * Use the remote server's MOUNT service to request the NFS file handle
1536 * corresponding to the provided path.
1537 */
1538static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1539 struct nfs_fh *root_fh)
1540{
Chuck Leverec88f282009-08-09 15:09:32 -04001541 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1542 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001543 struct nfs_mount_request request = {
1544 .sap = (struct sockaddr *)
1545 &args->mount_server.address,
1546 .dirpath = args->nfs_server.export_path,
1547 .protocol = args->mount_server.protocol,
1548 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001549 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001550 .auth_flav_len = &server_authlist_len,
1551 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001552 };
Chuck Lever4c568012007-12-10 14:59:28 -05001553 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001554
1555 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001556 switch (args->version) {
1557 default:
1558 args->mount_server.version = NFS_MNT3_VERSION;
1559 break;
1560 case 2:
1561 args->mount_server.version = NFS_MNT_VERSION;
1562 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001563 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001564 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001565
Chuck Lever33832032007-12-10 14:59:13 -05001566 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001567 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001568 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001569 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001570
Chuck Lever0076d7b2007-07-01 12:13:49 -04001571 /*
1572 * Construct the mount server's address.
1573 */
Chuck Lever4c568012007-12-10 14:59:28 -05001574 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001575 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001576 args->nfs_server.addrlen);
1577 args->mount_server.addrlen = args->nfs_server.addrlen;
1578 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001579 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001580 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001581
1582 /*
1583 * Now ask the mount server to map our export path
1584 * to a file handle.
1585 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001586 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001587 if (status != 0) {
1588 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1589 request.hostname, status);
1590 return status;
1591 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001592
Chuck Leverec88f282009-08-09 15:09:32 -04001593 /*
1594 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1595 */
1596 if (args->mount_server.version != NFS_MNT3_VERSION)
1597 return 0;
1598 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001599}
1600
Rob Landleyc12bace2011-03-09 15:54:13 -06001601/*
1602 * Split "dev_name" into "hostname:export_path".
1603 *
1604 * The leftmost colon demarks the split between the server's hostname
1605 * and the export path. If the hostname starts with a left square
1606 * bracket, then it may contain colons.
1607 *
1608 * Note: caller frees hostname and export path, even on error.
1609 */
1610static int nfs_parse_devname(const char *dev_name,
1611 char **hostname, size_t maxnamlen,
1612 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001613{
1614 size_t len;
Rob Landleyc12bace2011-03-09 15:54:13 -06001615 char *end;
Chuck Leverdc045892008-06-23 12:36:37 -04001616
Rob Landleyc12bace2011-03-09 15:54:13 -06001617 /* Is the host name protected with square brakcets? */
1618 if (*dev_name == '[') {
1619 end = strchr(++dev_name, ']');
1620 if (end == NULL || end[1] != ':')
1621 goto out_bad_devname;
Chuck Leverdc045892008-06-23 12:36:37 -04001622
Rob Landleyc12bace2011-03-09 15:54:13 -06001623 len = end - dev_name;
1624 end++;
1625 } else {
1626 char *comma;
1627
1628 end = strchr(dev_name, ':');
1629 if (end == NULL)
1630 goto out_bad_devname;
1631 len = end - dev_name;
1632
1633 /* kill possible hostname list: not supported */
1634 comma = strchr(dev_name, ',');
1635 if (comma != NULL && comma < end)
1636 *comma = 0;
1637 }
1638
Chuck Leverdc045892008-06-23 12:36:37 -04001639 if (len > maxnamlen)
1640 goto out_hostname;
1641
1642 /* N.B. caller will free nfs_server.hostname in all cases */
1643 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
Rob Landleyc12bace2011-03-09 15:54:13 -06001644 if (*hostname == NULL)
Chuck Leverdc045892008-06-23 12:36:37 -04001645 goto out_nomem;
Rob Landleyc12bace2011-03-09 15:54:13 -06001646 len = strlen(++end);
Chuck Leverdc045892008-06-23 12:36:37 -04001647 if (len > maxpathlen)
1648 goto out_path;
Rob Landleyc12bace2011-03-09 15:54:13 -06001649 *export_path = kstrndup(end, len, GFP_KERNEL);
Chuck Leverdc045892008-06-23 12:36:37 -04001650 if (!*export_path)
1651 goto out_nomem;
1652
1653 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1654 return 0;
1655
1656out_bad_devname:
1657 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1658 return -EINVAL;
1659
1660out_nomem:
1661 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1662 return -ENOMEM;
1663
1664out_hostname:
1665 dfprintk(MOUNT, "NFS: server hostname too long\n");
1666 return -ENAMETOOLONG;
1667
1668out_path:
1669 dfprintk(MOUNT, "NFS: export pathname too long\n");
1670 return -ENAMETOOLONG;
1671}
1672
1673/*
David Howells54ceac42006-08-22 20:06:13 -04001674 * Validate the NFS2/NFS3 mount data
1675 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001676 *
1677 * For option strings, user space handles the following behaviors:
1678 *
1679 * + DNS: mapping server host name to IP address ("addr=" option)
1680 *
1681 * + failure mode: how to behave if a mount request can't be handled
1682 * immediately ("fg/bg" option)
1683 *
1684 * + retry: how often to retry a mount request ("retry=" option)
1685 *
1686 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1687 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001688 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001689static int nfs_validate_mount_data(void *options,
1690 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001691 struct nfs_fh *mntfh,
1692 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001693{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001694 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001695 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001696
Chuck Lever5df36e72007-07-01 12:12:56 -04001697 if (data == NULL)
1698 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001699
David Howellsf7b422b2006-06-09 09:34:33 -04001700 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001701 case 1:
1702 data->namlen = 0;
1703 case 2:
1704 data->bsize = 0;
1705 case 3:
1706 if (data->flags & NFS_MOUNT_VER3)
1707 goto out_no_v3;
1708 data->root.size = NFS2_FHSIZE;
1709 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1710 case 4:
1711 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1712 goto out_no_sec;
1713 case 5:
1714 memset(data->context, 0, sizeof(data->context));
1715 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001716 if (data->flags & NFS_MOUNT_VER3) {
1717 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1718 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001719 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001720 args->version = 3;
1721 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001722 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001723 args->version = 2;
1724 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001725
Chuck Lever5df36e72007-07-01 12:12:56 -04001726
1727 memcpy(mntfh->data, data->root.data, mntfh->size);
1728 if (mntfh->size < sizeof(mntfh->data))
1729 memset(mntfh->data + mntfh->size, 0,
1730 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001731
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001732 /*
1733 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1734 * can deal with.
1735 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001736 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001737 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001738 args->rsize = data->rsize;
1739 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001740 args->timeo = data->timeo;
1741 args->retrans = data->retrans;
1742 args->acregmin = data->acregmin;
1743 args->acregmax = data->acregmax;
1744 args->acdirmin = data->acdirmin;
1745 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001746
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001747 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001748 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001749 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001750 goto out_no_address;
1751
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001752 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001753 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001754 /* N.B. caller will free nfs_server.hostname in all cases */
1755 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1756 args->namlen = data->namlen;
1757 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001758
1759 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1760 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001761 if (!args->nfs_server.hostname)
1762 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001763
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04001764 if (!(data->flags & NFS_MOUNT_NONLM))
1765 args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK|
1766 NFS_MOUNT_LOCAL_FCNTL);
1767 else
1768 args->flags |= (NFS_MOUNT_LOCAL_FLOCK|
1769 NFS_MOUNT_LOCAL_FCNTL);
Eric Parisf9c3a382008-03-05 14:20:18 -05001770 /*
1771 * The legacy version 6 binary mount data from userspace has a
1772 * field used only to transport selinux information into the
1773 * the kernel. To continue to support that functionality we
1774 * have a touch of selinux knowledge here in the NFS code. The
1775 * userspace code converted context=blah to just blah so we are
1776 * converting back to the full string selinux understands.
1777 */
1778 if (data->context[0]){
1779#ifdef CONFIG_SECURITY_SELINUX
1780 int rc;
1781 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1782 if (!opts_str)
1783 return -ENOMEM;
1784 strcpy(opts_str, "context=");
1785 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1786 strcat(opts_str, &data->context[0]);
1787 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1788 kfree(opts_str);
1789 if (rc)
1790 return rc;
1791#else
1792 return -EINVAL;
1793#endif
1794 }
1795
Chuck Lever5df36e72007-07-01 12:12:56 -04001796 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001797 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001798 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001799
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001800 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001801 return -EINVAL;
1802
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001803 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001804 goto out_no_address;
1805
Chuck Lever764302c2009-09-08 19:50:03 -04001806 if (args->version == 4)
1807#ifdef CONFIG_NFS_V4
1808 return nfs4_validate_text_mount_data(options,
1809 args, dev_name);
1810#else
1811 goto out_v4_not_compiled;
1812#endif
1813
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001814 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001815
Trond Myklebust259875e2008-07-02 14:43:47 -04001816 nfs_set_mount_transport_protocol(args);
1817
Chuck Leverdc045892008-06-23 12:36:37 -04001818 status = nfs_parse_devname(dev_name,
1819 &args->nfs_server.hostname,
1820 PAGE_SIZE,
1821 &args->nfs_server.export_path,
1822 NFS_MAXPATHLEN);
1823 if (!status)
1824 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001825
Chuck Leverdc045892008-06-23 12:36:37 -04001826 kfree(args->nfs_server.export_path);
1827 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001828
Chuck Lever136d5582007-07-01 12:13:54 -04001829 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001830 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001831
Chuck Lever136d5582007-07-01 12:13:54 -04001832 break;
1833 }
David Howellsf7b422b2006-06-09 09:34:33 -04001834 }
David Howells54ceac42006-08-22 20:06:13 -04001835
David Howellsf7b422b2006-06-09 09:34:33 -04001836#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001837 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001838 goto out_v3_not_compiled;
1839#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001840
David Howells54ceac42006-08-22 20:06:13 -04001841 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001842
1843out_no_data:
1844 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1845 return -EINVAL;
1846
1847out_no_v3:
1848 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1849 data->version);
1850 return -EINVAL;
1851
1852out_no_sec:
1853 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1854 return -EINVAL;
1855
Chuck Lever5df36e72007-07-01 12:12:56 -04001856#ifndef CONFIG_NFS_V3
1857out_v3_not_compiled:
1858 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1859 return -EPROTONOSUPPORT;
1860#endif /* !CONFIG_NFS_V3 */
1861
Chuck Lever764302c2009-09-08 19:50:03 -04001862#ifndef CONFIG_NFS_V4
1863out_v4_not_compiled:
1864 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1865 return -EPROTONOSUPPORT;
1866#endif /* !CONFIG_NFS_V4 */
1867
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001868out_nomem:
1869 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1870 return -ENOMEM;
1871
Chuck Lever5df36e72007-07-01 12:12:56 -04001872out_no_address:
1873 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1874 return -EINVAL;
1875
1876out_invalid_fh:
1877 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1878 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001879}
1880
Jeff Layton48b605f2008-06-10 15:38:39 -04001881static int
1882nfs_compare_remount_data(struct nfs_server *nfss,
1883 struct nfs_parsed_mount_data *data)
1884{
1885 if (data->flags != nfss->flags ||
1886 data->rsize != nfss->rsize ||
1887 data->wsize != nfss->wsize ||
1888 data->retrans != nfss->client->cl_timeout->to_retries ||
1889 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1890 data->acregmin != nfss->acregmin / HZ ||
1891 data->acregmax != nfss->acregmax / HZ ||
1892 data->acdirmin != nfss->acdirmin / HZ ||
1893 data->acdirmax != nfss->acdirmax / HZ ||
1894 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001895 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001896 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04001897 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1898 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04001899 return -EINVAL;
1900
1901 return 0;
1902}
1903
1904static int
1905nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1906{
1907 int error;
1908 struct nfs_server *nfss = sb->s_fs_info;
1909 struct nfs_parsed_mount_data *data;
1910 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1911 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001912 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001913
1914 /*
1915 * Userspace mount programs that send binary options generally send
1916 * them populated with default values. We have no way to know which
1917 * ones were explicitly specified. Fall back to legacy behavior and
1918 * just return success.
1919 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001920 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1921 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1922 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001923 return 0;
1924
1925 data = kzalloc(sizeof(*data), GFP_KERNEL);
1926 if (data == NULL)
1927 return -ENOMEM;
1928
1929 /* fill out struct with values from existing mount */
1930 data->flags = nfss->flags;
1931 data->rsize = nfss->rsize;
1932 data->wsize = nfss->wsize;
1933 data->retrans = nfss->client->cl_timeout->to_retries;
1934 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1935 data->acregmin = nfss->acregmin / HZ;
1936 data->acregmax = nfss->acregmax / HZ;
1937 data->acdirmin = nfss->acdirmin / HZ;
1938 data->acdirmax = nfss->acdirmax / HZ;
1939 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001940 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04001941 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1942 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1943 data->nfs_server.addrlen);
1944
1945 /* overwrite those values with any that were specified */
1946 error = nfs_parse_mount_options((char *)options, data);
1947 if (error < 0)
1948 goto out;
1949
1950 /* compare new mount options with old ones */
1951 error = nfs_compare_remount_data(nfss, data);
1952out:
1953 kfree(data);
1954 return error;
1955}
1956
David Howells54ceac42006-08-22 20:06:13 -04001957/*
1958 * Initialise the common bits of the superblock
1959 */
1960static inline void nfs_initialise_sb(struct super_block *sb)
1961{
1962 struct nfs_server *server = NFS_SB(sb);
1963
1964 sb->s_magic = NFS_SUPER_MAGIC;
1965
1966 /* We probably want something more informative here */
1967 snprintf(sb->s_id, sizeof(sb->s_id),
1968 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1969
1970 if (sb->s_blocksize == 0)
1971 sb->s_blocksize = nfs_block_bits(server->wsize,
1972 &sb->s_blocksize_bits);
1973
1974 if (server->flags & NFS_MOUNT_NOAC)
1975 sb->s_flags |= MS_SYNCHRONOUS;
1976
Jens Axboe32a88aa2009-09-16 15:02:33 +02001977 sb->s_bdi = &server->backing_dev_info;
1978
David Howells54ceac42006-08-22 20:06:13 -04001979 nfs_super_set_maxbytes(sb, server->maxfilesize);
1980}
1981
1982/*
1983 * Finish setting up an NFS2/3 superblock
1984 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001985static void nfs_fill_super(struct super_block *sb,
1986 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001987{
1988 struct nfs_server *server = NFS_SB(sb);
1989
1990 sb->s_blocksize_bits = 0;
1991 sb->s_blocksize = 0;
1992 if (data->bsize)
1993 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1994
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001995 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04001996 /* The VFS shouldn't apply the umask to mode bits. We will do
1997 * so ourselves when necessary.
1998 */
1999 sb->s_flags |= MS_POSIXACL;
2000 sb->s_time_gran = 1;
2001 }
2002
2003 sb->s_op = &nfs_sops;
2004 nfs_initialise_sb(sb);
2005}
2006
2007/*
2008 * Finish setting up a cloned NFS2/3 superblock
2009 */
2010static void nfs_clone_super(struct super_block *sb,
2011 const struct super_block *old_sb)
2012{
2013 struct nfs_server *server = NFS_SB(sb);
2014
2015 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2016 sb->s_blocksize = old_sb->s_blocksize;
2017 sb->s_maxbytes = old_sb->s_maxbytes;
2018
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002019 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002020 /* The VFS shouldn't apply the umask to mode bits. We will do
2021 * so ourselves when necessary.
2022 */
2023 sb->s_flags |= MS_POSIXACL;
2024 sb->s_time_gran = 1;
2025 }
2026
2027 sb->s_op = old_sb->s_op;
2028 nfs_initialise_sb(sb);
2029}
2030
Trond Myklebust275a5d22007-05-16 16:53:28 -04002031static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2032{
2033 const struct nfs_server *a = s->s_fs_info;
2034 const struct rpc_clnt *clnt_a = a->client;
2035 const struct rpc_clnt *clnt_b = b->client;
2036
2037 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2038 goto Ebusy;
2039 if (a->nfs_client != b->nfs_client)
2040 goto Ebusy;
2041 if (a->flags != b->flags)
2042 goto Ebusy;
2043 if (a->wsize != b->wsize)
2044 goto Ebusy;
2045 if (a->rsize != b->rsize)
2046 goto Ebusy;
2047 if (a->acregmin != b->acregmin)
2048 goto Ebusy;
2049 if (a->acregmax != b->acregmax)
2050 goto Ebusy;
2051 if (a->acdirmin != b->acdirmin)
2052 goto Ebusy;
2053 if (a->acdirmax != b->acdirmax)
2054 goto Ebusy;
2055 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2056 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002057 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002058Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002059 return 0;
2060}
2061
2062struct nfs_sb_mountdata {
2063 struct nfs_server *server;
2064 int mntflags;
2065};
2066
2067static int nfs_set_super(struct super_block *s, void *data)
2068{
2069 struct nfs_sb_mountdata *sb_mntdata = data;
2070 struct nfs_server *server = sb_mntdata->server;
2071 int ret;
2072
2073 s->s_flags = sb_mntdata->mntflags;
2074 s->s_fs_info = server;
Al Viro8b244ff2010-12-18 11:29:39 -05002075 s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002076 ret = set_anon_super(s, server);
2077 if (ret == 0)
2078 server->s_dev = s->s_dev;
2079 return ret;
2080}
2081
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002082static int nfs_compare_super_address(struct nfs_server *server1,
2083 struct nfs_server *server2)
2084{
2085 struct sockaddr *sap1, *sap2;
2086
2087 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2088 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2089
2090 if (sap1->sa_family != sap2->sa_family)
2091 return 0;
2092
2093 switch (sap1->sa_family) {
2094 case AF_INET: {
2095 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2096 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2097 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2098 return 0;
2099 if (sin1->sin_port != sin2->sin_port)
2100 return 0;
2101 break;
2102 }
2103 case AF_INET6: {
2104 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2105 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2106 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2107 return 0;
2108 if (sin1->sin6_port != sin2->sin6_port)
2109 return 0;
2110 break;
2111 }
2112 default:
2113 return 0;
2114 }
2115
2116 return 1;
2117}
2118
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002119static int nfs_compare_super(struct super_block *sb, void *data)
2120{
2121 struct nfs_sb_mountdata *sb_mntdata = data;
2122 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2123 int mntflags = sb_mntdata->mntflags;
2124
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002125 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002126 return 0;
2127 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2128 if (old->flags & NFS_MOUNT_UNSHARED)
2129 return 0;
2130 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2131 return 0;
2132 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002133}
2134
Miklos Szeredifa799752008-04-30 00:54:33 -07002135static int nfs_bdi_register(struct nfs_server *server)
2136{
2137 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2138}
2139
David Howells54ceac42006-08-22 20:06:13 -04002140static int nfs_get_sb(struct file_system_type *fs_type,
2141 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2142{
2143 struct nfs_server *server = NULL;
2144 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002145 struct nfs_parsed_mount_data *data;
2146 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002147 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002148 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002149 struct nfs_sb_mountdata sb_mntdata = {
2150 .mntflags = flags,
2151 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002152 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002153
Paulius Zaleckas1e657bd2010-10-31 18:21:05 +02002154 data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION);
Trond Myklebustb157b062010-04-19 19:05:48 -04002155 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002156 if (data == NULL || mntfh == NULL)
2157 goto out_free_fh;
2158
2159 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002160
David Howells54ceac42006-08-22 20:06:13 -04002161 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002162 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002163 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002164 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002165
Chuck Lever764302c2009-09-08 19:50:03 -04002166#ifdef CONFIG_NFS_V4
2167 if (data->version == 4) {
2168 error = nfs4_try_mount(flags, dev_name, data, mnt);
2169 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002170 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002171 goto out;
2172 }
2173#endif /* CONFIG_NFS_V4 */
2174
David Howells54ceac42006-08-22 20:06:13 -04002175 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002176 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002177 if (IS_ERR(server)) {
2178 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002179 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002180 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002181 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002182
Trond Myklebust75180df2007-05-16 16:53:28 -04002183 if (server->flags & NFS_MOUNT_UNSHARED)
2184 compare_super = NULL;
2185
David Howells54ceac42006-08-22 20:06:13 -04002186 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002187 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002188 if (IS_ERR(s)) {
2189 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002190 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002191 }
2192
David Howells54ceac42006-08-22 20:06:13 -04002193 if (s->s_fs_info != server) {
2194 nfs_free_server(server);
2195 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002196 } else {
2197 error = nfs_bdi_register(server);
2198 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002199 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002200 }
David Howells54ceac42006-08-22 20:06:13 -04002201
2202 if (!s->s_root) {
2203 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002204 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002205 nfs_fscache_get_super_cookie(
2206 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002207 }
2208
Trond Myklebust33852a12008-06-19 14:20:11 -04002209 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002210 if (IS_ERR(mntroot)) {
2211 error = PTR_ERR(mntroot);
2212 goto error_splat_super;
2213 }
2214
Trond Myklebust33852a12008-06-19 14:20:11 -04002215 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002216 if (error)
2217 goto error_splat_root;
2218
David Howellsf7b422b2006-06-09 09:34:33 -04002219 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002220 mnt->mnt_sb = s;
2221 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002222 error = 0;
2223
2224out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002225 kfree(data->nfs_server.hostname);
2226 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002227 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002228 security_free_mnt_opts(&data->lsm_opts);
2229out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002230 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002231 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002232 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002233
David Howells54ceac42006-08-22 20:06:13 -04002234out_err_nosb:
2235 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002236 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002237
Eric Parisf9c3a382008-03-05 14:20:18 -05002238error_splat_root:
2239 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002240error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002241 if (server && !s->s_root)
2242 bdi_unregister(&server->backing_dev_info);
2243error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002244 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002245 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002246}
2247
David Howells54ceac42006-08-22 20:06:13 -04002248/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002249 * Ensure that we unregister the bdi before kill_anon_super
2250 * releases the device name
2251 */
2252static void nfs_put_super(struct super_block *s)
2253{
2254 struct nfs_server *server = NFS_SB(s);
2255
2256 bdi_unregister(&server->backing_dev_info);
2257}
2258
2259/*
David Howells54ceac42006-08-22 20:06:13 -04002260 * Destroy an NFS2/3 superblock
2261 */
David Howellsf7b422b2006-06-09 09:34:33 -04002262static void nfs_kill_super(struct super_block *s)
2263{
2264 struct nfs_server *server = NFS_SB(s);
2265
2266 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002267 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002268 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002269}
2270
David Howells54ceac42006-08-22 20:06:13 -04002271/*
2272 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2273 */
Al Viro31f43472010-10-29 03:38:12 -04002274static struct dentry *
2275nfs_xdev_mount(struct file_system_type *fs_type, int flags,
2276 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002277{
2278 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002279 struct super_block *s;
2280 struct nfs_server *server;
2281 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002282 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002283 struct nfs_sb_mountdata sb_mntdata = {
2284 .mntflags = flags,
2285 };
David Howells54ceac42006-08-22 20:06:13 -04002286 int error;
2287
Al Viro31f43472010-10-29 03:38:12 -04002288 dprintk("--> nfs_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002289
2290 /* create a new volume representation */
2291 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2292 if (IS_ERR(server)) {
2293 error = PTR_ERR(server);
2294 goto out_err_noserver;
2295 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002296 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002297
Trond Myklebust75180df2007-05-16 16:53:28 -04002298 if (server->flags & NFS_MOUNT_UNSHARED)
2299 compare_super = NULL;
2300
David Howells54ceac42006-08-22 20:06:13 -04002301 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002302 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002303 if (IS_ERR(s)) {
2304 error = PTR_ERR(s);
2305 goto out_err_nosb;
2306 }
2307
2308 if (s->s_fs_info != server) {
2309 nfs_free_server(server);
2310 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002311 } else {
2312 error = nfs_bdi_register(server);
2313 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002314 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002315 }
2316
2317 if (!s->s_root) {
2318 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002319 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002320 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002321 }
2322
2323 mntroot = nfs_get_root(s, data->fh);
2324 if (IS_ERR(mntroot)) {
2325 error = PTR_ERR(mntroot);
2326 goto error_splat_super;
2327 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002328 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002329 dput(mntroot);
2330 error = -ESTALE;
2331 goto error_splat_super;
2332 }
David Howells54ceac42006-08-22 20:06:13 -04002333
2334 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002335
Eric Parisf9c3a382008-03-05 14:20:18 -05002336 /* clone any lsm security options from the parent to the new sb */
2337 security_sb_clone_mnt_opts(data->sb, s);
2338
Al Viro31f43472010-10-29 03:38:12 -04002339 dprintk("<-- nfs_xdev_mount() = 0\n");
2340 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002341
2342out_err_nosb:
2343 nfs_free_server(server);
2344out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002345 dprintk("<-- nfs_xdev_mount() = %d [error]\n", error);
2346 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002347
2348error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002349 if (server && !s->s_root)
2350 bdi_unregister(&server->backing_dev_info);
2351error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002352 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002353 dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error);
2354 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002355}
2356
2357#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002358
2359/*
2360 * Finish setting up a cloned NFS4 superblock
2361 */
2362static void nfs4_clone_super(struct super_block *sb,
2363 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002364{
David Howells54ceac42006-08-22 20:06:13 -04002365 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2366 sb->s_blocksize = old_sb->s_blocksize;
2367 sb->s_maxbytes = old_sb->s_maxbytes;
2368 sb->s_time_gran = 1;
2369 sb->s_op = old_sb->s_op;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002370 /*
2371 * The VFS shouldn't apply the umask to mode bits. We will do
2372 * so ourselves when necessary.
2373 */
2374 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002375 sb->s_xattr = old_sb->s_xattr;
2376 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002377}
2378
2379/*
2380 * Set up an NFS4 superblock
2381 */
David Howells54ceac42006-08-22 20:06:13 -04002382static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002383{
David Howellsf7b422b2006-06-09 09:34:33 -04002384 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002385 sb->s_op = &nfs4_sops;
Aneesh Kumar K.Va8a5da92010-12-09 11:35:14 +00002386 /*
2387 * The VFS shouldn't apply the umask to mode bits. We will do
2388 * so ourselves when necessary.
2389 */
2390 sb->s_flags |= MS_POSIXACL;
Aneesh Kumar K.V64c2ce82010-12-09 11:35:25 +00002391 sb->s_xattr = nfs4_xattr_handlers;
David Howells54ceac42006-08-22 20:06:13 -04002392 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002393}
2394
Trond Myklebust01c3f052009-06-17 13:22:58 -07002395static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2396{
Suresh Jayaraman5eebde22010-09-23 08:55:58 -04002397 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3|
2398 NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL);
Trond Myklebust01c3f052009-06-17 13:22:58 -07002399}
2400
Chuck Lever7630c852009-09-08 19:49:57 -04002401static int nfs4_validate_text_mount_data(void *options,
2402 struct nfs_parsed_mount_data *args,
2403 const char *dev_name)
2404{
2405 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2406
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002407 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002408
2409 nfs_validate_transport_protocol(args);
2410
2411 nfs4_validate_mount_flags(args);
2412
Trond Myklebust2ecda722009-09-08 19:50:07 -04002413 if (args->version != 4) {
2414 dfprintk(MOUNT,
2415 "NFS4: Illegal mount version\n");
2416 return -EINVAL;
2417 }
2418
Chuck Lever7630c852009-09-08 19:49:57 -04002419 if (args->auth_flavor_len > 1) {
2420 dfprintk(MOUNT,
2421 "NFS4: Too many RPC auth flavours specified\n");
2422 return -EINVAL;
2423 }
2424
2425 if (args->client_address == NULL) {
2426 dfprintk(MOUNT,
2427 "NFS4: mount program didn't pass callback address\n");
2428 return -EINVAL;
2429 }
2430
2431 return nfs_parse_devname(dev_name,
2432 &args->nfs_server.hostname,
2433 NFS4_MAXNAMLEN,
2434 &args->nfs_server.export_path,
2435 NFS4_MAXPATHLEN);
2436}
2437
David Howells54ceac42006-08-22 20:06:13 -04002438/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002439 * Validate NFSv4 mount options
2440 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002441static int nfs4_validate_mount_data(void *options,
2442 struct nfs_parsed_mount_data *args,
2443 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002444{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002445 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002446 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002447 char *c;
2448
2449 if (data == NULL)
2450 goto out_no_data;
2451
2452 switch (data->version) {
2453 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002454 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002455 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002456 if (data->host_addrlen == 0)
2457 goto out_no_address;
2458 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002459 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002460 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002461 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002462 goto out_no_address;
2463
Chuck Lever6738b252008-06-24 16:33:54 -04002464 if (data->auth_flavourlen) {
2465 if (data->auth_flavourlen > 1)
2466 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002467 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002468 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002469 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002470 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002471 }
2472
2473 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2474 if (IS_ERR(c))
2475 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002476 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002477
2478 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2479 if (IS_ERR(c))
2480 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002481 args->nfs_server.export_path = c;
2482 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002483
2484 c = strndup_user(data->client_addr.data, 16);
2485 if (IS_ERR(c))
2486 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002487 args->client_address = c;
2488
2489 /*
2490 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2491 * can deal with.
2492 */
2493
2494 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2495 args->rsize = data->rsize;
2496 args->wsize = data->wsize;
2497 args->timeo = data->timeo;
2498 args->retrans = data->retrans;
2499 args->acregmin = data->acregmin;
2500 args->acregmax = data->acregmax;
2501 args->acdirmin = data->acdirmin;
2502 args->acdirmax = data->acdirmax;
2503 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002504 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002505
2506 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002507 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002508 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002509 return -EINVAL;
2510
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002511 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002512 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002513
Chuck Lever7630c852009-09-08 19:49:57 -04002514 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002515 }
2516
2517 return 0;
2518
2519out_no_data:
2520 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2521 return -EINVAL;
2522
2523out_inval_auth:
2524 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2525 data->auth_flavourlen);
2526 return -EINVAL;
2527
2528out_no_address:
2529 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2530 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002531}
2532
2533/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002534 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002535 */
Al Viro31f43472010-10-29 03:38:12 -04002536static struct dentry *
2537nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2538 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002539{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002540 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002541 struct super_block *s;
2542 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002543 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002544 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002545 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002546 struct nfs_sb_mountdata sb_mntdata = {
2547 .mntflags = flags,
2548 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002549 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002550
Trond Myklebustb157b062010-04-19 19:05:48 -04002551 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002552 if (data == NULL || mntfh == NULL)
2553 goto out_free_fh;
2554
2555 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002556
David Howells54ceac42006-08-22 20:06:13 -04002557 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002558 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002559 if (IS_ERR(server)) {
2560 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002561 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002562 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002563 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002564
Trond Myklebust75180df2007-05-16 16:53:28 -04002565 if (server->flags & NFS4_MOUNT_UNSHARED)
2566 compare_super = NULL;
2567
David Howells54ceac42006-08-22 20:06:13 -04002568 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002569 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002570 if (IS_ERR(s)) {
2571 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002572 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002573 }
2574
Trond Myklebust5dd31772006-08-24 01:03:05 -04002575 if (s->s_fs_info != server) {
2576 nfs_free_server(server);
2577 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002578 } else {
2579 error = nfs_bdi_register(server);
2580 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002581 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002582 }
2583
David Howells54ceac42006-08-22 20:06:13 -04002584 if (!s->s_root) {
2585 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002586 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002587 nfs_fscache_get_super_cookie(
2588 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002589 }
David Howellsf7b422b2006-06-09 09:34:33 -04002590
Trond Myklebust33852a12008-06-19 14:20:11 -04002591 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002592 if (IS_ERR(mntroot)) {
2593 error = PTR_ERR(mntroot);
2594 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002595 }
David Howells54ceac42006-08-22 20:06:13 -04002596
Trond Myklebust33852a12008-06-19 14:20:11 -04002597 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002598 if (error)
2599 goto error_splat_root;
2600
David Howellsf7b422b2006-06-09 09:34:33 -04002601 s->s_flags |= MS_ACTIVE;
Al Viro31f43472010-10-29 03:38:12 -04002602
2603 security_free_mnt_opts(&data->lsm_opts);
2604 nfs_free_fhandle(mntfh);
2605 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002606
Chuck Lever29eb9812007-07-01 12:12:30 -04002607out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002608 security_free_mnt_opts(&data->lsm_opts);
2609out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002610 nfs_free_fhandle(mntfh);
Al Viro31f43472010-10-29 03:38:12 -04002611 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002612
Chuck Lever29eb9812007-07-01 12:12:30 -04002613out_free:
2614 nfs_free_server(server);
2615 goto out;
2616
Eric Paris46c8ac72008-05-02 13:42:42 -07002617error_splat_root:
2618 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002619error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002620 if (server && !s->s_root)
2621 bdi_unregister(&server->backing_dev_info);
2622error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002623 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002624 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002625}
2626
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002627static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2628 int flags, void *data, const char *hostname)
2629{
2630 struct vfsmount *root_mnt;
2631 char *root_devname;
2632 size_t len;
2633
2634 len = strlen(hostname) + 3;
2635 root_devname = kmalloc(len, GFP_KERNEL);
2636 if (root_devname == NULL)
2637 return ERR_PTR(-ENOMEM);
2638 snprintf(root_devname, len, "%s:/", hostname);
2639 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2640 kfree(root_devname);
2641 return root_mnt;
2642}
2643
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002644static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2645{
2646 char *page = (char *) __get_free_page(GFP_KERNEL);
2647 char *devname, *tmp;
2648
2649 if (page == NULL)
2650 return;
2651 devname = nfs_path(path->mnt->mnt_devname,
2652 path->mnt->mnt_root, path->dentry,
2653 page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002654 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002655 goto out_freepage;
2656 tmp = kstrdup(devname, GFP_KERNEL);
2657 if (tmp == NULL)
2658 goto out_freepage;
2659 kfree(mnt->mnt_devname);
2660 mnt->mnt_devname = tmp;
2661out_freepage:
2662 free_page((unsigned long)page);
2663}
2664
Trond Myklebustce587e02010-04-16 16:22:52 -04002665struct nfs_referral_count {
2666 struct list_head list;
2667 const struct task_struct *task;
2668 unsigned int referral_count;
2669};
2670
2671static LIST_HEAD(nfs_referral_count_list);
2672static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2673
2674static struct nfs_referral_count *nfs_find_referral_count(void)
2675{
2676 struct nfs_referral_count *p;
2677
2678 list_for_each_entry(p, &nfs_referral_count_list, list) {
2679 if (p->task == current)
2680 return p;
2681 }
2682 return NULL;
2683}
2684
2685#define NFS_MAX_NESTED_REFERRALS 2
2686
2687static int nfs_referral_loop_protect(void)
2688{
2689 struct nfs_referral_count *p, *new;
2690 int ret = -ENOMEM;
2691
2692 new = kmalloc(sizeof(*new), GFP_KERNEL);
2693 if (!new)
2694 goto out;
2695 new->task = current;
2696 new->referral_count = 1;
2697
2698 ret = 0;
2699 spin_lock(&nfs_referral_count_list_lock);
2700 p = nfs_find_referral_count();
2701 if (p != NULL) {
2702 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2703 ret = -ELOOP;
2704 else
2705 p->referral_count++;
2706 } else {
2707 list_add(&new->list, &nfs_referral_count_list);
2708 new = NULL;
2709 }
2710 spin_unlock(&nfs_referral_count_list_lock);
2711 kfree(new);
2712out:
2713 return ret;
2714}
2715
2716static void nfs_referral_loop_unprotect(void)
2717{
2718 struct nfs_referral_count *p;
2719
2720 spin_lock(&nfs_referral_count_list_lock);
2721 p = nfs_find_referral_count();
2722 p->referral_count--;
2723 if (p->referral_count == 0)
2724 list_del(&p->list);
2725 else
2726 p = NULL;
2727 spin_unlock(&nfs_referral_count_list_lock);
2728 kfree(p);
2729}
2730
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002731static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2732 const char *export_path, struct vfsmount *mnt_target)
2733{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002734 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002735 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002736 struct super_block *s;
2737 int ret;
2738
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002739 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2740 if (nd == NULL)
2741 return -ENOMEM;
2742
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002743 ns_private = create_mnt_ns(root_mnt);
2744 ret = PTR_ERR(ns_private);
2745 if (IS_ERR(ns_private))
2746 goto out_mntput;
2747
Trond Myklebustce587e02010-04-16 16:22:52 -04002748 ret = nfs_referral_loop_protect();
2749 if (ret != 0)
2750 goto out_put_mnt_ns;
2751
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002752 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002753 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002754
Trond Myklebustce587e02010-04-16 16:22:52 -04002755 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002756 put_mnt_ns(ns_private);
2757
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002758 if (ret != 0)
2759 goto out_err;
2760
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002761 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002762 atomic_inc(&s->s_active);
2763 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002764 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002765
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002766 /* Correct the device pathname */
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002767 nfs_fix_devname(&nd->path, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002768
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002769 path_put(&nd->path);
2770 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002771 down_write(&s->s_umount);
2772 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002773out_put_mnt_ns:
2774 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002775out_mntput:
2776 mntput(root_mnt);
2777out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002778 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002779 return ret;
2780}
2781
Chuck Levera6fe23b2009-09-08 19:50:00 -04002782static int nfs4_try_mount(int flags, const char *dev_name,
2783 struct nfs_parsed_mount_data *data,
2784 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002785{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002786 char *export_path;
2787 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002788 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002789
Chuck Levera6fe23b2009-09-08 19:50:00 -04002790 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002791
2792 export_path = data->nfs_server.export_path;
2793 data->nfs_server.export_path = "/";
2794 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2795 data->nfs_server.hostname);
2796 data->nfs_server.export_path = export_path;
2797
2798 error = PTR_ERR(root_mnt);
2799 if (IS_ERR(root_mnt))
2800 goto out;
2801
2802 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2803
2804out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002805 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2806 error != 0 ? " [error]" : "");
2807 return error;
2808}
2809
2810/*
2811 * Get the superblock for an NFS4 mountpoint
2812 */
2813static int nfs4_get_sb(struct file_system_type *fs_type,
2814 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2815{
2816 struct nfs_parsed_mount_data *data;
2817 int error = -ENOMEM;
2818
Trond Myklebustc5811db2009-10-06 15:40:15 -04002819 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002820 if (data == NULL)
2821 goto out_free_data;
2822
2823 /* Validate the mount data */
2824 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2825 if (error < 0)
2826 goto out;
2827
2828 error = nfs4_try_mount(flags, dev_name, data, mnt);
2829
2830out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002831 kfree(data->client_address);
2832 kfree(data->nfs_server.export_path);
2833 kfree(data->nfs_server.hostname);
2834 kfree(data->fscache_uniq);
2835out_free_data:
2836 kfree(data);
2837 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2838 error != 0 ? " [error]" : "");
2839 return error;
2840}
2841
David Howellsf7b422b2006-06-09 09:34:33 -04002842static void nfs4_kill_super(struct super_block *sb)
2843{
2844 struct nfs_server *server = NFS_SB(sb);
2845
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002846 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002847 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002848 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002849 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002850 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002851 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002852}
2853
2854/*
David Howells54ceac42006-08-22 20:06:13 -04002855 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002856 */
Al Viro31f43472010-10-29 03:38:12 -04002857static struct dentry *
2858nfs4_xdev_mount(struct file_system_type *fs_type, int flags,
2859 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002860{
2861 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002862 struct super_block *s;
2863 struct nfs_server *server;
2864 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002865 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002866 struct nfs_sb_mountdata sb_mntdata = {
2867 .mntflags = flags,
2868 };
David Howells54ceac42006-08-22 20:06:13 -04002869 int error;
2870
Al Viro31f43472010-10-29 03:38:12 -04002871 dprintk("--> nfs4_xdev_mount()\n");
David Howells54ceac42006-08-22 20:06:13 -04002872
2873 /* create a new volume representation */
2874 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2875 if (IS_ERR(server)) {
2876 error = PTR_ERR(server);
2877 goto out_err_noserver;
2878 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002879 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002880
Trond Myklebust75180df2007-05-16 16:53:28 -04002881 if (server->flags & NFS4_MOUNT_UNSHARED)
2882 compare_super = NULL;
2883
David Howells54ceac42006-08-22 20:06:13 -04002884 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002885 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002886 if (IS_ERR(s)) {
2887 error = PTR_ERR(s);
2888 goto out_err_nosb;
2889 }
2890
2891 if (s->s_fs_info != server) {
2892 nfs_free_server(server);
2893 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002894 } else {
2895 error = nfs_bdi_register(server);
2896 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002897 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002898 }
2899
2900 if (!s->s_root) {
2901 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002902 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002903 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002904 }
2905
2906 mntroot = nfs4_get_root(s, data->fh);
2907 if (IS_ERR(mntroot)) {
2908 error = PTR_ERR(mntroot);
2909 goto error_splat_super;
2910 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002911 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2912 dput(mntroot);
2913 error = -ESTALE;
2914 goto error_splat_super;
2915 }
David Howells54ceac42006-08-22 20:06:13 -04002916
2917 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002918
Eric Paris46c8ac72008-05-02 13:42:42 -07002919 security_sb_clone_mnt_opts(data->sb, s);
2920
Al Viro31f43472010-10-29 03:38:12 -04002921 dprintk("<-- nfs4_xdev_mount() = 0\n");
2922 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04002923
2924out_err_nosb:
2925 nfs_free_server(server);
2926out_err_noserver:
Al Viro31f43472010-10-29 03:38:12 -04002927 dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error);
2928 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04002929
2930error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002931 if (server && !s->s_root)
2932 bdi_unregister(&server->backing_dev_info);
2933error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002934 deactivate_locked_super(s);
Al Viro31f43472010-10-29 03:38:12 -04002935 dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error);
2936 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04002937}
2938
Al Viro31f43472010-10-29 03:38:12 -04002939static struct dentry *
2940nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,
2941 const char *dev_name, void *raw_data)
David Howellsf7b422b2006-06-09 09:34:33 -04002942{
2943 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002944 struct super_block *s;
2945 struct nfs_server *server;
2946 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002947 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002948 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002949 struct nfs_sb_mountdata sb_mntdata = {
2950 .mntflags = flags,
2951 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002952 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002953
2954 dprintk("--> nfs4_referral_get_sb()\n");
2955
Trond Myklebust4f727292010-04-16 16:22:48 -04002956 mntfh = nfs_alloc_fhandle();
2957 if (mntfh == NULL)
2958 goto out_err_nofh;
2959
David Howells54ceac42006-08-22 20:06:13 -04002960 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04002961 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002962 if (IS_ERR(server)) {
2963 error = PTR_ERR(server);
2964 goto out_err_noserver;
2965 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002966 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002967
Trond Myklebust75180df2007-05-16 16:53:28 -04002968 if (server->flags & NFS4_MOUNT_UNSHARED)
2969 compare_super = NULL;
2970
David Howells54ceac42006-08-22 20:06:13 -04002971 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002972 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002973 if (IS_ERR(s)) {
2974 error = PTR_ERR(s);
2975 goto out_err_nosb;
2976 }
2977
2978 if (s->s_fs_info != server) {
2979 nfs_free_server(server);
2980 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002981 } else {
2982 error = nfs_bdi_register(server);
2983 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002984 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002985 }
2986
2987 if (!s->s_root) {
2988 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002989 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002990 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002991 }
2992
Trond Myklebust4f727292010-04-16 16:22:48 -04002993 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002994 if (IS_ERR(mntroot)) {
2995 error = PTR_ERR(mntroot);
2996 goto error_splat_super;
2997 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002998 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2999 dput(mntroot);
3000 error = -ESTALE;
3001 goto error_splat_super;
3002 }
David Howells54ceac42006-08-22 20:06:13 -04003003
3004 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04003005
Eric Paris46c8ac72008-05-02 13:42:42 -07003006 security_sb_clone_mnt_opts(data->sb, s);
3007
Trond Myklebust4f727292010-04-16 16:22:48 -04003008 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003009 dprintk("<-- nfs4_referral_get_sb() = 0\n");
Al Viro31f43472010-10-29 03:38:12 -04003010 return mntroot;
David Howells54ceac42006-08-22 20:06:13 -04003011
3012out_err_nosb:
3013 nfs_free_server(server);
3014out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003015 nfs_free_fhandle(mntfh);
3016out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003017 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003018 return ERR_PTR(error);
David Howells54ceac42006-08-22 20:06:13 -04003019
3020error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003021 if (server && !s->s_root)
3022 bdi_unregister(&server->backing_dev_info);
3023error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003024 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003025 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003026 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
Al Viro31f43472010-10-29 03:38:12 -04003027 return ERR_PTR(error);
David Howellsf7b422b2006-06-09 09:34:33 -04003028}
3029
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003030/*
3031 * Create an NFS4 server record on referral traversal
3032 */
3033static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3034 int flags, const char *dev_name, void *raw_data,
3035 struct vfsmount *mnt)
3036{
3037 struct nfs_clone_mount *data = raw_data;
3038 char *export_path;
3039 struct vfsmount *root_mnt;
3040 int error;
3041
3042 dprintk("--> nfs4_referral_get_sb()\n");
3043
3044 export_path = data->mnt_path;
3045 data->mnt_path = "/";
3046
3047 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3048 flags, data, data->hostname);
3049 data->mnt_path = export_path;
3050
3051 error = PTR_ERR(root_mnt);
3052 if (IS_ERR(root_mnt))
3053 goto out;
3054
3055 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3056out:
3057 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3058 error != 0 ? " [error]" : "");
3059 return error;
3060}
3061
David Howells54ceac42006-08-22 20:06:13 -04003062#endif /* CONFIG_NFS_V4 */