blob: f4cbf0c306c64d6583cbfffaa14cfbc7a467dfaa [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
Trond Myklebustc02d7ad2009-06-22 15:09:14 -040045#include <linux/mnt_namespace.h>
46#include <linux/namei.h>
David Howellsf7b422b2006-06-09 09:34:33 -040047#include <linux/nfs_idmap.h>
48#include <linux/vfs.h>
49#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050050#include <linux/in6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090051#include <linux/slab.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050052#include <net/ipv6.h>
Chuck Leverd8e77482008-06-23 12:37:01 -040053#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040054#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080055#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040056#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040057
58#include <asm/system.h>
59#include <asm/uaccess.h>
60
61#include "nfs4_fs.h"
62#include "callback.h"
63#include "delegation.h"
64#include "iostat.h"
65#include "internal.h"
David Howells08734042009-04-03 16:42:42 +010066#include "fscache.h"
David Howellsf7b422b2006-06-09 09:34:33 -040067
68#define NFSDBG_FACILITY NFSDBG_VFS
69
Chuck Leverbf0fd762007-07-01 12:13:44 -040070enum {
71 /* Mount options that take no arguments */
72 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040073 Opt_posix, Opt_noposix,
74 Opt_cto, Opt_nocto,
75 Opt_ac, Opt_noac,
76 Opt_lock, Opt_nolock,
Chuck Lever764302c2009-09-08 19:50:03 -040077 Opt_v2, Opt_v3, Opt_v4,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040078 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040079 Opt_acl, Opt_noacl,
80 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040081 Opt_sharecache, Opt_nosharecache,
Chuck Leverd7403512008-12-23 15:21:37 -050082 Opt_resvport, Opt_noresvport,
David Howellsb797cac2009-04-03 16:42:48 +010083 Opt_fscache, Opt_nofscache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040084
85 /* Mount options that take integer arguments */
86 Opt_port,
87 Opt_rsize, Opt_wsize, Opt_bsize,
88 Opt_timeo, Opt_retrans,
89 Opt_acregmin, Opt_acregmax,
90 Opt_acdirmin, Opt_acdirmax,
91 Opt_actimeo,
92 Opt_namelen,
93 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040094 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040095 Opt_nfsvers,
Mike Sager3fd5be92009-04-01 09:21:48 -040096 Opt_minorversion,
Chuck Leverbf0fd762007-07-01 12:13:44 -040097
98 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050099 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -0400100 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400101 Opt_lookupcache,
David Howellsb797cac2009-04-03 16:42:48 +0100102 Opt_fscache_uniq,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103
Chuck Leverf45663c2008-06-24 19:28:02 -0400104 /* Special mount options */
105 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400106
107 Opt_err
108};
109
Steven Whitehousea447c092008-10-13 10:46:57 +0100110static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400111 { Opt_userspace, "bg" },
112 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400113 { Opt_userspace, "retry=%s" },
114
Chuck Leverf45663c2008-06-24 19:28:02 -0400115 { Opt_sloppy, "sloppy" },
116
Chuck Leverbf0fd762007-07-01 12:13:44 -0400117 { Opt_soft, "soft" },
118 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400119 { Opt_deprecated, "intr" },
120 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_posix, "posix" },
122 { Opt_noposix, "noposix" },
123 { Opt_cto, "cto" },
124 { Opt_nocto, "nocto" },
125 { Opt_ac, "ac" },
126 { Opt_noac, "noac" },
127 { Opt_lock, "lock" },
128 { Opt_nolock, "nolock" },
129 { Opt_v2, "v2" },
130 { Opt_v3, "v3" },
Chuck Lever764302c2009-09-08 19:50:03 -0400131 { Opt_v4, "v4" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400132 { Opt_udp, "udp" },
133 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400134 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400135 { Opt_acl, "acl" },
136 { Opt_noacl, "noacl" },
137 { Opt_rdirplus, "rdirplus" },
138 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400139 { Opt_sharecache, "sharecache" },
140 { Opt_nosharecache, "nosharecache" },
Chuck Leverd7403512008-12-23 15:21:37 -0500141 { Opt_resvport, "resvport" },
142 { Opt_noresvport, "noresvport" },
David Howellsb797cac2009-04-03 16:42:48 +0100143 { Opt_fscache, "fsc" },
David Howellsb797cac2009-04-03 16:42:48 +0100144 { Opt_nofscache, "nofsc" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400145
Chuck Levera5a16ba2009-06-17 18:02:14 -0700146 { Opt_port, "port=%s" },
147 { Opt_rsize, "rsize=%s" },
148 { Opt_wsize, "wsize=%s" },
149 { Opt_bsize, "bsize=%s" },
150 { Opt_timeo, "timeo=%s" },
151 { Opt_retrans, "retrans=%s" },
152 { Opt_acregmin, "acregmin=%s" },
153 { Opt_acregmax, "acregmax=%s" },
154 { Opt_acdirmin, "acdirmin=%s" },
155 { Opt_acdirmax, "acdirmax=%s" },
156 { Opt_actimeo, "actimeo=%s" },
157 { Opt_namelen, "namlen=%s" },
158 { Opt_mountport, "mountport=%s" },
159 { Opt_mountvers, "mountvers=%s" },
160 { Opt_nfsvers, "nfsvers=%s" },
161 { Opt_nfsvers, "vers=%s" },
Chuck Leverf3f4f4e2009-08-09 15:09:29 -0400162 { Opt_minorversion, "minorversion=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400163
164 { Opt_sec, "sec=%s" },
165 { Opt_proto, "proto=%s" },
166 { Opt_mountproto, "mountproto=%s" },
167 { Opt_addr, "addr=%s" },
168 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500169 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400170 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400171
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400172 { Opt_lookupcache, "lookupcache=%s" },
Chuck Levera6d5ff62010-05-07 13:33:58 -0400173 { Opt_fscache_uniq, "fsc=%s" },
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400174
Chuck Leverbf0fd762007-07-01 12:13:44 -0400175 { Opt_err, NULL }
176};
177
178enum {
Jeff Laytonee671b02009-12-03 15:58:56 -0500179 Opt_xprt_udp, Opt_xprt_udp6, Opt_xprt_tcp, Opt_xprt_tcp6, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400180
181 Opt_xprt_err
182};
183
Steven Whitehousea447c092008-10-13 10:46:57 +0100184static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400185 { Opt_xprt_udp, "udp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500186 { Opt_xprt_udp6, "udp6" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187 { Opt_xprt_tcp, "tcp" },
Jeff Laytonee671b02009-12-03 15:58:56 -0500188 { Opt_xprt_tcp6, "tcp6" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400189 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400190
191 { Opt_xprt_err, NULL }
192};
193
194enum {
195 Opt_sec_none, Opt_sec_sys,
196 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
197 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
198 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
199
200 Opt_sec_err
201};
202
Steven Whitehousea447c092008-10-13 10:46:57 +0100203static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400204 { Opt_sec_none, "none" },
205 { Opt_sec_none, "null" },
206 { Opt_sec_sys, "sys" },
207
208 { Opt_sec_krb5, "krb5" },
209 { Opt_sec_krb5i, "krb5i" },
210 { Opt_sec_krb5p, "krb5p" },
211
212 { Opt_sec_lkey, "lkey" },
213 { Opt_sec_lkeyi, "lkeyi" },
214 { Opt_sec_lkeyp, "lkeyp" },
215
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500216 { Opt_sec_spkm, "spkm3" },
217 { Opt_sec_spkmi, "spkm3i" },
218 { Opt_sec_spkmp, "spkm3p" },
219
Chuck Leverbf0fd762007-07-01 12:13:44 -0400220 { Opt_sec_err, NULL }
221};
222
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400223enum {
224 Opt_lookupcache_all, Opt_lookupcache_positive,
225 Opt_lookupcache_none,
226
227 Opt_lookupcache_err
228};
229
230static match_table_t nfs_lookupcache_tokens = {
231 { Opt_lookupcache_all, "all" },
232 { Opt_lookupcache_positive, "pos" },
233 { Opt_lookupcache_positive, "positive" },
234 { Opt_lookupcache_none, "none" },
235
236 { Opt_lookupcache_err, NULL }
237};
238
Chuck Leverbf0fd762007-07-01 12:13:44 -0400239
Al Viro42faad92008-04-24 07:21:56 -0400240static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400241static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400242static int nfs_show_options(struct seq_file *, struct vfsmount *);
243static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400244static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400245static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400246 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebust387c1492010-02-03 08:27:35 -0500247static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400248static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400249static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400250
251static struct file_system_type nfs_fs_type = {
252 .owner = THIS_MODULE,
253 .name = "nfs",
254 .get_sb = nfs_get_sb,
255 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400257};
258
David Howells54ceac42006-08-22 20:06:13 -0400259struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400260 .owner = THIS_MODULE,
261 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400262 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400265};
266
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800267static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400268 .alloc_inode = nfs_alloc_inode,
269 .destroy_inode = nfs_destroy_inode,
270 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500271 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400272 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400273 .evict_inode = nfs_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400277 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400278};
279
280#ifdef CONFIG_NFS_V4
Chuck Lever7630c852009-09-08 19:49:57 -0400281static int nfs4_validate_text_mount_data(void *options,
282 struct nfs_parsed_mount_data *args, const char *dev_name);
Chuck Levera6fe23b2009-09-08 19:50:00 -0400283static int nfs4_try_mount(int flags, const char *dev_name,
284 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
Trond Myklebust816724e2006-06-24 08:41:41 -0400285static int nfs4_get_sb(struct file_system_type *fs_type,
286 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400287static int nfs4_remote_get_sb(struct file_system_type *fs_type,
288 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400289static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
290 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
291static int nfs4_referral_get_sb(struct file_system_type *fs_type,
292 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400293static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
294 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400295static void nfs4_kill_super(struct super_block *sb);
296
297static struct file_system_type nfs4_fs_type = {
298 .owner = THIS_MODULE,
299 .name = "nfs4",
300 .get_sb = nfs4_get_sb,
301 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700302 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400303};
304
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400305static struct file_system_type nfs4_remote_fs_type = {
306 .owner = THIS_MODULE,
307 .name = "nfs4",
308 .get_sb = nfs4_remote_get_sb,
309 .kill_sb = nfs4_kill_super,
310 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
311};
312
David Howells54ceac42006-08-22 20:06:13 -0400313struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400314 .owner = THIS_MODULE,
315 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400316 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400317 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700318 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400319};
320
Trond Myklebustc02d7ad2009-06-22 15:09:14 -0400321static struct file_system_type nfs4_remote_referral_fs_type = {
322 .owner = THIS_MODULE,
323 .name = "nfs4",
324 .get_sb = nfs4_remote_referral_get_sb,
325 .kill_sb = nfs4_kill_super,
326 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
327};
328
David Howells54ceac42006-08-22 20:06:13 -0400329struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400330 .owner = THIS_MODULE,
331 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400332 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400333 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700334 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400335};
336
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800337static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400338 .alloc_inode = nfs_alloc_inode,
339 .destroy_inode = nfs_destroy_inode,
340 .write_inode = nfs_write_inode,
Trond Myklebust387c1492010-02-03 08:27:35 -0500341 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400342 .statfs = nfs_statfs,
Al Virob57922d2010-06-07 14:34:48 -0400343 .evict_inode = nfs4_evict_inode,
David Howellsf7b422b2006-06-09 09:34:33 -0400344 .umount_begin = nfs_umount_begin,
345 .show_options = nfs_show_options,
346 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400347 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400348};
349#endif
350
Rusty Russell8e1f9362007-07-17 04:03:17 -0700351static struct shrinker acl_shrinker = {
352 .shrink = nfs_access_cache_shrinker,
353 .seeks = DEFAULT_SEEKS,
354};
Trond Myklebust979df722006-07-25 11:28:19 -0400355
David Howellsf7b422b2006-06-09 09:34:33 -0400356/*
357 * Register the NFS filesystems
358 */
359int __init register_nfs_fs(void)
360{
361 int ret;
362
363 ret = register_filesystem(&nfs_fs_type);
364 if (ret < 0)
365 goto error_0;
366
David Howellsf7b422b2006-06-09 09:34:33 -0400367 ret = nfs_register_sysctl();
368 if (ret < 0)
369 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800370#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400371 ret = register_filesystem(&nfs4_fs_type);
372 if (ret < 0)
373 goto error_2;
374#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700375 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400376 return 0;
377
378#ifdef CONFIG_NFS_V4
379error_2:
380 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800381#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400382error_1:
383 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400384error_0:
385 return ret;
386}
387
388/*
389 * Unregister the NFS filesystems
390 */
391void __exit unregister_nfs_fs(void)
392{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700393 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400394#ifdef CONFIG_NFS_V4
395 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400396#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700397 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400398 unregister_filesystem(&nfs_fs_type);
399}
400
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400401void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500402{
403 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400404
405 if (atomic_inc_return(&server->active) == 1)
406 atomic_inc(&sb->s_active);
407}
408
409void nfs_sb_deactive(struct super_block *sb)
410{
411 struct nfs_server *server = NFS_SB(sb);
412
413 if (atomic_dec_and_test(&server->active))
414 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500415}
416
David Howellsf7b422b2006-06-09 09:34:33 -0400417/*
418 * Deliver file system statistics to userspace
419 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400420static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400421{
David Howells0c7d90c2006-08-22 20:06:10 -0400422 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400423 unsigned char blockbits;
424 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400425 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400426 struct nfs_fsstat res;
427 int error = -ENOMEM;
428
429 res.fattr = nfs_alloc_fattr();
430 if (res.fattr == NULL)
431 goto out_err;
David Howellsf7b422b2006-06-09 09:34:33 -0400432
David Howells8fa5c002006-08-22 20:06:12 -0400433 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400434 if (unlikely(error == -ESTALE)) {
435 struct dentry *pd_dentry;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400436
Menyhart Zoltanfbf3fdd2010-09-12 19:55:26 -0400437 pd_dentry = dget_parent(dentry);
438 if (pd_dentry != NULL) {
439 nfs_zap_caches(pd_dentry->d_inode);
440 dput(pd_dentry);
441 }
442 }
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400443 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400444 if (error < 0)
445 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400446
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700447 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400448
449 /*
450 * Current versions of glibc do not correctly handle the
451 * case where f_frsize != f_bsize. Eventually we want to
452 * report the value of wtmult in this field.
453 */
David Howells0c7d90c2006-08-22 20:06:10 -0400454 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400455
456 /*
457 * On most *nix systems, f_blocks, f_bfree, and f_bavail
458 * are reported in units of f_frsize. Linux hasn't had
459 * an f_frsize field in its statfs struct until recently,
460 * thus historically Linux's sys_statfs reports these
461 * fields in units of f_bsize.
462 */
David Howells0c7d90c2006-08-22 20:06:10 -0400463 buf->f_bsize = dentry->d_sb->s_blocksize;
464 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400465 blockres = (1 << blockbits) - 1;
466 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
467 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
468 buf->f_bavail = (res.abytes + blockres) >> blockbits;
469
470 buf->f_files = res.tfiles;
471 buf->f_ffree = res.afiles;
472
473 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700474
David Howellsf7b422b2006-06-09 09:34:33 -0400475 return 0;
476
477 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700478 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700479 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400480}
481
David Howells7d4e2742006-08-22 20:06:07 -0400482/*
483 * Map the security flavour number to a name
484 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400485static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
486{
David Howells7d4e2742006-08-22 20:06:07 -0400487 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400488 rpc_authflavor_t flavour;
489 const char *str;
490 } sec_flavours[] = {
491 { RPC_AUTH_NULL, "null" },
492 { RPC_AUTH_UNIX, "sys" },
493 { RPC_AUTH_GSS_KRB5, "krb5" },
494 { RPC_AUTH_GSS_KRB5I, "krb5i" },
495 { RPC_AUTH_GSS_KRB5P, "krb5p" },
496 { RPC_AUTH_GSS_LKEY, "lkey" },
497 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
498 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
499 { RPC_AUTH_GSS_SPKM, "spkm" },
500 { RPC_AUTH_GSS_SPKMI, "spkmi" },
501 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400502 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400503 };
504 int i;
505
Chuck Lever4d81cd12007-07-01 12:12:40 -0400506 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400507 if (sec_flavours[i].flavour == flavour)
508 break;
509 }
510 return sec_flavours[i].str;
511}
512
Jeff Laytonee671b02009-12-03 15:58:56 -0500513static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
514 int showdefaults)
515{
516 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
517
518 seq_printf(m, ",mountproto=");
519 switch (sap->sa_family) {
520 case AF_INET:
521 switch (nfss->mountd_protocol) {
522 case IPPROTO_UDP:
523 seq_printf(m, RPCBIND_NETID_UDP);
524 break;
525 case IPPROTO_TCP:
526 seq_printf(m, RPCBIND_NETID_TCP);
527 break;
528 default:
529 if (showdefaults)
530 seq_printf(m, "auto");
531 }
532 break;
533 case AF_INET6:
534 switch (nfss->mountd_protocol) {
535 case IPPROTO_UDP:
536 seq_printf(m, RPCBIND_NETID_UDP6);
537 break;
538 case IPPROTO_TCP:
539 seq_printf(m, RPCBIND_NETID_TCP6);
540 break;
541 default:
542 if (showdefaults)
543 seq_printf(m, "auto");
544 }
545 break;
546 default:
547 if (showdefaults)
548 seq_printf(m, "auto");
549 }
550}
551
Chuck Lever82d101d2008-03-14 14:10:37 -0400552static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
553 int showdefaults)
554{
555 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
556
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -0400557 if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
558 return;
559
Chuck Lever82d101d2008-03-14 14:10:37 -0400560 switch (sap->sa_family) {
561 case AF_INET: {
562 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700563 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400564 break;
565 }
566 case AF_INET6: {
567 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500568 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400569 break;
570 }
571 default:
572 if (showdefaults)
573 seq_printf(m, ",mountaddr=unspecified");
574 }
575
576 if (nfss->mountd_version || showdefaults)
577 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
578 if (nfss->mountd_port || showdefaults)
579 seq_printf(m, ",mountport=%u", nfss->mountd_port);
580
Jeff Laytonee671b02009-12-03 15:58:56 -0500581 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400582}
583
Trond Myklebust0be81892010-06-18 12:23:58 -0400584#ifdef CONFIG_NFS_V4
585static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
586 int showdefaults)
587{
588 struct nfs_client *clp = nfss->nfs_client;
589
590 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
591 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
592}
593#else
594static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
595 int showdefaults)
596{
597}
598#endif
599
David Howellsf7b422b2006-06-09 09:34:33 -0400600/*
601 * Describe the mount options in force on this server representation
602 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400603static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
604 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400605{
David Howells509de812006-08-22 20:06:11 -0400606 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400607 int flag;
David Howells509de812006-08-22 20:06:11 -0400608 const char *str;
609 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400610 } nfs_info[] = {
611 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400612 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400613 { NFS_MOUNT_NOCTO, ",nocto", "" },
614 { NFS_MOUNT_NOAC, ",noac", "" },
615 { NFS_MOUNT_NONLM, ",nolock", "" },
616 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400617 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500618 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
619 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400620 { 0, NULL, NULL }
621 };
David Howells509de812006-08-22 20:06:11 -0400622 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400623 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400624 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400625
Chuck Lever82d101d2008-03-14 14:10:37 -0400626 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400627 seq_printf(m, ",rsize=%u", nfss->rsize);
628 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400629 if (nfss->bsize != 0)
630 seq_printf(m, ",bsize=%u", nfss->bsize);
631 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400632 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400633 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400634 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400635 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400636 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400637 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400638 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400639 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400640 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
641 if (nfss->flags & nfs_infop->flag)
642 seq_puts(m, nfs_infop->str);
643 else
644 seq_puts(m, nfs_infop->nostr);
645 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400646 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500647 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400648 if (version == 4) {
649 if (nfss->port != NFS_PORT)
650 seq_printf(m, ",port=%u", nfss->port);
651 } else
652 if (nfss->port)
653 seq_printf(m, ",port=%u", nfss->port);
654
Trond Myklebust33170232007-12-20 16:03:59 -0500655 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
656 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400657 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400658
659 if (version != 4)
660 nfs_show_mountd_options(m, nfss, showdefaults);
Trond Myklebust0be81892010-06-18 12:23:58 -0400661 else
662 nfs_show_nfsv4_options(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400663
David Howellsb797cac2009-04-03 16:42:48 +0100664 if (nfss->options & NFS_OPTION_FSCACHE)
665 seq_printf(m, ",fsc");
Patrick J. LoPresti9b00c642010-08-10 17:28:01 -0400666
667 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
668 if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
669 seq_printf(m, ",lookupcache=none");
670 else
671 seq_printf(m, ",lookupcache=pos");
672 }
David Howellsf7b422b2006-06-09 09:34:33 -0400673}
674
675/*
676 * Describe the mount options on this VFS mountpoint
677 */
678static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
679{
680 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
681
682 nfs_show_mount_options(m, nfss, 0);
683
Chuck Lever5d8515c2007-12-10 14:57:16 -0500684 seq_printf(m, ",addr=%s",
685 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
686 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400687
688 return 0;
689}
690
691/*
692 * Present statistical information for this VFS mountpoint
693 */
694static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
695{
696 int i, cpu;
697 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
698 struct rpc_auth *auth = nfss->client->cl_auth;
699 struct nfs_iostats totals = { };
700
701 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
702
703 /*
704 * Display all mount option settings
705 */
706 seq_printf(m, "\n\topts:\t");
707 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
708 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
709 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
710 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
711 nfs_show_mount_options(m, nfss, 1);
712
713 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
714
715 seq_printf(m, "\n\tcaps:\t");
716 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400717 seq_printf(m, ",wtmult=%u", nfss->wtmult);
718 seq_printf(m, ",dtsize=%u", nfss->dtsize);
719 seq_printf(m, ",bsize=%u", nfss->bsize);
720 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400721
722#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500723 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400724 seq_printf(m, "\n\tnfsv4:\t");
725 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
726 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
727 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
728 }
729#endif
730
731 /*
732 * Display security flavor in effect for this mount
733 */
Chuck Lever2d767432008-03-14 14:10:08 -0400734 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400735 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400736 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400737
738 /*
739 * Display superblock I/O counters
740 */
741 for_each_possible_cpu(cpu) {
742 struct nfs_iostats *stats;
743
744 preempt_disable();
745 stats = per_cpu_ptr(nfss->io_stats, cpu);
746
747 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
748 totals.events[i] += stats->events[i];
749 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
750 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100751#ifdef CONFIG_NFS_FSCACHE
752 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
753 totals.fscache[i] += stats->fscache[i];
754#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400755
756 preempt_enable();
757 }
758
759 seq_printf(m, "\n\tevents:\t");
760 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
761 seq_printf(m, "%lu ", totals.events[i]);
762 seq_printf(m, "\n\tbytes:\t");
763 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
764 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100765#ifdef CONFIG_NFS_FSCACHE
766 if (nfss->options & NFS_OPTION_FSCACHE) {
767 seq_printf(m, "\n\tfsc:\t");
768 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
769 seq_printf(m, "%Lu ", totals.bytes[i]);
770 }
771#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400772 seq_printf(m, "\n");
773
774 rpc_print_iostats(m, nfss->client);
775
776 return 0;
777}
778
779/*
780 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400781 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400782 */
Al Viro42faad92008-04-24 07:21:56 -0400783static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400784{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200785 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400786 struct rpc_clnt *rpc;
787
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200788 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400789 /* -EIO all pending I/O */
790 rpc = server->client_acl;
791 if (!IS_ERR(rpc))
792 rpc_killall_tasks(rpc);
793 rpc = server->client;
794 if (!IS_ERR(rpc))
795 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400796}
797
Trond Myklebustc5811db2009-10-06 15:40:15 -0400798static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400799{
800 struct nfs_parsed_mount_data *data;
801
802 data = kzalloc(sizeof(*data), GFP_KERNEL);
803 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400804 data->acregmin = NFS_DEF_ACREGMIN;
805 data->acregmax = NFS_DEF_ACREGMAX;
806 data->acdirmin = NFS_DEF_ACDIRMIN;
807 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400808 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400809 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400810 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400811 data->auth_flavors[0] = RPC_AUTH_UNIX;
812 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400813 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400814 data->minorversion = 0;
815 }
816 return data;
817}
818
David Howellsf7b422b2006-06-09 09:34:33 -0400819/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500820 * Sanity-check a server address provided by the mount command.
821 *
822 * Address family must be initialized, and address must not be
823 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400824 */
825static int nfs_verify_server_address(struct sockaddr *addr)
826{
827 switch (addr->sa_family) {
828 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500829 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700830 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500831 }
832 case AF_INET6: {
833 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
834 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400835 }
836 }
837
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400838 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400839 return 0;
840}
841
Chuck Lever9412b922007-12-10 14:59:21 -0500842/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400843 * Select between a default port value and a user-specified port value.
844 * If a zero value is set, then autobind will be used.
845 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400846static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400847 const unsigned short default_port)
848{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400849 if (*port == NFS_UNSPEC_PORT)
850 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400851
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400852 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400853}
854
855/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400856 * Sanity check the NFS transport protocol.
857 *
858 */
859static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
860{
861 switch (mnt->nfs_server.protocol) {
862 case XPRT_TRANSPORT_UDP:
863 case XPRT_TRANSPORT_TCP:
864 case XPRT_TRANSPORT_RDMA:
865 break;
866 default:
867 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
868 }
869}
870
871/*
872 * For text based NFSv2/v3 mounts, the mount protocol transport default
873 * settings should depend upon the specified NFS transport.
874 */
875static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
876{
877 nfs_validate_transport_protocol(mnt);
878
879 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
880 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
881 return;
882 switch (mnt->nfs_server.protocol) {
883 case XPRT_TRANSPORT_UDP:
884 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
885 break;
886 case XPRT_TRANSPORT_TCP:
887 case XPRT_TRANSPORT_RDMA:
888 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
889 }
890}
891
892/*
Chuck Lever01060c82008-06-24 16:33:38 -0400893 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400894 */
895static int nfs_parse_security_flavors(char *value,
896 struct nfs_parsed_mount_data *mnt)
897{
898 substring_t args[MAX_OPT_ARGS];
899
900 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
901
902 switch (match_token(value, nfs_secflavor_tokens, args)) {
903 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400904 mnt->auth_flavors[0] = RPC_AUTH_NULL;
905 break;
906 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400907 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
908 break;
909 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400910 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
911 break;
912 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400913 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
914 break;
915 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400916 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
917 break;
918 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400919 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
920 break;
921 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400922 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
923 break;
924 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400925 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
926 break;
927 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400928 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
929 break;
930 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400931 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
932 break;
933 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400934 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
935 break;
936 default:
937 return 0;
938 }
939
Chuck Lever059f90b2009-08-09 15:09:31 -0400940 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400941 return 1;
942}
943
944/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400945 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400946 * a data structure. The whole mount string is processed; bad options are
947 * skipped as they are encountered. If there were no errors, return 1;
948 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400949 */
950static int nfs_parse_mount_options(char *raw,
951 struct nfs_parsed_mount_data *mnt)
952{
Eric Parisf9c3a382008-03-05 14:20:18 -0500953 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700954 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -0500955 unsigned short protofamily = AF_UNSPEC;
956 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400957
958 if (!raw) {
959 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
960 return 1;
961 }
962 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
963
Eric Parisf9c3a382008-03-05 14:20:18 -0500964 secdata = alloc_secdata();
965 if (!secdata)
966 goto out_nomem;
967
968 rc = security_sb_copy_data(raw, secdata);
969 if (rc)
970 goto out_security_failure;
971
972 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
973 if (rc)
974 goto out_security_failure;
975
976 free_secdata(secdata);
977
Chuck Leverbf0fd762007-07-01 12:13:44 -0400978 while ((p = strsep(&raw, ",")) != NULL) {
979 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700980 unsigned long option;
981 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400982
983 if (!*p)
984 continue;
985
986 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
987
988 token = match_token(p, nfs_mount_option_tokens, args);
989 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400990
991 /*
992 * boolean options: foo/nofoo
993 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400994 case Opt_soft:
995 mnt->flags |= NFS_MOUNT_SOFT;
996 break;
997 case Opt_hard:
998 mnt->flags &= ~NFS_MOUNT_SOFT;
999 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 case Opt_posix:
1001 mnt->flags |= NFS_MOUNT_POSIX;
1002 break;
1003 case Opt_noposix:
1004 mnt->flags &= ~NFS_MOUNT_POSIX;
1005 break;
1006 case Opt_cto:
1007 mnt->flags &= ~NFS_MOUNT_NOCTO;
1008 break;
1009 case Opt_nocto:
1010 mnt->flags |= NFS_MOUNT_NOCTO;
1011 break;
1012 case Opt_ac:
1013 mnt->flags &= ~NFS_MOUNT_NOAC;
1014 break;
1015 case Opt_noac:
1016 mnt->flags |= NFS_MOUNT_NOAC;
1017 break;
1018 case Opt_lock:
1019 mnt->flags &= ~NFS_MOUNT_NONLM;
1020 break;
1021 case Opt_nolock:
1022 mnt->flags |= NFS_MOUNT_NONLM;
1023 break;
1024 case Opt_v2:
1025 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001026 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001027 break;
1028 case Opt_v3:
1029 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001030 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001031 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001032#ifdef CONFIG_NFS_V4
1033 case Opt_v4:
1034 mnt->flags &= ~NFS_MOUNT_VER3;
1035 mnt->version = 4;
1036 break;
1037#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001038 case Opt_udp:
1039 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001040 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001041 break;
1042 case Opt_tcp:
1043 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001044 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001045 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001046 case Opt_rdma:
1047 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1048 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001049 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001050 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001051 case Opt_acl:
1052 mnt->flags &= ~NFS_MOUNT_NOACL;
1053 break;
1054 case Opt_noacl:
1055 mnt->flags |= NFS_MOUNT_NOACL;
1056 break;
1057 case Opt_rdirplus:
1058 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1059 break;
1060 case Opt_nordirplus:
1061 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1062 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001063 case Opt_sharecache:
1064 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1065 break;
1066 case Opt_nosharecache:
1067 mnt->flags |= NFS_MOUNT_UNSHARED;
1068 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001069 case Opt_resvport:
1070 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1071 break;
1072 case Opt_noresvport:
1073 mnt->flags |= NFS_MOUNT_NORESVPORT;
1074 break;
David Howellsb797cac2009-04-03 16:42:48 +01001075 case Opt_fscache:
1076 mnt->options |= NFS_OPTION_FSCACHE;
1077 kfree(mnt->fscache_uniq);
1078 mnt->fscache_uniq = NULL;
1079 break;
1080 case Opt_nofscache:
1081 mnt->options &= ~NFS_OPTION_FSCACHE;
1082 kfree(mnt->fscache_uniq);
1083 mnt->fscache_uniq = NULL;
1084 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001085
Chuck Leverf45663c2008-06-24 19:28:02 -04001086 /*
1087 * options that take numeric values
1088 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001089 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001090 string = match_strdup(args);
1091 if (string == NULL)
1092 goto out_nomem;
1093 rc = strict_strtoul(string, 10, &option);
1094 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001095 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001096 goto out_invalid_value;
1097 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001098 break;
1099 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001100 string = match_strdup(args);
1101 if (string == NULL)
1102 goto out_nomem;
1103 rc = strict_strtoul(string, 10, &option);
1104 kfree(string);
1105 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001106 goto out_invalid_value;
1107 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001108 break;
1109 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001110 string = match_strdup(args);
1111 if (string == NULL)
1112 goto out_nomem;
1113 rc = strict_strtoul(string, 10, &option);
1114 kfree(string);
1115 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001116 goto out_invalid_value;
1117 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001118 break;
1119 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001120 string = match_strdup(args);
1121 if (string == NULL)
1122 goto out_nomem;
1123 rc = strict_strtoul(string, 10, &option);
1124 kfree(string);
1125 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001126 goto out_invalid_value;
1127 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001128 break;
1129 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001130 string = match_strdup(args);
1131 if (string == NULL)
1132 goto out_nomem;
1133 rc = strict_strtoul(string, 10, &option);
1134 kfree(string);
1135 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001136 goto out_invalid_value;
1137 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001138 break;
1139 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001140 string = match_strdup(args);
1141 if (string == NULL)
1142 goto out_nomem;
1143 rc = strict_strtoul(string, 10, &option);
1144 kfree(string);
1145 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001146 goto out_invalid_value;
1147 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001148 break;
1149 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001150 string = match_strdup(args);
1151 if (string == NULL)
1152 goto out_nomem;
1153 rc = strict_strtoul(string, 10, &option);
1154 kfree(string);
1155 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001156 goto out_invalid_value;
1157 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001158 break;
1159 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001160 string = match_strdup(args);
1161 if (string == NULL)
1162 goto out_nomem;
1163 rc = strict_strtoul(string, 10, &option);
1164 kfree(string);
1165 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001166 goto out_invalid_value;
1167 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001168 break;
1169 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001170 string = match_strdup(args);
1171 if (string == NULL)
1172 goto out_nomem;
1173 rc = strict_strtoul(string, 10, &option);
1174 kfree(string);
1175 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001176 goto out_invalid_value;
1177 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001178 break;
1179 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001180 string = match_strdup(args);
1181 if (string == NULL)
1182 goto out_nomem;
1183 rc = strict_strtoul(string, 10, &option);
1184 kfree(string);
1185 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001186 goto out_invalid_value;
1187 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 break;
1189 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001190 string = match_strdup(args);
1191 if (string == NULL)
1192 goto out_nomem;
1193 rc = strict_strtoul(string, 10, &option);
1194 kfree(string);
1195 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001196 goto out_invalid_value;
1197 mnt->acregmin = mnt->acregmax =
1198 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
1200 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001201 string = match_strdup(args);
1202 if (string == NULL)
1203 goto out_nomem;
1204 rc = strict_strtoul(string, 10, &option);
1205 kfree(string);
1206 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001207 goto out_invalid_value;
1208 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001209 break;
1210 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001211 string = match_strdup(args);
1212 if (string == NULL)
1213 goto out_nomem;
1214 rc = strict_strtoul(string, 10, &option);
1215 kfree(string);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001216 if (rc != 0 || option > USHRT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001217 goto out_invalid_value;
1218 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001220 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001221 string = match_strdup(args);
1222 if (string == NULL)
1223 goto out_nomem;
1224 rc = strict_strtoul(string, 10, &option);
1225 kfree(string);
1226 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001227 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001228 option > NFS_MNT3_VERSION)
1229 goto out_invalid_value;
1230 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001231 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 case Opt_nfsvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001233 string = match_strdup(args);
1234 if (string == NULL)
1235 goto out_nomem;
1236 rc = strict_strtoul(string, 10, &option);
1237 kfree(string);
1238 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001239 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001240 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001241 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001243 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001244 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001245 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001247 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001249#ifdef CONFIG_NFS_V4
1250 case NFS4_VERSION:
1251 mnt->flags &= ~NFS_MOUNT_VER3;
1252 mnt->version = 4;
1253 break;
1254#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001255 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001256 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001257 }
1258 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001259 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001260 string = match_strdup(args);
1261 if (string == NULL)
1262 goto out_nomem;
1263 rc = strict_strtoul(string, 10, &option);
1264 kfree(string);
1265 if (rc != 0)
1266 goto out_invalid_value;
1267 if (option > NFS4_MAX_MINOR_VERSION)
1268 goto out_invalid_value;
1269 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001270 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001271
Chuck Leverf45663c2008-06-24 19:28:02 -04001272 /*
1273 * options that take text values
1274 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001275 case Opt_sec:
1276 string = match_strdup(args);
1277 if (string == NULL)
1278 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001279 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001280 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001281 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001282 dfprintk(MOUNT, "NFS: unrecognized "
1283 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001284 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001285 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001286 break;
1287 case Opt_proto:
1288 string = match_strdup(args);
1289 if (string == NULL)
1290 goto out_nomem;
1291 token = match_token(string,
1292 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001293
Jeff Laytonee671b02009-12-03 15:58:56 -05001294 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001295 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001296 case Opt_xprt_udp6:
1297 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001298 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001300 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001301 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001302 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001303 case Opt_xprt_tcp6:
1304 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001305 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001307 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001308 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001309 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001310 case Opt_xprt_rdma:
1311 /* vector side protocols to TCP */
1312 mnt->flags |= NFS_MOUNT_TCP;
1313 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001314 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001315 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001316 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001318 dfprintk(MOUNT, "NFS: unrecognized "
1319 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001320 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001321 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001322 }
1323 break;
1324 case Opt_mountproto:
1325 string = match_strdup(args);
1326 if (string == NULL)
1327 goto out_nomem;
1328 token = match_token(string,
1329 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001330 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331
Jeff Laytonee671b02009-12-03 15:58:56 -05001332 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001333 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001334 case Opt_xprt_udp6:
1335 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001336 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001337 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001338 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001339 case Opt_xprt_tcp6:
1340 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001341 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001342 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001343 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001344 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001345 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001346 dfprintk(MOUNT, "NFS: unrecognized "
1347 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001348 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001349 }
1350 break;
1351 case Opt_addr:
1352 string = match_strdup(args);
1353 if (string == NULL)
1354 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001355 mnt->nfs_server.addrlen =
1356 rpc_pton(string, strlen(string),
1357 (struct sockaddr *)
1358 &mnt->nfs_server.address,
1359 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001360 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001361 if (mnt->nfs_server.addrlen == 0)
1362 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001363 break;
1364 case Opt_clientaddr:
1365 string = match_strdup(args);
1366 if (string == NULL)
1367 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001368 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001369 mnt->client_address = string;
1370 break;
Chuck Lever33832032007-12-10 14:59:13 -05001371 case Opt_mounthost:
1372 string = match_strdup(args);
1373 if (string == NULL)
1374 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001375 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001376 mnt->mount_server.hostname = string;
1377 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001378 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001379 string = match_strdup(args);
1380 if (string == NULL)
1381 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001382 mnt->mount_server.addrlen =
1383 rpc_pton(string, strlen(string),
1384 (struct sockaddr *)
1385 &mnt->mount_server.address,
1386 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001387 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001388 if (mnt->mount_server.addrlen == 0)
1389 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001390 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001391 case Opt_lookupcache:
1392 string = match_strdup(args);
1393 if (string == NULL)
1394 goto out_nomem;
1395 token = match_token(string,
1396 nfs_lookupcache_tokens, args);
1397 kfree(string);
1398 switch (token) {
1399 case Opt_lookupcache_all:
1400 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1401 break;
1402 case Opt_lookupcache_positive:
1403 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1404 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1405 break;
1406 case Opt_lookupcache_none:
1407 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1408 break;
1409 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001410 dfprintk(MOUNT, "NFS: invalid "
1411 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001412 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001413 };
1414 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001415 case Opt_fscache_uniq:
1416 string = match_strdup(args);
1417 if (string == NULL)
1418 goto out_nomem;
1419 kfree(mnt->fscache_uniq);
1420 mnt->fscache_uniq = string;
1421 mnt->options |= NFS_OPTION_FSCACHE;
1422 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001423
Chuck Leverf45663c2008-06-24 19:28:02 -04001424 /*
1425 * Special options
1426 */
1427 case Opt_sloppy:
1428 sloppy = 1;
1429 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1430 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001431 case Opt_userspace:
1432 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001433 dfprintk(MOUNT, "NFS: ignoring mount option "
1434 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001435 break;
1436
1437 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001438 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001439 dfprintk(MOUNT, "NFS: unrecognized mount option "
1440 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001441 }
1442 }
1443
Chuck Leverd23c45f2009-06-17 18:02:13 -07001444 if (!sloppy && invalid_option)
1445 return 0;
1446
Jeff Laytonee671b02009-12-03 15:58:56 -05001447 /*
1448 * verify that any proto=/mountproto= options match the address
1449 * familiies in the addr=/mountaddr= options.
1450 */
1451 if (protofamily != AF_UNSPEC &&
1452 protofamily != mnt->nfs_server.address.ss_family)
1453 goto out_proto_mismatch;
1454
1455 if (mountfamily != AF_UNSPEC) {
1456 if (mnt->mount_server.addrlen) {
1457 if (mountfamily != mnt->mount_server.address.ss_family)
1458 goto out_mountproto_mismatch;
1459 } else {
1460 if (mountfamily != mnt->nfs_server.address.ss_family)
1461 goto out_mountproto_mismatch;
1462 }
1463 }
1464
Chuck Leverbf0fd762007-07-01 12:13:44 -04001465 return 1;
1466
Jeff Laytonee671b02009-12-03 15:58:56 -05001467out_mountproto_mismatch:
1468 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1469 "option\n");
1470 return 0;
1471out_proto_mismatch:
1472 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1473 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001474out_invalid_address:
1475 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1476 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001477out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001478 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001479 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001480out_nomem:
1481 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1482 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001483out_security_failure:
1484 free_secdata(secdata);
1485 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1486 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001487}
1488
1489/*
Chuck Leverec88f282009-08-09 15:09:32 -04001490 * Match the requested auth flavors with the list returned by
1491 * the server. Returns zero and sets the mount's authentication
1492 * flavor on success; returns -EACCES if server does not support
1493 * the requested flavor.
1494 */
1495static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1496 struct nfs_mount_request *request)
1497{
1498 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1499
1500 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001501 * Certain releases of Linux's mountd return an empty
1502 * flavor list. To prevent behavioral regression with
1503 * these servers (ie. rejecting mounts that used to
1504 * succeed), revert to pre-2.6.32 behavior (no checking)
1505 * if the returned flavor list is empty.
1506 */
1507 if (server_authlist_len == 0)
1508 return 0;
1509
1510 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001511 * We avoid sophisticated negotiating here, as there are
1512 * plenty of cases where we can get it wrong, providing
1513 * either too little or too much security.
1514 *
1515 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1516 * flavor listed first. However, some servers list
1517 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1518 * preferred default, in args->auth_flavors[0] if user
1519 * didn't specify sec= mount option.
1520 */
1521 for (i = 0; i < args->auth_flavor_len; i++)
1522 for (j = 0; j < server_authlist_len; j++)
1523 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1524 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1525 request->auth_flavs[j]);
1526 args->auth_flavors[0] = request->auth_flavs[j];
1527 return 0;
1528 }
1529
1530 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1531 nfs_umount(request);
1532 return -EACCES;
1533}
1534
1535/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001536 * Use the remote server's MOUNT service to request the NFS file handle
1537 * corresponding to the provided path.
1538 */
1539static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1540 struct nfs_fh *root_fh)
1541{
Chuck Leverec88f282009-08-09 15:09:32 -04001542 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1543 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001544 struct nfs_mount_request request = {
1545 .sap = (struct sockaddr *)
1546 &args->mount_server.address,
1547 .dirpath = args->nfs_server.export_path,
1548 .protocol = args->mount_server.protocol,
1549 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001550 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001551 .auth_flav_len = &server_authlist_len,
1552 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001553 };
Chuck Lever4c568012007-12-10 14:59:28 -05001554 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001555
1556 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001557 switch (args->version) {
1558 default:
1559 args->mount_server.version = NFS_MNT3_VERSION;
1560 break;
1561 case 2:
1562 args->mount_server.version = NFS_MNT_VERSION;
1563 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001564 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001565 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001566
Chuck Lever33832032007-12-10 14:59:13 -05001567 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001568 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001569 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001570 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001571
Chuck Lever0076d7b2007-07-01 12:13:49 -04001572 /*
1573 * Construct the mount server's address.
1574 */
Chuck Lever4c568012007-12-10 14:59:28 -05001575 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001576 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001577 args->nfs_server.addrlen);
1578 args->mount_server.addrlen = args->nfs_server.addrlen;
1579 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001580 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001581 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001582
1583 /*
1584 * Now ask the mount server to map our export path
1585 * to a file handle.
1586 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001587 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001588 if (status != 0) {
1589 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1590 request.hostname, status);
1591 return status;
1592 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001593
Chuck Leverec88f282009-08-09 15:09:32 -04001594 /*
1595 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1596 */
1597 if (args->mount_server.version != NFS_MNT3_VERSION)
1598 return 0;
1599 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001600}
1601
Chuck Leverd1aa0822008-06-23 12:36:45 -04001602static int nfs_parse_simple_hostname(const char *dev_name,
1603 char **hostname, size_t maxnamlen,
1604 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001605{
1606 size_t len;
1607 char *colon, *comma;
1608
1609 colon = strchr(dev_name, ':');
1610 if (colon == NULL)
1611 goto out_bad_devname;
1612
1613 len = colon - dev_name;
1614 if (len > maxnamlen)
1615 goto out_hostname;
1616
1617 /* N.B. caller will free nfs_server.hostname in all cases */
1618 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1619 if (!*hostname)
1620 goto out_nomem;
1621
1622 /* kill possible hostname list: not supported */
1623 comma = strchr(*hostname, ',');
1624 if (comma != NULL) {
1625 if (comma == *hostname)
1626 goto out_bad_devname;
1627 *comma = '\0';
1628 }
1629
1630 colon++;
1631 len = strlen(colon);
1632 if (len > maxpathlen)
1633 goto out_path;
1634 *export_path = kstrndup(colon, len, GFP_KERNEL);
1635 if (!*export_path)
1636 goto out_nomem;
1637
1638 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1639 return 0;
1640
1641out_bad_devname:
1642 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1643 return -EINVAL;
1644
1645out_nomem:
1646 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1647 return -ENOMEM;
1648
1649out_hostname:
1650 dfprintk(MOUNT, "NFS: server hostname too long\n");
1651 return -ENAMETOOLONG;
1652
1653out_path:
1654 dfprintk(MOUNT, "NFS: export pathname too long\n");
1655 return -ENAMETOOLONG;
1656}
1657
1658/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001659 * Hostname has square brackets around it because it contains one or
1660 * more colons. We look for the first closing square bracket, and a
1661 * colon must follow it.
1662 */
1663static int nfs_parse_protected_hostname(const char *dev_name,
1664 char **hostname, size_t maxnamlen,
1665 char **export_path, size_t maxpathlen)
1666{
1667 size_t len;
1668 char *start, *end;
1669
1670 start = (char *)(dev_name + 1);
1671
1672 end = strchr(start, ']');
1673 if (end == NULL)
1674 goto out_bad_devname;
1675 if (*(end + 1) != ':')
1676 goto out_bad_devname;
1677
1678 len = end - start;
1679 if (len > maxnamlen)
1680 goto out_hostname;
1681
1682 /* N.B. caller will free nfs_server.hostname in all cases */
1683 *hostname = kstrndup(start, len, GFP_KERNEL);
1684 if (*hostname == NULL)
1685 goto out_nomem;
1686
1687 end += 2;
1688 len = strlen(end);
1689 if (len > maxpathlen)
1690 goto out_path;
1691 *export_path = kstrndup(end, len, GFP_KERNEL);
1692 if (!*export_path)
1693 goto out_nomem;
1694
1695 return 0;
1696
1697out_bad_devname:
1698 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1699 return -EINVAL;
1700
1701out_nomem:
1702 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1703 return -ENOMEM;
1704
1705out_hostname:
1706 dfprintk(MOUNT, "NFS: server hostname too long\n");
1707 return -ENAMETOOLONG;
1708
1709out_path:
1710 dfprintk(MOUNT, "NFS: export pathname too long\n");
1711 return -ENAMETOOLONG;
1712}
1713
1714/*
1715 * Split "dev_name" into "hostname:export_path".
1716 *
1717 * The leftmost colon demarks the split between the server's hostname
1718 * and the export path. If the hostname starts with a left square
1719 * bracket, then it may contain colons.
1720 *
1721 * Note: caller frees hostname and export path, even on error.
1722 */
1723static int nfs_parse_devname(const char *dev_name,
1724 char **hostname, size_t maxnamlen,
1725 char **export_path, size_t maxpathlen)
1726{
1727 if (*dev_name == '[')
1728 return nfs_parse_protected_hostname(dev_name,
1729 hostname, maxnamlen,
1730 export_path, maxpathlen);
1731
1732 return nfs_parse_simple_hostname(dev_name,
1733 hostname, maxnamlen,
1734 export_path, maxpathlen);
1735}
1736
1737/*
David Howells54ceac42006-08-22 20:06:13 -04001738 * Validate the NFS2/NFS3 mount data
1739 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001740 *
1741 * For option strings, user space handles the following behaviors:
1742 *
1743 * + DNS: mapping server host name to IP address ("addr=" option)
1744 *
1745 * + failure mode: how to behave if a mount request can't be handled
1746 * immediately ("fg/bg" option)
1747 *
1748 * + retry: how often to retry a mount request ("retry=" option)
1749 *
1750 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1751 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001752 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001753static int nfs_validate_mount_data(void *options,
1754 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001755 struct nfs_fh *mntfh,
1756 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001757{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001758 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001759 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001760
Chuck Lever5df36e72007-07-01 12:12:56 -04001761 if (data == NULL)
1762 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001763
David Howellsf7b422b2006-06-09 09:34:33 -04001764 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001765 case 1:
1766 data->namlen = 0;
1767 case 2:
1768 data->bsize = 0;
1769 case 3:
1770 if (data->flags & NFS_MOUNT_VER3)
1771 goto out_no_v3;
1772 data->root.size = NFS2_FHSIZE;
1773 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1774 case 4:
1775 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1776 goto out_no_sec;
1777 case 5:
1778 memset(data->context, 0, sizeof(data->context));
1779 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001780 if (data->flags & NFS_MOUNT_VER3) {
1781 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1782 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001783 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001784 args->version = 3;
1785 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001786 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001787 args->version = 2;
1788 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001789
Chuck Lever5df36e72007-07-01 12:12:56 -04001790
1791 memcpy(mntfh->data, data->root.data, mntfh->size);
1792 if (mntfh->size < sizeof(mntfh->data))
1793 memset(mntfh->data + mntfh->size, 0,
1794 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001795
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001796 /*
1797 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1798 * can deal with.
1799 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001800 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
Bryan Schumakerd5eff1a2010-08-03 13:04:00 -04001801 args->flags |= NFS_MOUNT_LEGACY_INTERFACE;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001802 args->rsize = data->rsize;
1803 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001804 args->timeo = data->timeo;
1805 args->retrans = data->retrans;
1806 args->acregmin = data->acregmin;
1807 args->acregmax = data->acregmax;
1808 args->acdirmin = data->acdirmin;
1809 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001810
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001811 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001812 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001813 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001814 goto out_no_address;
1815
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001816 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001817 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001818 /* N.B. caller will free nfs_server.hostname in all cases */
1819 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1820 args->namlen = data->namlen;
1821 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001822
1823 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1824 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001825 if (!args->nfs_server.hostname)
1826 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001827
1828 /*
1829 * The legacy version 6 binary mount data from userspace has a
1830 * field used only to transport selinux information into the
1831 * the kernel. To continue to support that functionality we
1832 * have a touch of selinux knowledge here in the NFS code. The
1833 * userspace code converted context=blah to just blah so we are
1834 * converting back to the full string selinux understands.
1835 */
1836 if (data->context[0]){
1837#ifdef CONFIG_SECURITY_SELINUX
1838 int rc;
1839 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1840 if (!opts_str)
1841 return -ENOMEM;
1842 strcpy(opts_str, "context=");
1843 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1844 strcat(opts_str, &data->context[0]);
1845 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1846 kfree(opts_str);
1847 if (rc)
1848 return rc;
1849#else
1850 return -EINVAL;
1851#endif
1852 }
1853
Chuck Lever5df36e72007-07-01 12:12:56 -04001854 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001855 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001856 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001857
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001858 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001859 return -EINVAL;
1860
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001861 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001862 goto out_no_address;
1863
Chuck Lever764302c2009-09-08 19:50:03 -04001864 if (args->version == 4)
1865#ifdef CONFIG_NFS_V4
1866 return nfs4_validate_text_mount_data(options,
1867 args, dev_name);
1868#else
1869 goto out_v4_not_compiled;
1870#endif
1871
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001872 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001873
Trond Myklebust259875e2008-07-02 14:43:47 -04001874 nfs_set_mount_transport_protocol(args);
1875
Chuck Leverdc045892008-06-23 12:36:37 -04001876 status = nfs_parse_devname(dev_name,
1877 &args->nfs_server.hostname,
1878 PAGE_SIZE,
1879 &args->nfs_server.export_path,
1880 NFS_MAXPATHLEN);
1881 if (!status)
1882 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001883
Chuck Leverdc045892008-06-23 12:36:37 -04001884 kfree(args->nfs_server.export_path);
1885 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001886
Chuck Lever136d5582007-07-01 12:13:54 -04001887 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001888 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001889
Chuck Lever136d5582007-07-01 12:13:54 -04001890 break;
1891 }
David Howellsf7b422b2006-06-09 09:34:33 -04001892 }
David Howells54ceac42006-08-22 20:06:13 -04001893
David Howellsf7b422b2006-06-09 09:34:33 -04001894#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001895 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001896 goto out_v3_not_compiled;
1897#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001898
David Howells54ceac42006-08-22 20:06:13 -04001899 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001900
1901out_no_data:
1902 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1903 return -EINVAL;
1904
1905out_no_v3:
1906 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1907 data->version);
1908 return -EINVAL;
1909
1910out_no_sec:
1911 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1912 return -EINVAL;
1913
Chuck Lever5df36e72007-07-01 12:12:56 -04001914#ifndef CONFIG_NFS_V3
1915out_v3_not_compiled:
1916 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1917 return -EPROTONOSUPPORT;
1918#endif /* !CONFIG_NFS_V3 */
1919
Chuck Lever764302c2009-09-08 19:50:03 -04001920#ifndef CONFIG_NFS_V4
1921out_v4_not_compiled:
1922 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1923 return -EPROTONOSUPPORT;
1924#endif /* !CONFIG_NFS_V4 */
1925
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001926out_nomem:
1927 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1928 return -ENOMEM;
1929
Chuck Lever5df36e72007-07-01 12:12:56 -04001930out_no_address:
1931 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1932 return -EINVAL;
1933
1934out_invalid_fh:
1935 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1936 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001937}
1938
Jeff Layton48b605f2008-06-10 15:38:39 -04001939static int
1940nfs_compare_remount_data(struct nfs_server *nfss,
1941 struct nfs_parsed_mount_data *data)
1942{
1943 if (data->flags != nfss->flags ||
1944 data->rsize != nfss->rsize ||
1945 data->wsize != nfss->wsize ||
1946 data->retrans != nfss->client->cl_timeout->to_retries ||
1947 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1948 data->acregmin != nfss->acregmin / HZ ||
1949 data->acregmax != nfss->acregmax / HZ ||
1950 data->acdirmin != nfss->acdirmin / HZ ||
1951 data->acdirmax != nfss->acdirmax / HZ ||
1952 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001953 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001954 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04001955 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1956 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04001957 return -EINVAL;
1958
1959 return 0;
1960}
1961
1962static int
1963nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1964{
1965 int error;
1966 struct nfs_server *nfss = sb->s_fs_info;
1967 struct nfs_parsed_mount_data *data;
1968 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1969 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001970 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001971
1972 /*
1973 * Userspace mount programs that send binary options generally send
1974 * them populated with default values. We have no way to know which
1975 * ones were explicitly specified. Fall back to legacy behavior and
1976 * just return success.
1977 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001978 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1979 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1980 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001981 return 0;
1982
1983 data = kzalloc(sizeof(*data), GFP_KERNEL);
1984 if (data == NULL)
1985 return -ENOMEM;
1986
1987 /* fill out struct with values from existing mount */
1988 data->flags = nfss->flags;
1989 data->rsize = nfss->rsize;
1990 data->wsize = nfss->wsize;
1991 data->retrans = nfss->client->cl_timeout->to_retries;
1992 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1993 data->acregmin = nfss->acregmin / HZ;
1994 data->acregmax = nfss->acregmax / HZ;
1995 data->acdirmin = nfss->acdirmin / HZ;
1996 data->acdirmax = nfss->acdirmax / HZ;
1997 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001998 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04001999 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
2000 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
2001 data->nfs_server.addrlen);
2002
2003 /* overwrite those values with any that were specified */
2004 error = nfs_parse_mount_options((char *)options, data);
2005 if (error < 0)
2006 goto out;
2007
2008 /* compare new mount options with old ones */
2009 error = nfs_compare_remount_data(nfss, data);
2010out:
2011 kfree(data);
2012 return error;
2013}
2014
David Howells54ceac42006-08-22 20:06:13 -04002015/*
2016 * Initialise the common bits of the superblock
2017 */
2018static inline void nfs_initialise_sb(struct super_block *sb)
2019{
2020 struct nfs_server *server = NFS_SB(sb);
2021
2022 sb->s_magic = NFS_SUPER_MAGIC;
2023
2024 /* We probably want something more informative here */
2025 snprintf(sb->s_id, sizeof(sb->s_id),
2026 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2027
2028 if (sb->s_blocksize == 0)
2029 sb->s_blocksize = nfs_block_bits(server->wsize,
2030 &sb->s_blocksize_bits);
2031
2032 if (server->flags & NFS_MOUNT_NOAC)
2033 sb->s_flags |= MS_SYNCHRONOUS;
2034
Jens Axboe32a88aa2009-09-16 15:02:33 +02002035 sb->s_bdi = &server->backing_dev_info;
2036
David Howells54ceac42006-08-22 20:06:13 -04002037 nfs_super_set_maxbytes(sb, server->maxfilesize);
2038}
2039
2040/*
2041 * Finish setting up an NFS2/3 superblock
2042 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002043static void nfs_fill_super(struct super_block *sb,
2044 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002045{
2046 struct nfs_server *server = NFS_SB(sb);
2047
2048 sb->s_blocksize_bits = 0;
2049 sb->s_blocksize = 0;
2050 if (data->bsize)
2051 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2052
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002053 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002054 /* The VFS shouldn't apply the umask to mode bits. We will do
2055 * so ourselves when necessary.
2056 */
2057 sb->s_flags |= MS_POSIXACL;
2058 sb->s_time_gran = 1;
2059 }
2060
2061 sb->s_op = &nfs_sops;
2062 nfs_initialise_sb(sb);
2063}
2064
2065/*
2066 * Finish setting up a cloned NFS2/3 superblock
2067 */
2068static void nfs_clone_super(struct super_block *sb,
2069 const struct super_block *old_sb)
2070{
2071 struct nfs_server *server = NFS_SB(sb);
2072
2073 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2074 sb->s_blocksize = old_sb->s_blocksize;
2075 sb->s_maxbytes = old_sb->s_maxbytes;
2076
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002077 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002078 /* The VFS shouldn't apply the umask to mode bits. We will do
2079 * so ourselves when necessary.
2080 */
2081 sb->s_flags |= MS_POSIXACL;
2082 sb->s_time_gran = 1;
2083 }
2084
2085 sb->s_op = old_sb->s_op;
2086 nfs_initialise_sb(sb);
2087}
2088
Trond Myklebust275a5d22007-05-16 16:53:28 -04002089static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2090{
2091 const struct nfs_server *a = s->s_fs_info;
2092 const struct rpc_clnt *clnt_a = a->client;
2093 const struct rpc_clnt *clnt_b = b->client;
2094
2095 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2096 goto Ebusy;
2097 if (a->nfs_client != b->nfs_client)
2098 goto Ebusy;
2099 if (a->flags != b->flags)
2100 goto Ebusy;
2101 if (a->wsize != b->wsize)
2102 goto Ebusy;
2103 if (a->rsize != b->rsize)
2104 goto Ebusy;
2105 if (a->acregmin != b->acregmin)
2106 goto Ebusy;
2107 if (a->acregmax != b->acregmax)
2108 goto Ebusy;
2109 if (a->acdirmin != b->acdirmin)
2110 goto Ebusy;
2111 if (a->acdirmax != b->acdirmax)
2112 goto Ebusy;
2113 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2114 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002115 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002116Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002117 return 0;
2118}
2119
2120struct nfs_sb_mountdata {
2121 struct nfs_server *server;
2122 int mntflags;
2123};
2124
2125static int nfs_set_super(struct super_block *s, void *data)
2126{
2127 struct nfs_sb_mountdata *sb_mntdata = data;
2128 struct nfs_server *server = sb_mntdata->server;
2129 int ret;
2130
2131 s->s_flags = sb_mntdata->mntflags;
2132 s->s_fs_info = server;
2133 ret = set_anon_super(s, server);
2134 if (ret == 0)
2135 server->s_dev = s->s_dev;
2136 return ret;
2137}
2138
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002139static int nfs_compare_super_address(struct nfs_server *server1,
2140 struct nfs_server *server2)
2141{
2142 struct sockaddr *sap1, *sap2;
2143
2144 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2145 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2146
2147 if (sap1->sa_family != sap2->sa_family)
2148 return 0;
2149
2150 switch (sap1->sa_family) {
2151 case AF_INET: {
2152 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2153 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2154 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2155 return 0;
2156 if (sin1->sin_port != sin2->sin_port)
2157 return 0;
2158 break;
2159 }
2160 case AF_INET6: {
2161 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2162 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2163 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2164 return 0;
2165 if (sin1->sin6_port != sin2->sin6_port)
2166 return 0;
2167 break;
2168 }
2169 default:
2170 return 0;
2171 }
2172
2173 return 1;
2174}
2175
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002176static int nfs_compare_super(struct super_block *sb, void *data)
2177{
2178 struct nfs_sb_mountdata *sb_mntdata = data;
2179 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2180 int mntflags = sb_mntdata->mntflags;
2181
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002182 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002183 return 0;
2184 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2185 if (old->flags & NFS_MOUNT_UNSHARED)
2186 return 0;
2187 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2188 return 0;
2189 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002190}
2191
Miklos Szeredifa799752008-04-30 00:54:33 -07002192static int nfs_bdi_register(struct nfs_server *server)
2193{
2194 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2195}
2196
David Howells54ceac42006-08-22 20:06:13 -04002197static int nfs_get_sb(struct file_system_type *fs_type,
2198 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2199{
2200 struct nfs_server *server = NULL;
2201 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002202 struct nfs_parsed_mount_data *data;
2203 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002204 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002205 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002206 struct nfs_sb_mountdata sb_mntdata = {
2207 .mntflags = flags,
2208 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002209 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002210
Trond Myklebustc5811db2009-10-06 15:40:15 -04002211 data = nfs_alloc_parsed_mount_data(3);
Trond Myklebustb157b062010-04-19 19:05:48 -04002212 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002213 if (data == NULL || mntfh == NULL)
2214 goto out_free_fh;
2215
2216 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002217
David Howells54ceac42006-08-22 20:06:13 -04002218 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002219 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002220 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002221 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002222
Chuck Lever764302c2009-09-08 19:50:03 -04002223#ifdef CONFIG_NFS_V4
2224 if (data->version == 4) {
2225 error = nfs4_try_mount(flags, dev_name, data, mnt);
2226 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002227 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002228 goto out;
2229 }
2230#endif /* CONFIG_NFS_V4 */
2231
David Howells54ceac42006-08-22 20:06:13 -04002232 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002233 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002234 if (IS_ERR(server)) {
2235 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002236 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002237 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002238 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002239
Trond Myklebust75180df2007-05-16 16:53:28 -04002240 if (server->flags & NFS_MOUNT_UNSHARED)
2241 compare_super = NULL;
2242
David Howells54ceac42006-08-22 20:06:13 -04002243 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002244 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002245 if (IS_ERR(s)) {
2246 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002247 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002248 }
2249
David Howells54ceac42006-08-22 20:06:13 -04002250 if (s->s_fs_info != server) {
2251 nfs_free_server(server);
2252 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002253 } else {
2254 error = nfs_bdi_register(server);
2255 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002256 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002257 }
David Howells54ceac42006-08-22 20:06:13 -04002258
2259 if (!s->s_root) {
2260 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002261 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002262 nfs_fscache_get_super_cookie(
2263 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002264 }
2265
Trond Myklebust33852a12008-06-19 14:20:11 -04002266 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002267 if (IS_ERR(mntroot)) {
2268 error = PTR_ERR(mntroot);
2269 goto error_splat_super;
2270 }
2271
Trond Myklebust33852a12008-06-19 14:20:11 -04002272 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002273 if (error)
2274 goto error_splat_root;
2275
David Howellsf7b422b2006-06-09 09:34:33 -04002276 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002277 mnt->mnt_sb = s;
2278 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002279 error = 0;
2280
2281out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002282 kfree(data->nfs_server.hostname);
2283 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002284 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002285 security_free_mnt_opts(&data->lsm_opts);
2286out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002287 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002288 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002289 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002290
David Howells54ceac42006-08-22 20:06:13 -04002291out_err_nosb:
2292 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002293 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002294
Eric Parisf9c3a382008-03-05 14:20:18 -05002295error_splat_root:
2296 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002297error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002298 if (server && !s->s_root)
2299 bdi_unregister(&server->backing_dev_info);
2300error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002301 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002302 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002303}
2304
David Howells54ceac42006-08-22 20:06:13 -04002305/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002306 * Ensure that we unregister the bdi before kill_anon_super
2307 * releases the device name
2308 */
2309static void nfs_put_super(struct super_block *s)
2310{
2311 struct nfs_server *server = NFS_SB(s);
2312
2313 bdi_unregister(&server->backing_dev_info);
2314}
2315
2316/*
David Howells54ceac42006-08-22 20:06:13 -04002317 * Destroy an NFS2/3 superblock
2318 */
David Howellsf7b422b2006-06-09 09:34:33 -04002319static void nfs_kill_super(struct super_block *s)
2320{
2321 struct nfs_server *server = NFS_SB(s);
2322
2323 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002324 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002325 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002326}
2327
David Howells54ceac42006-08-22 20:06:13 -04002328/*
2329 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2330 */
2331static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2332 const char *dev_name, void *raw_data,
2333 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002334{
2335 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002336 struct super_block *s;
2337 struct nfs_server *server;
2338 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002339 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002340 struct nfs_sb_mountdata sb_mntdata = {
2341 .mntflags = flags,
2342 };
David Howells54ceac42006-08-22 20:06:13 -04002343 int error;
2344
2345 dprintk("--> nfs_xdev_get_sb()\n");
2346
2347 /* create a new volume representation */
2348 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2349 if (IS_ERR(server)) {
2350 error = PTR_ERR(server);
2351 goto out_err_noserver;
2352 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002353 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002354
Trond Myklebust75180df2007-05-16 16:53:28 -04002355 if (server->flags & NFS_MOUNT_UNSHARED)
2356 compare_super = NULL;
2357
David Howells54ceac42006-08-22 20:06:13 -04002358 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002359 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002360 if (IS_ERR(s)) {
2361 error = PTR_ERR(s);
2362 goto out_err_nosb;
2363 }
2364
2365 if (s->s_fs_info != server) {
2366 nfs_free_server(server);
2367 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002368 } else {
2369 error = nfs_bdi_register(server);
2370 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002371 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002372 }
2373
2374 if (!s->s_root) {
2375 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002376 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002377 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002378 }
2379
2380 mntroot = nfs_get_root(s, data->fh);
2381 if (IS_ERR(mntroot)) {
2382 error = PTR_ERR(mntroot);
2383 goto error_splat_super;
2384 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002385 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002386 dput(mntroot);
2387 error = -ESTALE;
2388 goto error_splat_super;
2389 }
David Howells54ceac42006-08-22 20:06:13 -04002390
2391 s->s_flags |= MS_ACTIVE;
2392 mnt->mnt_sb = s;
2393 mnt->mnt_root = mntroot;
2394
Eric Parisf9c3a382008-03-05 14:20:18 -05002395 /* clone any lsm security options from the parent to the new sb */
2396 security_sb_clone_mnt_opts(data->sb, s);
2397
David Howells54ceac42006-08-22 20:06:13 -04002398 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2399 return 0;
2400
2401out_err_nosb:
2402 nfs_free_server(server);
2403out_err_noserver:
2404 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2405 return error;
2406
2407error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002408 if (server && !s->s_root)
2409 bdi_unregister(&server->backing_dev_info);
2410error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002411 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002412 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2413 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002414}
2415
2416#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002417
2418/*
2419 * Finish setting up a cloned NFS4 superblock
2420 */
2421static void nfs4_clone_super(struct super_block *sb,
2422 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002423{
David Howells54ceac42006-08-22 20:06:13 -04002424 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2425 sb->s_blocksize = old_sb->s_blocksize;
2426 sb->s_maxbytes = old_sb->s_maxbytes;
2427 sb->s_time_gran = 1;
2428 sb->s_op = old_sb->s_op;
2429 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002430}
2431
2432/*
2433 * Set up an NFS4 superblock
2434 */
David Howells54ceac42006-08-22 20:06:13 -04002435static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002436{
David Howellsf7b422b2006-06-09 09:34:33 -04002437 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002438 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002439 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002440}
2441
Trond Myklebust01c3f052009-06-17 13:22:58 -07002442static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2443{
2444 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2445}
2446
Chuck Lever7630c852009-09-08 19:49:57 -04002447static int nfs4_validate_text_mount_data(void *options,
2448 struct nfs_parsed_mount_data *args,
2449 const char *dev_name)
2450{
2451 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2452
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002453 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002454
2455 nfs_validate_transport_protocol(args);
2456
2457 nfs4_validate_mount_flags(args);
2458
Trond Myklebust2ecda722009-09-08 19:50:07 -04002459 if (args->version != 4) {
2460 dfprintk(MOUNT,
2461 "NFS4: Illegal mount version\n");
2462 return -EINVAL;
2463 }
2464
Chuck Lever7630c852009-09-08 19:49:57 -04002465 if (args->auth_flavor_len > 1) {
2466 dfprintk(MOUNT,
2467 "NFS4: Too many RPC auth flavours specified\n");
2468 return -EINVAL;
2469 }
2470
2471 if (args->client_address == NULL) {
2472 dfprintk(MOUNT,
2473 "NFS4: mount program didn't pass callback address\n");
2474 return -EINVAL;
2475 }
2476
2477 return nfs_parse_devname(dev_name,
2478 &args->nfs_server.hostname,
2479 NFS4_MAXNAMLEN,
2480 &args->nfs_server.export_path,
2481 NFS4_MAXPATHLEN);
2482}
2483
David Howells54ceac42006-08-22 20:06:13 -04002484/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002485 * Validate NFSv4 mount options
2486 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002487static int nfs4_validate_mount_data(void *options,
2488 struct nfs_parsed_mount_data *args,
2489 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002490{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002491 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002492 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002493 char *c;
2494
2495 if (data == NULL)
2496 goto out_no_data;
2497
2498 switch (data->version) {
2499 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002500 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002501 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002502 if (data->host_addrlen == 0)
2503 goto out_no_address;
2504 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002505 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002506 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002507 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002508 goto out_no_address;
2509
Chuck Lever6738b252008-06-24 16:33:54 -04002510 if (data->auth_flavourlen) {
2511 if (data->auth_flavourlen > 1)
2512 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002513 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002514 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002515 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002516 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002517 }
2518
2519 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2520 if (IS_ERR(c))
2521 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002522 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002523
2524 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2525 if (IS_ERR(c))
2526 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002527 args->nfs_server.export_path = c;
2528 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002529
2530 c = strndup_user(data->client_addr.data, 16);
2531 if (IS_ERR(c))
2532 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002533 args->client_address = c;
2534
2535 /*
2536 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2537 * can deal with.
2538 */
2539
2540 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2541 args->rsize = data->rsize;
2542 args->wsize = data->wsize;
2543 args->timeo = data->timeo;
2544 args->retrans = data->retrans;
2545 args->acregmin = data->acregmin;
2546 args->acregmax = data->acregmax;
2547 args->acdirmin = data->acdirmin;
2548 args->acdirmax = data->acdirmax;
2549 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002550 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002551
2552 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002553 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002554 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002555 return -EINVAL;
2556
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002557 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002558 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002559
Chuck Lever7630c852009-09-08 19:49:57 -04002560 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002561 }
2562
2563 return 0;
2564
2565out_no_data:
2566 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2567 return -EINVAL;
2568
2569out_inval_auth:
2570 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2571 data->auth_flavourlen);
2572 return -EINVAL;
2573
2574out_no_address:
2575 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2576 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002577}
2578
2579/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002580 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002581 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002582static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002583 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002584{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002585 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002586 struct super_block *s;
2587 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002588 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002589 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002590 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002591 struct nfs_sb_mountdata sb_mntdata = {
2592 .mntflags = flags,
2593 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002594 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002595
Trond Myklebustb157b062010-04-19 19:05:48 -04002596 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002597 if (data == NULL || mntfh == NULL)
2598 goto out_free_fh;
2599
2600 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002601
David Howells54ceac42006-08-22 20:06:13 -04002602 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002603 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002604 if (IS_ERR(server)) {
2605 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002606 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002607 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002608 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002609
Trond Myklebust75180df2007-05-16 16:53:28 -04002610 if (server->flags & NFS4_MOUNT_UNSHARED)
2611 compare_super = NULL;
2612
David Howells54ceac42006-08-22 20:06:13 -04002613 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002614 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002615 if (IS_ERR(s)) {
2616 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002617 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002618 }
2619
Trond Myklebust5dd31772006-08-24 01:03:05 -04002620 if (s->s_fs_info != server) {
2621 nfs_free_server(server);
2622 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002623 } else {
2624 error = nfs_bdi_register(server);
2625 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002626 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002627 }
2628
David Howells54ceac42006-08-22 20:06:13 -04002629 if (!s->s_root) {
2630 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002631 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002632 nfs_fscache_get_super_cookie(
2633 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002634 }
David Howellsf7b422b2006-06-09 09:34:33 -04002635
Trond Myklebust33852a12008-06-19 14:20:11 -04002636 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002637 if (IS_ERR(mntroot)) {
2638 error = PTR_ERR(mntroot);
2639 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002640 }
David Howells54ceac42006-08-22 20:06:13 -04002641
Trond Myklebust33852a12008-06-19 14:20:11 -04002642 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002643 if (error)
2644 goto error_splat_root;
2645
David Howellsf7b422b2006-06-09 09:34:33 -04002646 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002647 mnt->mnt_sb = s;
2648 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002649 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002650
Chuck Lever29eb9812007-07-01 12:12:30 -04002651out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002652 security_free_mnt_opts(&data->lsm_opts);
2653out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002654 nfs_free_fhandle(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002655 return error;
David Howells54ceac42006-08-22 20:06:13 -04002656
Chuck Lever29eb9812007-07-01 12:12:30 -04002657out_free:
2658 nfs_free_server(server);
2659 goto out;
2660
Eric Paris46c8ac72008-05-02 13:42:42 -07002661error_splat_root:
2662 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002663error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002664 if (server && !s->s_root)
2665 bdi_unregister(&server->backing_dev_info);
2666error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002667 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002668 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002669}
2670
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002671static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2672 int flags, void *data, const char *hostname)
2673{
2674 struct vfsmount *root_mnt;
2675 char *root_devname;
2676 size_t len;
2677
2678 len = strlen(hostname) + 3;
2679 root_devname = kmalloc(len, GFP_KERNEL);
2680 if (root_devname == NULL)
2681 return ERR_PTR(-ENOMEM);
2682 snprintf(root_devname, len, "%s:/", hostname);
2683 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2684 kfree(root_devname);
2685 return root_mnt;
2686}
2687
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002688static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2689{
2690 char *page = (char *) __get_free_page(GFP_KERNEL);
2691 char *devname, *tmp;
2692
2693 if (page == NULL)
2694 return;
2695 devname = nfs_path(path->mnt->mnt_devname,
2696 path->mnt->mnt_root, path->dentry,
2697 page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002698 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002699 goto out_freepage;
2700 tmp = kstrdup(devname, GFP_KERNEL);
2701 if (tmp == NULL)
2702 goto out_freepage;
2703 kfree(mnt->mnt_devname);
2704 mnt->mnt_devname = tmp;
2705out_freepage:
2706 free_page((unsigned long)page);
2707}
2708
Trond Myklebustce587e02010-04-16 16:22:52 -04002709struct nfs_referral_count {
2710 struct list_head list;
2711 const struct task_struct *task;
2712 unsigned int referral_count;
2713};
2714
2715static LIST_HEAD(nfs_referral_count_list);
2716static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2717
2718static struct nfs_referral_count *nfs_find_referral_count(void)
2719{
2720 struct nfs_referral_count *p;
2721
2722 list_for_each_entry(p, &nfs_referral_count_list, list) {
2723 if (p->task == current)
2724 return p;
2725 }
2726 return NULL;
2727}
2728
2729#define NFS_MAX_NESTED_REFERRALS 2
2730
2731static int nfs_referral_loop_protect(void)
2732{
2733 struct nfs_referral_count *p, *new;
2734 int ret = -ENOMEM;
2735
2736 new = kmalloc(sizeof(*new), GFP_KERNEL);
2737 if (!new)
2738 goto out;
2739 new->task = current;
2740 new->referral_count = 1;
2741
2742 ret = 0;
2743 spin_lock(&nfs_referral_count_list_lock);
2744 p = nfs_find_referral_count();
2745 if (p != NULL) {
2746 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2747 ret = -ELOOP;
2748 else
2749 p->referral_count++;
2750 } else {
2751 list_add(&new->list, &nfs_referral_count_list);
2752 new = NULL;
2753 }
2754 spin_unlock(&nfs_referral_count_list_lock);
2755 kfree(new);
2756out:
2757 return ret;
2758}
2759
2760static void nfs_referral_loop_unprotect(void)
2761{
2762 struct nfs_referral_count *p;
2763
2764 spin_lock(&nfs_referral_count_list_lock);
2765 p = nfs_find_referral_count();
2766 p->referral_count--;
2767 if (p->referral_count == 0)
2768 list_del(&p->list);
2769 else
2770 p = NULL;
2771 spin_unlock(&nfs_referral_count_list_lock);
2772 kfree(p);
2773}
2774
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002775static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2776 const char *export_path, struct vfsmount *mnt_target)
2777{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002778 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002779 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002780 struct super_block *s;
2781 int ret;
2782
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002783 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2784 if (nd == NULL)
2785 return -ENOMEM;
2786
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002787 ns_private = create_mnt_ns(root_mnt);
2788 ret = PTR_ERR(ns_private);
2789 if (IS_ERR(ns_private))
2790 goto out_mntput;
2791
Trond Myklebustce587e02010-04-16 16:22:52 -04002792 ret = nfs_referral_loop_protect();
2793 if (ret != 0)
2794 goto out_put_mnt_ns;
2795
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002796 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002797 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002798
Trond Myklebustce587e02010-04-16 16:22:52 -04002799 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002800 put_mnt_ns(ns_private);
2801
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002802 if (ret != 0)
2803 goto out_err;
2804
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002805 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002806 atomic_inc(&s->s_active);
2807 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002808 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002809
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002810 /* Correct the device pathname */
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002811 nfs_fix_devname(&nd->path, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002812
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002813 path_put(&nd->path);
2814 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002815 down_write(&s->s_umount);
2816 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002817out_put_mnt_ns:
2818 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002819out_mntput:
2820 mntput(root_mnt);
2821out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002822 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002823 return ret;
2824}
2825
Chuck Levera6fe23b2009-09-08 19:50:00 -04002826static int nfs4_try_mount(int flags, const char *dev_name,
2827 struct nfs_parsed_mount_data *data,
2828 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002829{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002830 char *export_path;
2831 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002832 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002833
Chuck Levera6fe23b2009-09-08 19:50:00 -04002834 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002835
2836 export_path = data->nfs_server.export_path;
2837 data->nfs_server.export_path = "/";
2838 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2839 data->nfs_server.hostname);
2840 data->nfs_server.export_path = export_path;
2841
2842 error = PTR_ERR(root_mnt);
2843 if (IS_ERR(root_mnt))
2844 goto out;
2845
2846 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2847
2848out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002849 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2850 error != 0 ? " [error]" : "");
2851 return error;
2852}
2853
2854/*
2855 * Get the superblock for an NFS4 mountpoint
2856 */
2857static int nfs4_get_sb(struct file_system_type *fs_type,
2858 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2859{
2860 struct nfs_parsed_mount_data *data;
2861 int error = -ENOMEM;
2862
Trond Myklebustc5811db2009-10-06 15:40:15 -04002863 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002864 if (data == NULL)
2865 goto out_free_data;
2866
2867 /* Validate the mount data */
2868 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2869 if (error < 0)
2870 goto out;
2871
2872 error = nfs4_try_mount(flags, dev_name, data, mnt);
2873
2874out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002875 kfree(data->client_address);
2876 kfree(data->nfs_server.export_path);
2877 kfree(data->nfs_server.hostname);
2878 kfree(data->fscache_uniq);
2879out_free_data:
2880 kfree(data);
2881 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2882 error != 0 ? " [error]" : "");
2883 return error;
2884}
2885
David Howellsf7b422b2006-06-09 09:34:33 -04002886static void nfs4_kill_super(struct super_block *sb)
2887{
2888 struct nfs_server *server = NFS_SB(sb);
2889
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002890 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002891 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002892 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002893 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002894 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002895 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002896}
2897
2898/*
David Howells54ceac42006-08-22 20:06:13 -04002899 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002900 */
David Howells54ceac42006-08-22 20:06:13 -04002901static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2902 const char *dev_name, void *raw_data,
2903 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002904{
2905 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002906 struct super_block *s;
2907 struct nfs_server *server;
2908 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002909 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002910 struct nfs_sb_mountdata sb_mntdata = {
2911 .mntflags = flags,
2912 };
David Howells54ceac42006-08-22 20:06:13 -04002913 int error;
2914
2915 dprintk("--> nfs4_xdev_get_sb()\n");
2916
2917 /* create a new volume representation */
2918 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2919 if (IS_ERR(server)) {
2920 error = PTR_ERR(server);
2921 goto out_err_noserver;
2922 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002923 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002924
Trond Myklebust75180df2007-05-16 16:53:28 -04002925 if (server->flags & NFS4_MOUNT_UNSHARED)
2926 compare_super = NULL;
2927
David Howells54ceac42006-08-22 20:06:13 -04002928 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002929 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002930 if (IS_ERR(s)) {
2931 error = PTR_ERR(s);
2932 goto out_err_nosb;
2933 }
2934
2935 if (s->s_fs_info != server) {
2936 nfs_free_server(server);
2937 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002938 } else {
2939 error = nfs_bdi_register(server);
2940 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002941 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002942 }
2943
2944 if (!s->s_root) {
2945 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002946 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002947 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002948 }
2949
2950 mntroot = nfs4_get_root(s, data->fh);
2951 if (IS_ERR(mntroot)) {
2952 error = PTR_ERR(mntroot);
2953 goto error_splat_super;
2954 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002955 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2956 dput(mntroot);
2957 error = -ESTALE;
2958 goto error_splat_super;
2959 }
David Howells54ceac42006-08-22 20:06:13 -04002960
2961 s->s_flags |= MS_ACTIVE;
2962 mnt->mnt_sb = s;
2963 mnt->mnt_root = mntroot;
2964
Eric Paris46c8ac72008-05-02 13:42:42 -07002965 security_sb_clone_mnt_opts(data->sb, s);
2966
David Howells54ceac42006-08-22 20:06:13 -04002967 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2968 return 0;
2969
2970out_err_nosb:
2971 nfs_free_server(server);
2972out_err_noserver:
2973 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2974 return error;
2975
2976error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002977 if (server && !s->s_root)
2978 bdi_unregister(&server->backing_dev_info);
2979error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002980 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002981 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2982 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002983}
2984
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002985static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2986 int flags, const char *dev_name, void *raw_data,
2987 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002988{
2989 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002990 struct super_block *s;
2991 struct nfs_server *server;
2992 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002993 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002994 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002995 struct nfs_sb_mountdata sb_mntdata = {
2996 .mntflags = flags,
2997 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002998 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002999
3000 dprintk("--> nfs4_referral_get_sb()\n");
3001
Trond Myklebust4f727292010-04-16 16:22:48 -04003002 mntfh = nfs_alloc_fhandle();
3003 if (mntfh == NULL)
3004 goto out_err_nofh;
3005
David Howells54ceac42006-08-22 20:06:13 -04003006 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04003007 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003008 if (IS_ERR(server)) {
3009 error = PTR_ERR(server);
3010 goto out_err_noserver;
3011 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04003012 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04003013
Trond Myklebust75180df2007-05-16 16:53:28 -04003014 if (server->flags & NFS4_MOUNT_UNSHARED)
3015 compare_super = NULL;
3016
David Howells54ceac42006-08-22 20:06:13 -04003017 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04003018 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04003019 if (IS_ERR(s)) {
3020 error = PTR_ERR(s);
3021 goto out_err_nosb;
3022 }
3023
3024 if (s->s_fs_info != server) {
3025 nfs_free_server(server);
3026 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07003027 } else {
3028 error = nfs_bdi_register(server);
3029 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11003030 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04003031 }
3032
3033 if (!s->s_root) {
3034 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003035 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003036 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003037 }
3038
Trond Myklebust4f727292010-04-16 16:22:48 -04003039 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003040 if (IS_ERR(mntroot)) {
3041 error = PTR_ERR(mntroot);
3042 goto error_splat_super;
3043 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003044 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3045 dput(mntroot);
3046 error = -ESTALE;
3047 goto error_splat_super;
3048 }
David Howells54ceac42006-08-22 20:06:13 -04003049
3050 s->s_flags |= MS_ACTIVE;
3051 mnt->mnt_sb = s;
3052 mnt->mnt_root = mntroot;
3053
Eric Paris46c8ac72008-05-02 13:42:42 -07003054 security_sb_clone_mnt_opts(data->sb, s);
3055
Trond Myklebust4f727292010-04-16 16:22:48 -04003056 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003057 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3058 return 0;
3059
3060out_err_nosb:
3061 nfs_free_server(server);
3062out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003063 nfs_free_fhandle(mntfh);
3064out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003065 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3066 return error;
3067
3068error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003069 if (server && !s->s_root)
3070 bdi_unregister(&server->backing_dev_info);
3071error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003072 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003073 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003074 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3075 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04003076}
3077
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003078/*
3079 * Create an NFS4 server record on referral traversal
3080 */
3081static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3082 int flags, const char *dev_name, void *raw_data,
3083 struct vfsmount *mnt)
3084{
3085 struct nfs_clone_mount *data = raw_data;
3086 char *export_path;
3087 struct vfsmount *root_mnt;
3088 int error;
3089
3090 dprintk("--> nfs4_referral_get_sb()\n");
3091
3092 export_path = data->mnt_path;
3093 data->mnt_path = "/";
3094
3095 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3096 flags, data, data->hostname);
3097 data->mnt_path = export_path;
3098
3099 error = PTR_ERR(root_mnt);
3100 if (IS_ERR(root_mnt))
3101 goto out;
3102
3103 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3104out:
3105 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3106 error != 0 ? " [error]" : "");
3107 return error;
3108}
3109
David Howells54ceac42006-08-22 20:06:13 -04003110#endif /* CONFIG_NFS_V4 */