blob: 2f8b1157daa2cf279d4e5562300e250c3bec6c9e [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,
273 .clear_inode = nfs_clear_inode,
274 .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,
343 .clear_inode = nfs4_clear_inode,
344 .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);
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400434
435 nfs_free_fattr(res.fattr);
David Howellsf7b422b2006-06-09 09:34:33 -0400436 if (error < 0)
437 goto out_err;
Trond Myklebustca7e9a02010-04-16 16:22:52 -0400438
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700439 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400440
441 /*
442 * Current versions of glibc do not correctly handle the
443 * case where f_frsize != f_bsize. Eventually we want to
444 * report the value of wtmult in this field.
445 */
David Howells0c7d90c2006-08-22 20:06:10 -0400446 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400447
448 /*
449 * On most *nix systems, f_blocks, f_bfree, and f_bavail
450 * are reported in units of f_frsize. Linux hasn't had
451 * an f_frsize field in its statfs struct until recently,
452 * thus historically Linux's sys_statfs reports these
453 * fields in units of f_bsize.
454 */
David Howells0c7d90c2006-08-22 20:06:10 -0400455 buf->f_bsize = dentry->d_sb->s_blocksize;
456 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400457 blockres = (1 << blockbits) - 1;
458 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
459 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
460 buf->f_bavail = (res.abytes + blockres) >> blockbits;
461
462 buf->f_files = res.tfiles;
463 buf->f_ffree = res.afiles;
464
465 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700466
David Howellsf7b422b2006-06-09 09:34:33 -0400467 return 0;
468
469 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700470 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700471 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400472}
473
David Howells7d4e2742006-08-22 20:06:07 -0400474/*
475 * Map the security flavour number to a name
476 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400477static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
478{
David Howells7d4e2742006-08-22 20:06:07 -0400479 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400480 rpc_authflavor_t flavour;
481 const char *str;
482 } sec_flavours[] = {
483 { RPC_AUTH_NULL, "null" },
484 { RPC_AUTH_UNIX, "sys" },
485 { RPC_AUTH_GSS_KRB5, "krb5" },
486 { RPC_AUTH_GSS_KRB5I, "krb5i" },
487 { RPC_AUTH_GSS_KRB5P, "krb5p" },
488 { RPC_AUTH_GSS_LKEY, "lkey" },
489 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
490 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
491 { RPC_AUTH_GSS_SPKM, "spkm" },
492 { RPC_AUTH_GSS_SPKMI, "spkmi" },
493 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400494 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400495 };
496 int i;
497
Chuck Lever4d81cd12007-07-01 12:12:40 -0400498 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400499 if (sec_flavours[i].flavour == flavour)
500 break;
501 }
502 return sec_flavours[i].str;
503}
504
Jeff Laytonee671b02009-12-03 15:58:56 -0500505static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
506 int showdefaults)
507{
508 struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
509
510 seq_printf(m, ",mountproto=");
511 switch (sap->sa_family) {
512 case AF_INET:
513 switch (nfss->mountd_protocol) {
514 case IPPROTO_UDP:
515 seq_printf(m, RPCBIND_NETID_UDP);
516 break;
517 case IPPROTO_TCP:
518 seq_printf(m, RPCBIND_NETID_TCP);
519 break;
520 default:
521 if (showdefaults)
522 seq_printf(m, "auto");
523 }
524 break;
525 case AF_INET6:
526 switch (nfss->mountd_protocol) {
527 case IPPROTO_UDP:
528 seq_printf(m, RPCBIND_NETID_UDP6);
529 break;
530 case IPPROTO_TCP:
531 seq_printf(m, RPCBIND_NETID_TCP6);
532 break;
533 default:
534 if (showdefaults)
535 seq_printf(m, "auto");
536 }
537 break;
538 default:
539 if (showdefaults)
540 seq_printf(m, "auto");
541 }
542}
543
Chuck Lever82d101d2008-03-14 14:10:37 -0400544static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
545 int showdefaults)
546{
547 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
548
549 switch (sap->sa_family) {
550 case AF_INET: {
551 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700552 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400553 break;
554 }
555 case AF_INET6: {
556 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Chuck Leverd250e192009-12-03 15:58:56 -0500557 seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400558 break;
559 }
560 default:
561 if (showdefaults)
562 seq_printf(m, ",mountaddr=unspecified");
563 }
564
565 if (nfss->mountd_version || showdefaults)
566 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
567 if (nfss->mountd_port || showdefaults)
568 seq_printf(m, ",mountport=%u", nfss->mountd_port);
569
Jeff Laytonee671b02009-12-03 15:58:56 -0500570 nfs_show_mountd_netid(m, nfss, showdefaults);
Chuck Lever82d101d2008-03-14 14:10:37 -0400571}
572
David Howellsf7b422b2006-06-09 09:34:33 -0400573/*
574 * Describe the mount options in force on this server representation
575 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400576static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
577 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400578{
David Howells509de812006-08-22 20:06:11 -0400579 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400580 int flag;
David Howells509de812006-08-22 20:06:11 -0400581 const char *str;
582 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400583 } nfs_info[] = {
584 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400585 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400586 { NFS_MOUNT_NOCTO, ",nocto", "" },
587 { NFS_MOUNT_NOAC, ",noac", "" },
588 { NFS_MOUNT_NONLM, ",nolock", "" },
589 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400590 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Chuck Leverd7403512008-12-23 15:21:37 -0500591 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
592 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400593 { 0, NULL, NULL }
594 };
David Howells509de812006-08-22 20:06:11 -0400595 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400596 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400597 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400598
Chuck Lever82d101d2008-03-14 14:10:37 -0400599 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400600 seq_printf(m, ",rsize=%u", nfss->rsize);
601 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400602 if (nfss->bsize != 0)
603 seq_printf(m, ",bsize=%u", nfss->bsize);
604 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400605 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400606 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400607 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400608 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400609 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400610 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400611 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400612 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400613 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
614 if (nfss->flags & nfs_infop->flag)
615 seq_puts(m, nfs_infop->str);
616 else
617 seq_puts(m, nfs_infop->nostr);
618 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400619 seq_printf(m, ",proto=%s",
Jeff Laytonee671b02009-12-03 15:58:56 -0500620 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
Chuck Lever82d101d2008-03-14 14:10:37 -0400621 if (version == 4) {
622 if (nfss->port != NFS_PORT)
623 seq_printf(m, ",port=%u", nfss->port);
624 } else
625 if (nfss->port)
626 seq_printf(m, ",port=%u", nfss->port);
627
Trond Myklebust33170232007-12-20 16:03:59 -0500628 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
629 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400630 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400631
632 if (version != 4)
633 nfs_show_mountd_options(m, nfss, showdefaults);
634
635#ifdef CONFIG_NFS_V4
636 if (clp->rpc_ops->version == 4)
637 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
638#endif
David Howellsb797cac2009-04-03 16:42:48 +0100639 if (nfss->options & NFS_OPTION_FSCACHE)
640 seq_printf(m, ",fsc");
David Howellsf7b422b2006-06-09 09:34:33 -0400641}
642
643/*
644 * Describe the mount options on this VFS mountpoint
645 */
646static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
647{
648 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
649
650 nfs_show_mount_options(m, nfss, 0);
651
Chuck Lever5d8515c2007-12-10 14:57:16 -0500652 seq_printf(m, ",addr=%s",
653 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
654 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400655
656 return 0;
657}
658
659/*
660 * Present statistical information for this VFS mountpoint
661 */
662static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
663{
664 int i, cpu;
665 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
666 struct rpc_auth *auth = nfss->client->cl_auth;
667 struct nfs_iostats totals = { };
668
669 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
670
671 /*
672 * Display all mount option settings
673 */
674 seq_printf(m, "\n\topts:\t");
675 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
676 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
677 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
678 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
679 nfs_show_mount_options(m, nfss, 1);
680
681 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
682
683 seq_printf(m, "\n\tcaps:\t");
684 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400685 seq_printf(m, ",wtmult=%u", nfss->wtmult);
686 seq_printf(m, ",dtsize=%u", nfss->dtsize);
687 seq_printf(m, ",bsize=%u", nfss->bsize);
688 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400689
690#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500691 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400692 seq_printf(m, "\n\tnfsv4:\t");
693 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
694 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
695 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
696 }
697#endif
698
699 /*
700 * Display security flavor in effect for this mount
701 */
Chuck Lever2d767432008-03-14 14:10:08 -0400702 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400703 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400704 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400705
706 /*
707 * Display superblock I/O counters
708 */
709 for_each_possible_cpu(cpu) {
710 struct nfs_iostats *stats;
711
712 preempt_disable();
713 stats = per_cpu_ptr(nfss->io_stats, cpu);
714
715 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
716 totals.events[i] += stats->events[i];
717 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
718 totals.bytes[i] += stats->bytes[i];
David Howells6a510912009-04-03 16:42:43 +0100719#ifdef CONFIG_NFS_FSCACHE
720 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
721 totals.fscache[i] += stats->fscache[i];
722#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400723
724 preempt_enable();
725 }
726
727 seq_printf(m, "\n\tevents:\t");
728 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
729 seq_printf(m, "%lu ", totals.events[i]);
730 seq_printf(m, "\n\tbytes:\t");
731 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
732 seq_printf(m, "%Lu ", totals.bytes[i]);
David Howells6a510912009-04-03 16:42:43 +0100733#ifdef CONFIG_NFS_FSCACHE
734 if (nfss->options & NFS_OPTION_FSCACHE) {
735 seq_printf(m, "\n\tfsc:\t");
736 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
737 seq_printf(m, "%Lu ", totals.bytes[i]);
738 }
739#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400740 seq_printf(m, "\n");
741
742 rpc_print_iostats(m, nfss->client);
743
744 return 0;
745}
746
747/*
748 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400749 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400750 */
Al Viro42faad92008-04-24 07:21:56 -0400751static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400752{
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200753 struct nfs_server *server;
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400754 struct rpc_clnt *rpc;
755
Alessio Igor Bogani67e55202009-04-24 09:06:53 +0200756 server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400757 /* -EIO all pending I/O */
758 rpc = server->client_acl;
759 if (!IS_ERR(rpc))
760 rpc_killall_tasks(rpc);
761 rpc = server->client;
762 if (!IS_ERR(rpc))
763 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400764}
765
Trond Myklebustc5811db2009-10-06 15:40:15 -0400766static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
Chuck Lever9423a082009-09-23 14:36:38 -0400767{
768 struct nfs_parsed_mount_data *data;
769
770 data = kzalloc(sizeof(*data), GFP_KERNEL);
771 if (data) {
Chuck Lever9423a082009-09-23 14:36:38 -0400772 data->acregmin = NFS_DEF_ACREGMIN;
773 data->acregmax = NFS_DEF_ACREGMAX;
774 data->acdirmin = NFS_DEF_ACDIRMIN;
775 data->acdirmax = NFS_DEF_ACDIRMAX;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400776 data->mount_server.port = NFS_UNSPEC_PORT;
Chuck Lever9423a082009-09-23 14:36:38 -0400777 data->nfs_server.port = NFS_UNSPEC_PORT;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400778 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Lever9423a082009-09-23 14:36:38 -0400779 data->auth_flavors[0] = RPC_AUTH_UNIX;
780 data->auth_flavor_len = 1;
Trond Myklebustc5811db2009-10-06 15:40:15 -0400781 data->version = version;
Chuck Lever9423a082009-09-23 14:36:38 -0400782 data->minorversion = 0;
783 }
784 return data;
785}
786
David Howellsf7b422b2006-06-09 09:34:33 -0400787/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500788 * Sanity-check a server address provided by the mount command.
789 *
790 * Address family must be initialized, and address must not be
791 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400792 */
793static int nfs_verify_server_address(struct sockaddr *addr)
794{
795 switch (addr->sa_family) {
796 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500797 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700798 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500799 }
800 case AF_INET6: {
801 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
802 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400803 }
804 }
805
Chuck Lever53a0b9c2009-08-09 15:09:36 -0400806 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
Chuck Leverfc50d582007-07-01 12:12:46 -0400807 return 0;
808}
809
Chuck Lever9412b922007-12-10 14:59:21 -0500810/*
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400811 * Select between a default port value and a user-specified port value.
812 * If a zero value is set, then autobind will be used.
813 */
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400814static void nfs_set_port(struct sockaddr *sap, int *port,
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400815 const unsigned short default_port)
816{
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400817 if (*port == NFS_UNSPEC_PORT)
818 *port = default_port;
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400819
Trond Myklebustf5855fe2009-10-06 15:40:37 -0400820 rpc_set_port(sap, *port);
Chuck Lever4cfd74f2009-09-08 19:49:47 -0400821}
822
823/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400824 * Sanity check the NFS transport protocol.
825 *
826 */
827static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
828{
829 switch (mnt->nfs_server.protocol) {
830 case XPRT_TRANSPORT_UDP:
831 case XPRT_TRANSPORT_TCP:
832 case XPRT_TRANSPORT_RDMA:
833 break;
834 default:
835 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
836 }
837}
838
839/*
840 * For text based NFSv2/v3 mounts, the mount protocol transport default
841 * settings should depend upon the specified NFS transport.
842 */
843static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
844{
845 nfs_validate_transport_protocol(mnt);
846
847 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
848 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
849 return;
850 switch (mnt->nfs_server.protocol) {
851 case XPRT_TRANSPORT_UDP:
852 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
853 break;
854 case XPRT_TRANSPORT_TCP:
855 case XPRT_TRANSPORT_RDMA:
856 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
857 }
858}
859
860/*
Chuck Lever01060c82008-06-24 16:33:38 -0400861 * Parse the value of the 'sec=' option.
Chuck Lever01060c82008-06-24 16:33:38 -0400862 */
863static int nfs_parse_security_flavors(char *value,
864 struct nfs_parsed_mount_data *mnt)
865{
866 substring_t args[MAX_OPT_ARGS];
867
868 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
869
870 switch (match_token(value, nfs_secflavor_tokens, args)) {
871 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400872 mnt->auth_flavors[0] = RPC_AUTH_NULL;
873 break;
874 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400875 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
876 break;
877 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400878 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
879 break;
880 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400881 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
882 break;
883 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400884 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
885 break;
886 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400887 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
888 break;
889 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400890 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
891 break;
892 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400893 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
894 break;
895 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400896 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
897 break;
898 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400899 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
900 break;
901 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400902 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
903 break;
904 default:
905 return 0;
906 }
907
Chuck Lever059f90b2009-08-09 15:09:31 -0400908 mnt->auth_flavor_len = 1;
Chuck Lever01060c82008-06-24 16:33:38 -0400909 return 1;
910}
911
912/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400913 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400914 * a data structure. The whole mount string is processed; bad options are
915 * skipped as they are encountered. If there were no errors, return 1;
916 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400917 */
918static int nfs_parse_mount_options(char *raw,
919 struct nfs_parsed_mount_data *mnt)
920{
Eric Parisf9c3a382008-03-05 14:20:18 -0500921 char *p, *string, *secdata;
Chuck Leverd23c45f2009-06-17 18:02:13 -0700922 int rc, sloppy = 0, invalid_option = 0;
Jeff Laytonee671b02009-12-03 15:58:56 -0500923 unsigned short protofamily = AF_UNSPEC;
924 unsigned short mountfamily = AF_UNSPEC;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400925
926 if (!raw) {
927 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
928 return 1;
929 }
930 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
931
Eric Parisf9c3a382008-03-05 14:20:18 -0500932 secdata = alloc_secdata();
933 if (!secdata)
934 goto out_nomem;
935
936 rc = security_sb_copy_data(raw, secdata);
937 if (rc)
938 goto out_security_failure;
939
940 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
941 if (rc)
942 goto out_security_failure;
943
944 free_secdata(secdata);
945
Chuck Leverbf0fd762007-07-01 12:13:44 -0400946 while ((p = strsep(&raw, ",")) != NULL) {
947 substring_t args[MAX_OPT_ARGS];
Chuck Levera5a16ba2009-06-17 18:02:14 -0700948 unsigned long option;
949 int token;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950
951 if (!*p)
952 continue;
953
954 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
955
956 token = match_token(p, nfs_mount_option_tokens, args);
957 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400958
959 /*
960 * boolean options: foo/nofoo
961 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400962 case Opt_soft:
963 mnt->flags |= NFS_MOUNT_SOFT;
964 break;
965 case Opt_hard:
966 mnt->flags &= ~NFS_MOUNT_SOFT;
967 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400968 case Opt_posix:
969 mnt->flags |= NFS_MOUNT_POSIX;
970 break;
971 case Opt_noposix:
972 mnt->flags &= ~NFS_MOUNT_POSIX;
973 break;
974 case Opt_cto:
975 mnt->flags &= ~NFS_MOUNT_NOCTO;
976 break;
977 case Opt_nocto:
978 mnt->flags |= NFS_MOUNT_NOCTO;
979 break;
980 case Opt_ac:
981 mnt->flags &= ~NFS_MOUNT_NOAC;
982 break;
983 case Opt_noac:
984 mnt->flags |= NFS_MOUNT_NOAC;
985 break;
986 case Opt_lock:
987 mnt->flags &= ~NFS_MOUNT_NONLM;
988 break;
989 case Opt_nolock:
990 mnt->flags |= NFS_MOUNT_NONLM;
991 break;
992 case Opt_v2:
993 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400994 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400995 break;
996 case Opt_v3:
997 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -0400998 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400999 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001000#ifdef CONFIG_NFS_V4
1001 case Opt_v4:
1002 mnt->flags &= ~NFS_MOUNT_VER3;
1003 mnt->version = 4;
1004 break;
1005#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001006 case Opt_udp:
1007 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001008 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001009 break;
1010 case Opt_tcp:
1011 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001012 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001013 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001014 case Opt_rdma:
1015 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1016 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001017 xprt_load_transport(p);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001018 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001019 case Opt_acl:
1020 mnt->flags &= ~NFS_MOUNT_NOACL;
1021 break;
1022 case Opt_noacl:
1023 mnt->flags |= NFS_MOUNT_NOACL;
1024 break;
1025 case Opt_rdirplus:
1026 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1027 break;
1028 case Opt_nordirplus:
1029 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1030 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001031 case Opt_sharecache:
1032 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1033 break;
1034 case Opt_nosharecache:
1035 mnt->flags |= NFS_MOUNT_UNSHARED;
1036 break;
Chuck Leverd7403512008-12-23 15:21:37 -05001037 case Opt_resvport:
1038 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1039 break;
1040 case Opt_noresvport:
1041 mnt->flags |= NFS_MOUNT_NORESVPORT;
1042 break;
David Howellsb797cac2009-04-03 16:42:48 +01001043 case Opt_fscache:
1044 mnt->options |= NFS_OPTION_FSCACHE;
1045 kfree(mnt->fscache_uniq);
1046 mnt->fscache_uniq = NULL;
1047 break;
1048 case Opt_nofscache:
1049 mnt->options &= ~NFS_OPTION_FSCACHE;
1050 kfree(mnt->fscache_uniq);
1051 mnt->fscache_uniq = NULL;
1052 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001053
Chuck Leverf45663c2008-06-24 19:28:02 -04001054 /*
1055 * options that take numeric values
1056 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001057 case Opt_port:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001058 string = match_strdup(args);
1059 if (string == NULL)
1060 goto out_nomem;
1061 rc = strict_strtoul(string, 10, &option);
1062 kfree(string);
1063 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001064 goto out_invalid_value;
1065 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001066 break;
1067 case Opt_rsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001068 string = match_strdup(args);
1069 if (string == NULL)
1070 goto out_nomem;
1071 rc = strict_strtoul(string, 10, &option);
1072 kfree(string);
1073 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001074 goto out_invalid_value;
1075 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001076 break;
1077 case Opt_wsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001078 string = match_strdup(args);
1079 if (string == NULL)
1080 goto out_nomem;
1081 rc = strict_strtoul(string, 10, &option);
1082 kfree(string);
1083 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001084 goto out_invalid_value;
1085 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001086 break;
1087 case Opt_bsize:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001088 string = match_strdup(args);
1089 if (string == NULL)
1090 goto out_nomem;
1091 rc = strict_strtoul(string, 10, &option);
1092 kfree(string);
1093 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001094 goto out_invalid_value;
1095 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001096 break;
1097 case Opt_timeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001098 string = match_strdup(args);
1099 if (string == NULL)
1100 goto out_nomem;
1101 rc = strict_strtoul(string, 10, &option);
1102 kfree(string);
1103 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001104 goto out_invalid_value;
1105 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001106 break;
1107 case Opt_retrans:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001108 string = match_strdup(args);
1109 if (string == NULL)
1110 goto out_nomem;
1111 rc = strict_strtoul(string, 10, &option);
1112 kfree(string);
1113 if (rc != 0 || option == 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001114 goto out_invalid_value;
1115 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001116 break;
1117 case Opt_acregmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001118 string = match_strdup(args);
1119 if (string == NULL)
1120 goto out_nomem;
1121 rc = strict_strtoul(string, 10, &option);
1122 kfree(string);
1123 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001124 goto out_invalid_value;
1125 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126 break;
1127 case Opt_acregmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001128 string = match_strdup(args);
1129 if (string == NULL)
1130 goto out_nomem;
1131 rc = strict_strtoul(string, 10, &option);
1132 kfree(string);
1133 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001134 goto out_invalid_value;
1135 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001136 break;
1137 case Opt_acdirmin:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001138 string = match_strdup(args);
1139 if (string == NULL)
1140 goto out_nomem;
1141 rc = strict_strtoul(string, 10, &option);
1142 kfree(string);
1143 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001144 goto out_invalid_value;
1145 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001146 break;
1147 case Opt_acdirmax:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001148 string = match_strdup(args);
1149 if (string == NULL)
1150 goto out_nomem;
1151 rc = strict_strtoul(string, 10, &option);
1152 kfree(string);
1153 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001154 goto out_invalid_value;
1155 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001156 break;
1157 case Opt_actimeo:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001158 string = match_strdup(args);
1159 if (string == NULL)
1160 goto out_nomem;
1161 rc = strict_strtoul(string, 10, &option);
1162 kfree(string);
1163 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001164 goto out_invalid_value;
1165 mnt->acregmin = mnt->acregmax =
1166 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001167 break;
1168 case Opt_namelen:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001169 string = match_strdup(args);
1170 if (string == NULL)
1171 goto out_nomem;
1172 rc = strict_strtoul(string, 10, &option);
1173 kfree(string);
1174 if (rc != 0)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001175 goto out_invalid_value;
1176 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001177 break;
1178 case Opt_mountport:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001179 string = match_strdup(args);
1180 if (string == NULL)
1181 goto out_nomem;
1182 rc = strict_strtoul(string, 10, &option);
1183 kfree(string);
1184 if (rc != 0 || option > USHORT_MAX)
Chuck Leverd23c45f2009-06-17 18:02:13 -07001185 goto out_invalid_value;
1186 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001187 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001188 case Opt_mountvers:
Chuck Levera5a16ba2009-06-17 18:02:14 -07001189 string = match_strdup(args);
1190 if (string == NULL)
1191 goto out_nomem;
1192 rc = strict_strtoul(string, 10, &option);
1193 kfree(string);
1194 if (rc != 0 ||
Chuck Leverf45663c2008-06-24 19:28:02 -04001195 option < NFS_MNT_VERSION ||
Chuck Leverd23c45f2009-06-17 18:02:13 -07001196 option > NFS_MNT3_VERSION)
1197 goto out_invalid_value;
1198 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 case Opt_nfsvers:
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;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001208 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001209 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001210 mnt->flags &= ~NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001211 mnt->version = 2;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001212 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001213 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 mnt->flags |= NFS_MOUNT_VER3;
Chuck Lever764302c2009-09-08 19:50:03 -04001215 mnt->version = 3;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
Chuck Lever764302c2009-09-08 19:50:03 -04001217#ifdef CONFIG_NFS_V4
1218 case NFS4_VERSION:
1219 mnt->flags &= ~NFS_MOUNT_VER3;
1220 mnt->version = 4;
1221 break;
1222#endif
Chuck Leverbf0fd762007-07-01 12:13:44 -04001223 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001224 goto out_invalid_value;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 }
1226 break;
Mike Sager3fd5be92009-04-01 09:21:48 -04001227 case Opt_minorversion:
Chuck Leverf3f4f4e2009-08-09 15:09:29 -04001228 string = match_strdup(args);
1229 if (string == NULL)
1230 goto out_nomem;
1231 rc = strict_strtoul(string, 10, &option);
1232 kfree(string);
1233 if (rc != 0)
1234 goto out_invalid_value;
1235 if (option > NFS4_MAX_MINOR_VERSION)
1236 goto out_invalid_value;
1237 mnt->minorversion = option;
Mike Sager3fd5be92009-04-01 09:21:48 -04001238 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001239
Chuck Leverf45663c2008-06-24 19:28:02 -04001240 /*
1241 * options that take text values
1242 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001243 case Opt_sec:
1244 string = match_strdup(args);
1245 if (string == NULL)
1246 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001247 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001248 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001249 if (!rc) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001250 dfprintk(MOUNT, "NFS: unrecognized "
1251 "security flavor\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001252 return 0;
Chuck Leverf45663c2008-06-24 19:28:02 -04001253 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001254 break;
1255 case Opt_proto:
1256 string = match_strdup(args);
1257 if (string == NULL)
1258 goto out_nomem;
1259 token = match_token(string,
1260 nfs_xprt_protocol_tokens, args);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001261
Jeff Laytonee671b02009-12-03 15:58:56 -05001262 protofamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001263 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001264 case Opt_xprt_udp6:
1265 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001266 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001267 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001268 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001269 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001271 case Opt_xprt_tcp6:
1272 protofamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001273 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001274 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001275 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001276 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001277 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001278 case Opt_xprt_rdma:
1279 /* vector side protocols to TCP */
1280 mnt->flags |= NFS_MOUNT_TCP;
1281 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
Tom Talpeya67d18f2009-03-11 14:37:56 -04001282 xprt_load_transport(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001283 kfree(string);
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001284 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001286 dfprintk(MOUNT, "NFS: unrecognized "
1287 "transport protocol\n");
Yinghai Lu4223a4a2009-10-20 14:13:46 +09001288 kfree(string);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001289 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001290 }
1291 break;
1292 case Opt_mountproto:
1293 string = match_strdup(args);
1294 if (string == NULL)
1295 goto out_nomem;
1296 token = match_token(string,
1297 nfs_xprt_protocol_tokens, args);
Trond Myklebustd508afb2009-04-06 16:41:35 -07001298 kfree(string);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001299
Jeff Laytonee671b02009-12-03 15:58:56 -05001300 mountfamily = AF_INET;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001301 switch (token) {
Jeff Laytonee671b02009-12-03 15:58:56 -05001302 case Opt_xprt_udp6:
1303 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001304 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001305 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001306 break;
Jeff Laytonee671b02009-12-03 15:58:56 -05001307 case Opt_xprt_tcp6:
1308 mountfamily = AF_INET6;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001309 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001310 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001311 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001312 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001313 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001314 dfprintk(MOUNT, "NFS: unrecognized "
1315 "transport protocol\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001316 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001317 }
1318 break;
1319 case Opt_addr:
1320 string = match_strdup(args);
1321 if (string == NULL)
1322 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001323 mnt->nfs_server.addrlen =
1324 rpc_pton(string, strlen(string),
1325 (struct sockaddr *)
1326 &mnt->nfs_server.address,
1327 sizeof(mnt->nfs_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001328 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001329 if (mnt->nfs_server.addrlen == 0)
1330 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001331 break;
1332 case Opt_clientaddr:
1333 string = match_strdup(args);
1334 if (string == NULL)
1335 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001336 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001337 mnt->client_address = string;
1338 break;
Chuck Lever33832032007-12-10 14:59:13 -05001339 case Opt_mounthost:
1340 string = match_strdup(args);
1341 if (string == NULL)
1342 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001343 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001344 mnt->mount_server.hostname = string;
1345 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001346 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001347 string = match_strdup(args);
1348 if (string == NULL)
1349 goto out_nomem;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001350 mnt->mount_server.addrlen =
1351 rpc_pton(string, strlen(string),
1352 (struct sockaddr *)
1353 &mnt->mount_server.address,
1354 sizeof(mnt->mount_server.address));
Chuck Leverbf0fd762007-07-01 12:13:44 -04001355 kfree(string);
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001356 if (mnt->mount_server.addrlen == 0)
1357 goto out_invalid_address;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001358 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001359 case Opt_lookupcache:
1360 string = match_strdup(args);
1361 if (string == NULL)
1362 goto out_nomem;
1363 token = match_token(string,
1364 nfs_lookupcache_tokens, args);
1365 kfree(string);
1366 switch (token) {
1367 case Opt_lookupcache_all:
1368 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1369 break;
1370 case Opt_lookupcache_positive:
1371 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1372 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1373 break;
1374 case Opt_lookupcache_none:
1375 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1376 break;
1377 default:
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001378 dfprintk(MOUNT, "NFS: invalid "
1379 "lookupcache argument\n");
Chuck Leverd23c45f2009-06-17 18:02:13 -07001380 return 0;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001381 };
1382 break;
Chuck Levera6d5ff62010-05-07 13:33:58 -04001383 case Opt_fscache_uniq:
1384 string = match_strdup(args);
1385 if (string == NULL)
1386 goto out_nomem;
1387 kfree(mnt->fscache_uniq);
1388 mnt->fscache_uniq = string;
1389 mnt->options |= NFS_OPTION_FSCACHE;
1390 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001391
Chuck Leverf45663c2008-06-24 19:28:02 -04001392 /*
1393 * Special options
1394 */
1395 case Opt_sloppy:
1396 sloppy = 1;
1397 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1398 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001399 case Opt_userspace:
1400 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001401 dfprintk(MOUNT, "NFS: ignoring mount option "
1402 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001403 break;
1404
1405 default:
Chuck Leverd23c45f2009-06-17 18:02:13 -07001406 invalid_option = 1;
Chuck Leverf45663c2008-06-24 19:28:02 -04001407 dfprintk(MOUNT, "NFS: unrecognized mount option "
1408 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001409 }
1410 }
1411
Chuck Leverd23c45f2009-06-17 18:02:13 -07001412 if (!sloppy && invalid_option)
1413 return 0;
1414
Jeff Laytonee671b02009-12-03 15:58:56 -05001415 /*
1416 * verify that any proto=/mountproto= options match the address
1417 * familiies in the addr=/mountaddr= options.
1418 */
1419 if (protofamily != AF_UNSPEC &&
1420 protofamily != mnt->nfs_server.address.ss_family)
1421 goto out_proto_mismatch;
1422
1423 if (mountfamily != AF_UNSPEC) {
1424 if (mnt->mount_server.addrlen) {
1425 if (mountfamily != mnt->mount_server.address.ss_family)
1426 goto out_mountproto_mismatch;
1427 } else {
1428 if (mountfamily != mnt->nfs_server.address.ss_family)
1429 goto out_mountproto_mismatch;
1430 }
1431 }
1432
Chuck Leverbf0fd762007-07-01 12:13:44 -04001433 return 1;
1434
Jeff Laytonee671b02009-12-03 15:58:56 -05001435out_mountproto_mismatch:
1436 printk(KERN_INFO "NFS: mount server address does not match mountproto= "
1437 "option\n");
1438 return 0;
1439out_proto_mismatch:
1440 printk(KERN_INFO "NFS: server address does not match proto= option\n");
1441 return 0;
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001442out_invalid_address:
1443 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1444 return 0;
Chuck Leverd23c45f2009-06-17 18:02:13 -07001445out_invalid_value:
Chuck Lever53a0b9c2009-08-09 15:09:36 -04001446 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
Chuck Leverd23c45f2009-06-17 18:02:13 -07001447 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001448out_nomem:
1449 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1450 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001451out_security_failure:
1452 free_secdata(secdata);
1453 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1454 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001455}
1456
1457/*
Chuck Leverec88f282009-08-09 15:09:32 -04001458 * Match the requested auth flavors with the list returned by
1459 * the server. Returns zero and sets the mount's authentication
1460 * flavor on success; returns -EACCES if server does not support
1461 * the requested flavor.
1462 */
1463static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1464 struct nfs_mount_request *request)
1465{
1466 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1467
1468 /*
Chuck Lever5eecfde2009-08-21 17:50:30 -04001469 * Certain releases of Linux's mountd return an empty
1470 * flavor list. To prevent behavioral regression with
1471 * these servers (ie. rejecting mounts that used to
1472 * succeed), revert to pre-2.6.32 behavior (no checking)
1473 * if the returned flavor list is empty.
1474 */
1475 if (server_authlist_len == 0)
1476 return 0;
1477
1478 /*
Chuck Leverec88f282009-08-09 15:09:32 -04001479 * We avoid sophisticated negotiating here, as there are
1480 * plenty of cases where we can get it wrong, providing
1481 * either too little or too much security.
1482 *
1483 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1484 * flavor listed first. However, some servers list
1485 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1486 * preferred default, in args->auth_flavors[0] if user
1487 * didn't specify sec= mount option.
1488 */
1489 for (i = 0; i < args->auth_flavor_len; i++)
1490 for (j = 0; j < server_authlist_len; j++)
1491 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1492 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1493 request->auth_flavs[j]);
1494 args->auth_flavors[0] = request->auth_flavs[j];
1495 return 0;
1496 }
1497
1498 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1499 nfs_umount(request);
1500 return -EACCES;
1501}
1502
1503/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001504 * Use the remote server's MOUNT service to request the NFS file handle
1505 * corresponding to the provided path.
1506 */
1507static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1508 struct nfs_fh *root_fh)
1509{
Chuck Leverec88f282009-08-09 15:09:32 -04001510 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1511 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
Chuck Leverc5d120f2008-12-23 15:21:35 -05001512 struct nfs_mount_request request = {
1513 .sap = (struct sockaddr *)
1514 &args->mount_server.address,
1515 .dirpath = args->nfs_server.export_path,
1516 .protocol = args->mount_server.protocol,
1517 .fh = root_fh,
Chuck Lever50a737f2008-12-23 15:21:37 -05001518 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
Chuck Leverec88f282009-08-09 15:09:32 -04001519 .auth_flav_len = &server_authlist_len,
1520 .auth_flavs = server_authlist,
Chuck Leverc5d120f2008-12-23 15:21:35 -05001521 };
Chuck Lever4c568012007-12-10 14:59:28 -05001522 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001523
1524 if (args->mount_server.version == 0) {
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001525 switch (args->version) {
1526 default:
1527 args->mount_server.version = NFS_MNT3_VERSION;
1528 break;
1529 case 2:
1530 args->mount_server.version = NFS_MNT_VERSION;
1531 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001532 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001533 request.version = args->mount_server.version;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001534
Chuck Lever33832032007-12-10 14:59:13 -05001535 if (args->mount_server.hostname)
Chuck Leverc5d120f2008-12-23 15:21:35 -05001536 request.hostname = args->mount_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001537 else
Chuck Leverc5d120f2008-12-23 15:21:35 -05001538 request.hostname = args->nfs_server.hostname;
Chuck Lever33832032007-12-10 14:59:13 -05001539
Chuck Lever0076d7b2007-07-01 12:13:49 -04001540 /*
1541 * Construct the mount server's address.
1542 */
Chuck Lever4c568012007-12-10 14:59:28 -05001543 if (args->mount_server.address.ss_family == AF_UNSPEC) {
Chuck Leverc5d120f2008-12-23 15:21:35 -05001544 memcpy(request.sap, &args->nfs_server.address,
Chuck Lever4c568012007-12-10 14:59:28 -05001545 args->nfs_server.addrlen);
1546 args->mount_server.addrlen = args->nfs_server.addrlen;
1547 }
Chuck Leverc5d120f2008-12-23 15:21:35 -05001548 request.salen = args->mount_server.addrlen;
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001549 nfs_set_port(request.sap, &args->mount_server.port, 0);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001550
1551 /*
1552 * Now ask the mount server to map our export path
1553 * to a file handle.
1554 */
Chuck Leverc5d120f2008-12-23 15:21:35 -05001555 status = nfs_mount(&request);
Chuck Leverec88f282009-08-09 15:09:32 -04001556 if (status != 0) {
1557 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1558 request.hostname, status);
1559 return status;
1560 }
Chuck Lever0076d7b2007-07-01 12:13:49 -04001561
Chuck Leverec88f282009-08-09 15:09:32 -04001562 /*
1563 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1564 */
1565 if (args->mount_server.version != NFS_MNT3_VERSION)
1566 return 0;
1567 return nfs_walk_authlist(args, &request);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001568}
1569
Chuck Leverd1aa0822008-06-23 12:36:45 -04001570static int nfs_parse_simple_hostname(const char *dev_name,
1571 char **hostname, size_t maxnamlen,
1572 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001573{
1574 size_t len;
1575 char *colon, *comma;
1576
1577 colon = strchr(dev_name, ':');
1578 if (colon == NULL)
1579 goto out_bad_devname;
1580
1581 len = colon - dev_name;
1582 if (len > maxnamlen)
1583 goto out_hostname;
1584
1585 /* N.B. caller will free nfs_server.hostname in all cases */
1586 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1587 if (!*hostname)
1588 goto out_nomem;
1589
1590 /* kill possible hostname list: not supported */
1591 comma = strchr(*hostname, ',');
1592 if (comma != NULL) {
1593 if (comma == *hostname)
1594 goto out_bad_devname;
1595 *comma = '\0';
1596 }
1597
1598 colon++;
1599 len = strlen(colon);
1600 if (len > maxpathlen)
1601 goto out_path;
1602 *export_path = kstrndup(colon, len, GFP_KERNEL);
1603 if (!*export_path)
1604 goto out_nomem;
1605
1606 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1607 return 0;
1608
1609out_bad_devname:
1610 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1611 return -EINVAL;
1612
1613out_nomem:
1614 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1615 return -ENOMEM;
1616
1617out_hostname:
1618 dfprintk(MOUNT, "NFS: server hostname too long\n");
1619 return -ENAMETOOLONG;
1620
1621out_path:
1622 dfprintk(MOUNT, "NFS: export pathname too long\n");
1623 return -ENAMETOOLONG;
1624}
1625
1626/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001627 * Hostname has square brackets around it because it contains one or
1628 * more colons. We look for the first closing square bracket, and a
1629 * colon must follow it.
1630 */
1631static int nfs_parse_protected_hostname(const char *dev_name,
1632 char **hostname, size_t maxnamlen,
1633 char **export_path, size_t maxpathlen)
1634{
1635 size_t len;
1636 char *start, *end;
1637
1638 start = (char *)(dev_name + 1);
1639
1640 end = strchr(start, ']');
1641 if (end == NULL)
1642 goto out_bad_devname;
1643 if (*(end + 1) != ':')
1644 goto out_bad_devname;
1645
1646 len = end - start;
1647 if (len > maxnamlen)
1648 goto out_hostname;
1649
1650 /* N.B. caller will free nfs_server.hostname in all cases */
1651 *hostname = kstrndup(start, len, GFP_KERNEL);
1652 if (*hostname == NULL)
1653 goto out_nomem;
1654
1655 end += 2;
1656 len = strlen(end);
1657 if (len > maxpathlen)
1658 goto out_path;
1659 *export_path = kstrndup(end, len, GFP_KERNEL);
1660 if (!*export_path)
1661 goto out_nomem;
1662
1663 return 0;
1664
1665out_bad_devname:
1666 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1667 return -EINVAL;
1668
1669out_nomem:
1670 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1671 return -ENOMEM;
1672
1673out_hostname:
1674 dfprintk(MOUNT, "NFS: server hostname too long\n");
1675 return -ENAMETOOLONG;
1676
1677out_path:
1678 dfprintk(MOUNT, "NFS: export pathname too long\n");
1679 return -ENAMETOOLONG;
1680}
1681
1682/*
1683 * Split "dev_name" into "hostname:export_path".
1684 *
1685 * The leftmost colon demarks the split between the server's hostname
1686 * and the export path. If the hostname starts with a left square
1687 * bracket, then it may contain colons.
1688 *
1689 * Note: caller frees hostname and export path, even on error.
1690 */
1691static int nfs_parse_devname(const char *dev_name,
1692 char **hostname, size_t maxnamlen,
1693 char **export_path, size_t maxpathlen)
1694{
1695 if (*dev_name == '[')
1696 return nfs_parse_protected_hostname(dev_name,
1697 hostname, maxnamlen,
1698 export_path, maxpathlen);
1699
1700 return nfs_parse_simple_hostname(dev_name,
1701 hostname, maxnamlen,
1702 export_path, maxpathlen);
1703}
1704
1705/*
David Howells54ceac42006-08-22 20:06:13 -04001706 * Validate the NFS2/NFS3 mount data
1707 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001708 *
1709 * For option strings, user space handles the following behaviors:
1710 *
1711 * + DNS: mapping server host name to IP address ("addr=" option)
1712 *
1713 * + failure mode: how to behave if a mount request can't be handled
1714 * immediately ("fg/bg" option)
1715 *
1716 * + retry: how often to retry a mount request ("retry=" option)
1717 *
1718 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1719 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001720 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001721static int nfs_validate_mount_data(void *options,
1722 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001723 struct nfs_fh *mntfh,
1724 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001725{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001726 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001727 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
Chuck Lever136d5582007-07-01 12:13:54 -04001728
Chuck Lever5df36e72007-07-01 12:12:56 -04001729 if (data == NULL)
1730 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001731
David Howellsf7b422b2006-06-09 09:34:33 -04001732 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001733 case 1:
1734 data->namlen = 0;
1735 case 2:
1736 data->bsize = 0;
1737 case 3:
1738 if (data->flags & NFS_MOUNT_VER3)
1739 goto out_no_v3;
1740 data->root.size = NFS2_FHSIZE;
1741 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1742 case 4:
1743 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1744 goto out_no_sec;
1745 case 5:
1746 memset(data->context, 0, sizeof(data->context));
1747 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001748 if (data->flags & NFS_MOUNT_VER3) {
1749 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1750 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001751 mntfh->size = data->root.size;
Chuck Lever764302c2009-09-08 19:50:03 -04001752 args->version = 3;
1753 } else {
Chuck Lever5df36e72007-07-01 12:12:56 -04001754 mntfh->size = NFS2_FHSIZE;
Chuck Lever764302c2009-09-08 19:50:03 -04001755 args->version = 2;
1756 }
Chuck Lever5df36e72007-07-01 12:12:56 -04001757
Chuck Lever5df36e72007-07-01 12:12:56 -04001758
1759 memcpy(mntfh->data, data->root.data, mntfh->size);
1760 if (mntfh->size < sizeof(mntfh->data))
1761 memset(mntfh->data + mntfh->size, 0,
1762 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001763
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001764 /*
1765 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1766 * can deal with.
1767 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001768 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001769 args->rsize = data->rsize;
1770 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001771 args->timeo = data->timeo;
1772 args->retrans = data->retrans;
1773 args->acregmin = data->acregmin;
1774 args->acregmax = data->acregmax;
1775 args->acdirmin = data->acdirmin;
1776 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001777
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001778 memcpy(sap, &data->addr, sizeof(data->addr));
Chuck Lever4c568012007-12-10 14:59:28 -05001779 args->nfs_server.addrlen = sizeof(data->addr);
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001780 if (!nfs_verify_server_address(sap))
Chuck Lever4c568012007-12-10 14:59:28 -05001781 goto out_no_address;
1782
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001783 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001784 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001785 /* N.B. caller will free nfs_server.hostname in all cases */
1786 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1787 args->namlen = data->namlen;
1788 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001789
1790 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1791 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001792 if (!args->nfs_server.hostname)
1793 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001794
1795 /*
1796 * The legacy version 6 binary mount data from userspace has a
1797 * field used only to transport selinux information into the
1798 * the kernel. To continue to support that functionality we
1799 * have a touch of selinux knowledge here in the NFS code. The
1800 * userspace code converted context=blah to just blah so we are
1801 * converting back to the full string selinux understands.
1802 */
1803 if (data->context[0]){
1804#ifdef CONFIG_SECURITY_SELINUX
1805 int rc;
1806 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1807 if (!opts_str)
1808 return -ENOMEM;
1809 strcpy(opts_str, "context=");
1810 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1811 strcat(opts_str, &data->context[0]);
1812 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1813 kfree(opts_str);
1814 if (rc)
1815 return rc;
1816#else
1817 return -EINVAL;
1818#endif
1819 }
1820
Chuck Lever5df36e72007-07-01 12:12:56 -04001821 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001822 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001823 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001824
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001825 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001826 return -EINVAL;
1827
Chuck Lever4cfd74f2009-09-08 19:49:47 -04001828 if (!nfs_verify_server_address(sap))
Chuck Lever6e88e062007-09-24 15:39:50 -04001829 goto out_no_address;
1830
Chuck Lever764302c2009-09-08 19:50:03 -04001831 if (args->version == 4)
1832#ifdef CONFIG_NFS_V4
1833 return nfs4_validate_text_mount_data(options,
1834 args, dev_name);
1835#else
1836 goto out_v4_not_compiled;
1837#endif
1838
Trond Myklebustf5855fe2009-10-06 15:40:37 -04001839 nfs_set_port(sap, &args->nfs_server.port, 0);
Chuck Levered596a82008-06-26 17:47:05 -04001840
Trond Myklebust259875e2008-07-02 14:43:47 -04001841 nfs_set_mount_transport_protocol(args);
1842
Chuck Leverdc045892008-06-23 12:36:37 -04001843 status = nfs_parse_devname(dev_name,
1844 &args->nfs_server.hostname,
1845 PAGE_SIZE,
1846 &args->nfs_server.export_path,
1847 NFS_MAXPATHLEN);
1848 if (!status)
1849 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001850
Chuck Leverdc045892008-06-23 12:36:37 -04001851 kfree(args->nfs_server.export_path);
1852 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001853
Chuck Lever136d5582007-07-01 12:13:54 -04001854 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001855 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001856
Chuck Lever136d5582007-07-01 12:13:54 -04001857 break;
1858 }
David Howellsf7b422b2006-06-09 09:34:33 -04001859 }
David Howells54ceac42006-08-22 20:06:13 -04001860
David Howellsf7b422b2006-06-09 09:34:33 -04001861#ifndef CONFIG_NFS_V3
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04001862 if (args->version == 3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001863 goto out_v3_not_compiled;
1864#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001865
David Howells54ceac42006-08-22 20:06:13 -04001866 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001867
1868out_no_data:
1869 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1870 return -EINVAL;
1871
1872out_no_v3:
1873 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1874 data->version);
1875 return -EINVAL;
1876
1877out_no_sec:
1878 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1879 return -EINVAL;
1880
Chuck Lever5df36e72007-07-01 12:12:56 -04001881#ifndef CONFIG_NFS_V3
1882out_v3_not_compiled:
1883 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1884 return -EPROTONOSUPPORT;
1885#endif /* !CONFIG_NFS_V3 */
1886
Chuck Lever764302c2009-09-08 19:50:03 -04001887#ifndef CONFIG_NFS_V4
1888out_v4_not_compiled:
1889 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1890 return -EPROTONOSUPPORT;
1891#endif /* !CONFIG_NFS_V4 */
1892
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001893out_nomem:
1894 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1895 return -ENOMEM;
1896
Chuck Lever5df36e72007-07-01 12:12:56 -04001897out_no_address:
1898 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1899 return -EINVAL;
1900
1901out_invalid_fh:
1902 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1903 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001904}
1905
Jeff Layton48b605f2008-06-10 15:38:39 -04001906static int
1907nfs_compare_remount_data(struct nfs_server *nfss,
1908 struct nfs_parsed_mount_data *data)
1909{
1910 if (data->flags != nfss->flags ||
1911 data->rsize != nfss->rsize ||
1912 data->wsize != nfss->wsize ||
1913 data->retrans != nfss->client->cl_timeout->to_retries ||
1914 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1915 data->acregmin != nfss->acregmin / HZ ||
1916 data->acregmax != nfss->acregmax / HZ ||
1917 data->acdirmin != nfss->acdirmin / HZ ||
1918 data->acdirmax != nfss->acdirmax / HZ ||
1919 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001920 data->nfs_server.port != nfss->port ||
Jeff Layton48b605f2008-06-10 15:38:39 -04001921 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
Stefan Richtera1be9ee2009-10-12 11:26:12 -04001922 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1923 (struct sockaddr *)&nfss->nfs_client->cl_addr))
Jeff Layton48b605f2008-06-10 15:38:39 -04001924 return -EINVAL;
1925
1926 return 0;
1927}
1928
1929static int
1930nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1931{
1932 int error;
1933 struct nfs_server *nfss = sb->s_fs_info;
1934 struct nfs_parsed_mount_data *data;
1935 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1936 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001937 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001938
1939 /*
1940 * Userspace mount programs that send binary options generally send
1941 * them populated with default values. We have no way to know which
1942 * ones were explicitly specified. Fall back to legacy behavior and
1943 * just return success.
1944 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001945 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1946 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1947 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001948 return 0;
1949
1950 data = kzalloc(sizeof(*data), GFP_KERNEL);
1951 if (data == NULL)
1952 return -ENOMEM;
1953
1954 /* fill out struct with values from existing mount */
1955 data->flags = nfss->flags;
1956 data->rsize = nfss->rsize;
1957 data->wsize = nfss->wsize;
1958 data->retrans = nfss->client->cl_timeout->to_retries;
1959 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1960 data->acregmin = nfss->acregmin / HZ;
1961 data->acregmax = nfss->acregmax / HZ;
1962 data->acdirmin = nfss->acdirmin / HZ;
1963 data->acdirmax = nfss->acdirmax / HZ;
1964 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
Trond Myklebustbcd2ea12009-10-06 15:41:22 -04001965 data->nfs_server.port = nfss->port;
Jeff Layton48b605f2008-06-10 15:38:39 -04001966 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1967 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1968 data->nfs_server.addrlen);
1969
1970 /* overwrite those values with any that were specified */
1971 error = nfs_parse_mount_options((char *)options, data);
1972 if (error < 0)
1973 goto out;
1974
1975 /* compare new mount options with old ones */
1976 error = nfs_compare_remount_data(nfss, data);
1977out:
1978 kfree(data);
1979 return error;
1980}
1981
David Howells54ceac42006-08-22 20:06:13 -04001982/*
1983 * Initialise the common bits of the superblock
1984 */
1985static inline void nfs_initialise_sb(struct super_block *sb)
1986{
1987 struct nfs_server *server = NFS_SB(sb);
1988
1989 sb->s_magic = NFS_SUPER_MAGIC;
1990
1991 /* We probably want something more informative here */
1992 snprintf(sb->s_id, sizeof(sb->s_id),
1993 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1994
1995 if (sb->s_blocksize == 0)
1996 sb->s_blocksize = nfs_block_bits(server->wsize,
1997 &sb->s_blocksize_bits);
1998
1999 if (server->flags & NFS_MOUNT_NOAC)
2000 sb->s_flags |= MS_SYNCHRONOUS;
2001
Jens Axboe32a88aa2009-09-16 15:02:33 +02002002 sb->s_bdi = &server->backing_dev_info;
2003
David Howells54ceac42006-08-22 20:06:13 -04002004 nfs_super_set_maxbytes(sb, server->maxfilesize);
2005}
2006
2007/*
2008 * Finish setting up an NFS2/3 superblock
2009 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04002010static void nfs_fill_super(struct super_block *sb,
2011 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04002012{
2013 struct nfs_server *server = NFS_SB(sb);
2014
2015 sb->s_blocksize_bits = 0;
2016 sb->s_blocksize = 0;
2017 if (data->bsize)
2018 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
2019
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002020 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002021 /* The VFS shouldn't apply the umask to mode bits. We will do
2022 * so ourselves when necessary.
2023 */
2024 sb->s_flags |= MS_POSIXACL;
2025 sb->s_time_gran = 1;
2026 }
2027
2028 sb->s_op = &nfs_sops;
2029 nfs_initialise_sb(sb);
2030}
2031
2032/*
2033 * Finish setting up a cloned NFS2/3 superblock
2034 */
2035static void nfs_clone_super(struct super_block *sb,
2036 const struct super_block *old_sb)
2037{
2038 struct nfs_server *server = NFS_SB(sb);
2039
2040 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2041 sb->s_blocksize = old_sb->s_blocksize;
2042 sb->s_maxbytes = old_sb->s_maxbytes;
2043
Trond Myklebust8a6e5de2009-09-23 14:36:37 -04002044 if (server->nfs_client->rpc_ops->version == 3) {
David Howells54ceac42006-08-22 20:06:13 -04002045 /* The VFS shouldn't apply the umask to mode bits. We will do
2046 * so ourselves when necessary.
2047 */
2048 sb->s_flags |= MS_POSIXACL;
2049 sb->s_time_gran = 1;
2050 }
2051
2052 sb->s_op = old_sb->s_op;
2053 nfs_initialise_sb(sb);
2054}
2055
Trond Myklebust275a5d22007-05-16 16:53:28 -04002056static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
2057{
2058 const struct nfs_server *a = s->s_fs_info;
2059 const struct rpc_clnt *clnt_a = a->client;
2060 const struct rpc_clnt *clnt_b = b->client;
2061
2062 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
2063 goto Ebusy;
2064 if (a->nfs_client != b->nfs_client)
2065 goto Ebusy;
2066 if (a->flags != b->flags)
2067 goto Ebusy;
2068 if (a->wsize != b->wsize)
2069 goto Ebusy;
2070 if (a->rsize != b->rsize)
2071 goto Ebusy;
2072 if (a->acregmin != b->acregmin)
2073 goto Ebusy;
2074 if (a->acregmax != b->acregmax)
2075 goto Ebusy;
2076 if (a->acdirmin != b->acdirmin)
2077 goto Ebusy;
2078 if (a->acdirmax != b->acdirmax)
2079 goto Ebusy;
2080 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2081 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002082 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04002083Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002084 return 0;
2085}
2086
2087struct nfs_sb_mountdata {
2088 struct nfs_server *server;
2089 int mntflags;
2090};
2091
2092static int nfs_set_super(struct super_block *s, void *data)
2093{
2094 struct nfs_sb_mountdata *sb_mntdata = data;
2095 struct nfs_server *server = sb_mntdata->server;
2096 int ret;
2097
2098 s->s_flags = sb_mntdata->mntflags;
2099 s->s_fs_info = server;
2100 ret = set_anon_super(s, server);
2101 if (ret == 0)
2102 server->s_dev = s->s_dev;
2103 return ret;
2104}
2105
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002106static int nfs_compare_super_address(struct nfs_server *server1,
2107 struct nfs_server *server2)
2108{
2109 struct sockaddr *sap1, *sap2;
2110
2111 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2112 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2113
2114 if (sap1->sa_family != sap2->sa_family)
2115 return 0;
2116
2117 switch (sap1->sa_family) {
2118 case AF_INET: {
2119 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2120 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2121 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2122 return 0;
2123 if (sin1->sin_port != sin2->sin_port)
2124 return 0;
2125 break;
2126 }
2127 case AF_INET6: {
2128 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2129 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2130 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2131 return 0;
2132 if (sin1->sin6_port != sin2->sin6_port)
2133 return 0;
2134 break;
2135 }
2136 default:
2137 return 0;
2138 }
2139
2140 return 1;
2141}
2142
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002143static int nfs_compare_super(struct super_block *sb, void *data)
2144{
2145 struct nfs_sb_mountdata *sb_mntdata = data;
2146 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2147 int mntflags = sb_mntdata->mntflags;
2148
Chuck Leverfd00a8f2007-12-10 14:57:38 -05002149 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002150 return 0;
2151 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2152 if (old->flags & NFS_MOUNT_UNSHARED)
2153 return 0;
2154 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2155 return 0;
2156 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04002157}
2158
Miklos Szeredifa799752008-04-30 00:54:33 -07002159static int nfs_bdi_register(struct nfs_server *server)
2160{
2161 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2162}
2163
David Howells54ceac42006-08-22 20:06:13 -04002164static int nfs_get_sb(struct file_system_type *fs_type,
2165 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2166{
2167 struct nfs_server *server = NULL;
2168 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04002169 struct nfs_parsed_mount_data *data;
2170 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002171 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002172 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002173 struct nfs_sb_mountdata sb_mntdata = {
2174 .mntflags = flags,
2175 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002176 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002177
Trond Myklebustc5811db2009-10-06 15:40:15 -04002178 data = nfs_alloc_parsed_mount_data(3);
Trond Myklebustb157b062010-04-19 19:05:48 -04002179 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002180 if (data == NULL || mntfh == NULL)
2181 goto out_free_fh;
2182
2183 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002184
David Howells54ceac42006-08-22 20:06:13 -04002185 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002186 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002187 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002188 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002189
Chuck Lever764302c2009-09-08 19:50:03 -04002190#ifdef CONFIG_NFS_V4
2191 if (data->version == 4) {
2192 error = nfs4_try_mount(flags, dev_name, data, mnt);
2193 kfree(data->client_address);
Xiaotian Feng9699eda2010-04-22 18:56:17 +08002194 kfree(data->nfs_server.export_path);
Chuck Lever764302c2009-09-08 19:50:03 -04002195 goto out;
2196 }
2197#endif /* CONFIG_NFS_V4 */
2198
David Howells54ceac42006-08-22 20:06:13 -04002199 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002200 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002201 if (IS_ERR(server)) {
2202 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002203 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002204 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002205 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002206
Trond Myklebust75180df2007-05-16 16:53:28 -04002207 if (server->flags & NFS_MOUNT_UNSHARED)
2208 compare_super = NULL;
2209
David Howells54ceac42006-08-22 20:06:13 -04002210 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002211 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002212 if (IS_ERR(s)) {
2213 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002214 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002215 }
2216
David Howells54ceac42006-08-22 20:06:13 -04002217 if (s->s_fs_info != server) {
2218 nfs_free_server(server);
2219 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002220 } else {
2221 error = nfs_bdi_register(server);
2222 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002223 goto error_splat_bdi;
David Howellsf7b422b2006-06-09 09:34:33 -04002224 }
David Howells54ceac42006-08-22 20:06:13 -04002225
2226 if (!s->s_root) {
2227 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002228 nfs_fill_super(s, data);
David Howells2df54802009-09-23 14:36:39 -04002229 nfs_fscache_get_super_cookie(
2230 s, data ? data->fscache_uniq : NULL, NULL);
David Howells54ceac42006-08-22 20:06:13 -04002231 }
2232
Trond Myklebust33852a12008-06-19 14:20:11 -04002233 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002234 if (IS_ERR(mntroot)) {
2235 error = PTR_ERR(mntroot);
2236 goto error_splat_super;
2237 }
2238
Trond Myklebust33852a12008-06-19 14:20:11 -04002239 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002240 if (error)
2241 goto error_splat_root;
2242
David Howellsf7b422b2006-06-09 09:34:33 -04002243 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002244 mnt->mnt_sb = s;
2245 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002246 error = 0;
2247
2248out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002249 kfree(data->nfs_server.hostname);
2250 kfree(data->mount_server.hostname);
David Howells08734042009-04-03 16:42:42 +01002251 kfree(data->fscache_uniq);
Trond Myklebust33852a12008-06-19 14:20:11 -04002252 security_free_mnt_opts(&data->lsm_opts);
2253out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002254 nfs_free_fhandle(mntfh);
Trond Myklebust33852a12008-06-19 14:20:11 -04002255 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002256 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002257
David Howells54ceac42006-08-22 20:06:13 -04002258out_err_nosb:
2259 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002260 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002261
Eric Parisf9c3a382008-03-05 14:20:18 -05002262error_splat_root:
2263 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002264error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002265 if (server && !s->s_root)
2266 bdi_unregister(&server->backing_dev_info);
2267error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002268 deactivate_locked_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002269 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002270}
2271
David Howells54ceac42006-08-22 20:06:13 -04002272/*
Trond Myklebust387c1492010-02-03 08:27:35 -05002273 * Ensure that we unregister the bdi before kill_anon_super
2274 * releases the device name
2275 */
2276static void nfs_put_super(struct super_block *s)
2277{
2278 struct nfs_server *server = NFS_SB(s);
2279
2280 bdi_unregister(&server->backing_dev_info);
2281}
2282
2283/*
David Howells54ceac42006-08-22 20:06:13 -04002284 * Destroy an NFS2/3 superblock
2285 */
David Howellsf7b422b2006-06-09 09:34:33 -04002286static void nfs_kill_super(struct super_block *s)
2287{
2288 struct nfs_server *server = NFS_SB(s);
2289
2290 kill_anon_super(s);
David Howells08734042009-04-03 16:42:42 +01002291 nfs_fscache_release_super_cookie(s);
David Howells54ceac42006-08-22 20:06:13 -04002292 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002293}
2294
David Howells54ceac42006-08-22 20:06:13 -04002295/*
2296 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2297 */
2298static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2299 const char *dev_name, void *raw_data,
2300 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002301{
2302 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002303 struct super_block *s;
2304 struct nfs_server *server;
2305 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002306 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002307 struct nfs_sb_mountdata sb_mntdata = {
2308 .mntflags = flags,
2309 };
David Howells54ceac42006-08-22 20:06:13 -04002310 int error;
2311
2312 dprintk("--> nfs_xdev_get_sb()\n");
2313
2314 /* create a new volume representation */
2315 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2316 if (IS_ERR(server)) {
2317 error = PTR_ERR(server);
2318 goto out_err_noserver;
2319 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002320 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002321
Trond Myklebust75180df2007-05-16 16:53:28 -04002322 if (server->flags & NFS_MOUNT_UNSHARED)
2323 compare_super = NULL;
2324
David Howells54ceac42006-08-22 20:06:13 -04002325 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002326 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002327 if (IS_ERR(s)) {
2328 error = PTR_ERR(s);
2329 goto out_err_nosb;
2330 }
2331
2332 if (s->s_fs_info != server) {
2333 nfs_free_server(server);
2334 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002335 } else {
2336 error = nfs_bdi_register(server);
2337 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002338 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002339 }
2340
2341 if (!s->s_root) {
2342 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002343 nfs_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002344 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002345 }
2346
2347 mntroot = nfs_get_root(s, data->fh);
2348 if (IS_ERR(mntroot)) {
2349 error = PTR_ERR(mntroot);
2350 goto error_splat_super;
2351 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002352 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002353 dput(mntroot);
2354 error = -ESTALE;
2355 goto error_splat_super;
2356 }
David Howells54ceac42006-08-22 20:06:13 -04002357
2358 s->s_flags |= MS_ACTIVE;
2359 mnt->mnt_sb = s;
2360 mnt->mnt_root = mntroot;
2361
Eric Parisf9c3a382008-03-05 14:20:18 -05002362 /* clone any lsm security options from the parent to the new sb */
2363 security_sb_clone_mnt_opts(data->sb, s);
2364
David Howells54ceac42006-08-22 20:06:13 -04002365 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2366 return 0;
2367
2368out_err_nosb:
2369 nfs_free_server(server);
2370out_err_noserver:
2371 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2372 return error;
2373
2374error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002375 if (server && !s->s_root)
2376 bdi_unregister(&server->backing_dev_info);
2377error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002378 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002379 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2380 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002381}
2382
2383#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002384
2385/*
2386 * Finish setting up a cloned NFS4 superblock
2387 */
2388static void nfs4_clone_super(struct super_block *sb,
2389 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002390{
David Howells54ceac42006-08-22 20:06:13 -04002391 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2392 sb->s_blocksize = old_sb->s_blocksize;
2393 sb->s_maxbytes = old_sb->s_maxbytes;
2394 sb->s_time_gran = 1;
2395 sb->s_op = old_sb->s_op;
2396 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002397}
2398
2399/*
2400 * Set up an NFS4 superblock
2401 */
David Howells54ceac42006-08-22 20:06:13 -04002402static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002403{
David Howellsf7b422b2006-06-09 09:34:33 -04002404 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002405 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002406 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002407}
2408
Trond Myklebust01c3f052009-06-17 13:22:58 -07002409static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2410{
2411 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2412}
2413
Chuck Lever7630c852009-09-08 19:49:57 -04002414static int nfs4_validate_text_mount_data(void *options,
2415 struct nfs_parsed_mount_data *args,
2416 const char *dev_name)
2417{
2418 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2419
Trond Myklebustf5855fe2009-10-06 15:40:37 -04002420 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
Chuck Lever7630c852009-09-08 19:49:57 -04002421
2422 nfs_validate_transport_protocol(args);
2423
2424 nfs4_validate_mount_flags(args);
2425
Trond Myklebust2ecda722009-09-08 19:50:07 -04002426 if (args->version != 4) {
2427 dfprintk(MOUNT,
2428 "NFS4: Illegal mount version\n");
2429 return -EINVAL;
2430 }
2431
Chuck Lever7630c852009-09-08 19:49:57 -04002432 if (args->auth_flavor_len > 1) {
2433 dfprintk(MOUNT,
2434 "NFS4: Too many RPC auth flavours specified\n");
2435 return -EINVAL;
2436 }
2437
2438 if (args->client_address == NULL) {
2439 dfprintk(MOUNT,
2440 "NFS4: mount program didn't pass callback address\n");
2441 return -EINVAL;
2442 }
2443
2444 return nfs_parse_devname(dev_name,
2445 &args->nfs_server.hostname,
2446 NFS4_MAXNAMLEN,
2447 &args->nfs_server.export_path,
2448 NFS4_MAXPATHLEN);
2449}
2450
David Howells54ceac42006-08-22 20:06:13 -04002451/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002452 * Validate NFSv4 mount options
2453 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002454static int nfs4_validate_mount_data(void *options,
2455 struct nfs_parsed_mount_data *args,
2456 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002457{
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002458 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002459 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002460 char *c;
2461
2462 if (data == NULL)
2463 goto out_no_data;
2464
2465 switch (data->version) {
2466 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002467 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002468 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002469 if (data->host_addrlen == 0)
2470 goto out_no_address;
2471 args->nfs_server.addrlen = data->host_addrlen;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002472 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002473 return -EFAULT;
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002474 if (!nfs_verify_server_address(sap))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002475 goto out_no_address;
2476
Chuck Lever6738b252008-06-24 16:33:54 -04002477 if (data->auth_flavourlen) {
2478 if (data->auth_flavourlen > 1)
2479 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002480 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002481 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002482 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002483 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002484 }
2485
2486 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2487 if (IS_ERR(c))
2488 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002489 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002490
2491 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2492 if (IS_ERR(c))
2493 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002494 args->nfs_server.export_path = c;
2495 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002496
2497 c = strndup_user(data->client_addr.data, 16);
2498 if (IS_ERR(c))
2499 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002500 args->client_address = c;
2501
2502 /*
2503 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2504 * can deal with.
2505 */
2506
2507 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2508 args->rsize = data->rsize;
2509 args->wsize = data->wsize;
2510 args->timeo = data->timeo;
2511 args->retrans = data->retrans;
2512 args->acregmin = data->acregmin;
2513 args->acregmax = data->acregmax;
2514 args->acdirmin = data->acdirmin;
2515 args->acdirmax = data->acdirmax;
2516 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002517 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002518
2519 break;
Chuck Lever7630c852009-09-08 19:49:57 -04002520 default:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002521 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002522 return -EINVAL;
2523
Chuck Lever4cfd74f2009-09-08 19:49:47 -04002524 if (!nfs_verify_server_address(sap))
Chuck Lever80071222007-07-01 12:13:59 -04002525 return -EINVAL;
Chuck Levered596a82008-06-26 17:47:05 -04002526
Chuck Lever7630c852009-09-08 19:49:57 -04002527 return nfs4_validate_text_mount_data(options, args, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002528 }
2529
2530 return 0;
2531
2532out_no_data:
2533 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2534 return -EINVAL;
2535
2536out_inval_auth:
2537 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2538 data->auth_flavourlen);
2539 return -EINVAL;
2540
2541out_no_address:
2542 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2543 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002544}
2545
2546/*
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002547 * Get the superblock for the NFS4 root partition
David Howells54ceac42006-08-22 20:06:13 -04002548 */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002549static int nfs4_remote_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -04002550 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002551{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002552 struct nfs_parsed_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002553 struct super_block *s;
2554 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002555 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002556 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002557 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002558 struct nfs_sb_mountdata sb_mntdata = {
2559 .mntflags = flags,
2560 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002561 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002562
Trond Myklebustb157b062010-04-19 19:05:48 -04002563 mntfh = nfs_alloc_fhandle();
Trond Myklebust33852a12008-06-19 14:20:11 -04002564 if (data == NULL || mntfh == NULL)
2565 goto out_free_fh;
2566
2567 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002568
David Howells54ceac42006-08-22 20:06:13 -04002569 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002570 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002571 if (IS_ERR(server)) {
2572 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002573 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002574 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002575 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002576
Trond Myklebust75180df2007-05-16 16:53:28 -04002577 if (server->flags & NFS4_MOUNT_UNSHARED)
2578 compare_super = NULL;
2579
David Howells54ceac42006-08-22 20:06:13 -04002580 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002581 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002582 if (IS_ERR(s)) {
2583 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002584 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002585 }
2586
Trond Myklebust5dd31772006-08-24 01:03:05 -04002587 if (s->s_fs_info != server) {
2588 nfs_free_server(server);
2589 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002590 } else {
2591 error = nfs_bdi_register(server);
2592 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002593 goto error_splat_bdi;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002594 }
2595
David Howells54ceac42006-08-22 20:06:13 -04002596 if (!s->s_root) {
2597 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002598 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04002599 nfs_fscache_get_super_cookie(
2600 s, data ? data->fscache_uniq : NULL, NULL);
Trond Myklebust816724e2006-06-24 08:41:41 -04002601 }
David Howellsf7b422b2006-06-09 09:34:33 -04002602
Trond Myklebust33852a12008-06-19 14:20:11 -04002603 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002604 if (IS_ERR(mntroot)) {
2605 error = PTR_ERR(mntroot);
2606 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002607 }
David Howells54ceac42006-08-22 20:06:13 -04002608
Trond Myklebust33852a12008-06-19 14:20:11 -04002609 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002610 if (error)
2611 goto error_splat_root;
2612
David Howellsf7b422b2006-06-09 09:34:33 -04002613 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002614 mnt->mnt_sb = s;
2615 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002616 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002617
Chuck Lever29eb9812007-07-01 12:12:30 -04002618out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002619 security_free_mnt_opts(&data->lsm_opts);
2620out_free_fh:
Trond Myklebustb157b062010-04-19 19:05:48 -04002621 nfs_free_fhandle(mntfh);
Trond Myklebust816724e2006-06-24 08:41:41 -04002622 return error;
David Howells54ceac42006-08-22 20:06:13 -04002623
Chuck Lever29eb9812007-07-01 12:12:30 -04002624out_free:
2625 nfs_free_server(server);
2626 goto out;
2627
Eric Paris46c8ac72008-05-02 13:42:42 -07002628error_splat_root:
2629 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002630error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002631 if (server && !s->s_root)
2632 bdi_unregister(&server->backing_dev_info);
2633error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002634 deactivate_locked_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002635 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002636}
2637
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002638static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2639 int flags, void *data, const char *hostname)
2640{
2641 struct vfsmount *root_mnt;
2642 char *root_devname;
2643 size_t len;
2644
2645 len = strlen(hostname) + 3;
2646 root_devname = kmalloc(len, GFP_KERNEL);
2647 if (root_devname == NULL)
2648 return ERR_PTR(-ENOMEM);
2649 snprintf(root_devname, len, "%s:/", hostname);
2650 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2651 kfree(root_devname);
2652 return root_mnt;
2653}
2654
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002655static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2656{
2657 char *page = (char *) __get_free_page(GFP_KERNEL);
2658 char *devname, *tmp;
2659
2660 if (page == NULL)
2661 return;
2662 devname = nfs_path(path->mnt->mnt_devname,
2663 path->mnt->mnt_root, path->dentry,
2664 page, PAGE_SIZE);
Dan Carpentercdd29ec2010-04-22 15:35:56 -04002665 if (IS_ERR(devname))
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002666 goto out_freepage;
2667 tmp = kstrdup(devname, GFP_KERNEL);
2668 if (tmp == NULL)
2669 goto out_freepage;
2670 kfree(mnt->mnt_devname);
2671 mnt->mnt_devname = tmp;
2672out_freepage:
2673 free_page((unsigned long)page);
2674}
2675
Trond Myklebustce587e02010-04-16 16:22:52 -04002676struct nfs_referral_count {
2677 struct list_head list;
2678 const struct task_struct *task;
2679 unsigned int referral_count;
2680};
2681
2682static LIST_HEAD(nfs_referral_count_list);
2683static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
2684
2685static struct nfs_referral_count *nfs_find_referral_count(void)
2686{
2687 struct nfs_referral_count *p;
2688
2689 list_for_each_entry(p, &nfs_referral_count_list, list) {
2690 if (p->task == current)
2691 return p;
2692 }
2693 return NULL;
2694}
2695
2696#define NFS_MAX_NESTED_REFERRALS 2
2697
2698static int nfs_referral_loop_protect(void)
2699{
2700 struct nfs_referral_count *p, *new;
2701 int ret = -ENOMEM;
2702
2703 new = kmalloc(sizeof(*new), GFP_KERNEL);
2704 if (!new)
2705 goto out;
2706 new->task = current;
2707 new->referral_count = 1;
2708
2709 ret = 0;
2710 spin_lock(&nfs_referral_count_list_lock);
2711 p = nfs_find_referral_count();
2712 if (p != NULL) {
2713 if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
2714 ret = -ELOOP;
2715 else
2716 p->referral_count++;
2717 } else {
2718 list_add(&new->list, &nfs_referral_count_list);
2719 new = NULL;
2720 }
2721 spin_unlock(&nfs_referral_count_list_lock);
2722 kfree(new);
2723out:
2724 return ret;
2725}
2726
2727static void nfs_referral_loop_unprotect(void)
2728{
2729 struct nfs_referral_count *p;
2730
2731 spin_lock(&nfs_referral_count_list_lock);
2732 p = nfs_find_referral_count();
2733 p->referral_count--;
2734 if (p->referral_count == 0)
2735 list_del(&p->list);
2736 else
2737 p = NULL;
2738 spin_unlock(&nfs_referral_count_list_lock);
2739 kfree(p);
2740}
2741
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002742static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2743 const char *export_path, struct vfsmount *mnt_target)
2744{
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002745 struct nameidata *nd = NULL;
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002746 struct mnt_namespace *ns_private;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002747 struct super_block *s;
2748 int ret;
2749
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002750 nd = kmalloc(sizeof(*nd), GFP_KERNEL);
2751 if (nd == NULL)
2752 return -ENOMEM;
2753
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002754 ns_private = create_mnt_ns(root_mnt);
2755 ret = PTR_ERR(ns_private);
2756 if (IS_ERR(ns_private))
2757 goto out_mntput;
2758
Trond Myklebustce587e02010-04-16 16:22:52 -04002759 ret = nfs_referral_loop_protect();
2760 if (ret != 0)
2761 goto out_put_mnt_ns;
2762
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002763 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002764 export_path, LOOKUP_FOLLOW, nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002765
Trond Myklebustce587e02010-04-16 16:22:52 -04002766 nfs_referral_loop_unprotect();
Linus Torvaldsa2770d82009-12-17 12:51:05 -08002767 put_mnt_ns(ns_private);
2768
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002769 if (ret != 0)
2770 goto out_err;
2771
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002772 s = nd->path.mnt->mnt_sb;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002773 atomic_inc(&s->s_active);
2774 mnt_target->mnt_sb = s;
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002775 mnt_target->mnt_root = dget(nd->path.dentry);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002776
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002777 /* Correct the device pathname */
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002778 nfs_fix_devname(&nd->path, mnt_target);
Trond Myklebustb88f8a52009-06-22 15:09:14 -04002779
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002780 path_put(&nd->path);
2781 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002782 down_write(&s->s_umount);
2783 return 0;
Trond Myklebustce587e02010-04-16 16:22:52 -04002784out_put_mnt_ns:
2785 put_mnt_ns(ns_private);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002786out_mntput:
2787 mntput(root_mnt);
2788out_err:
Trond Myklebust04ffdbe2010-04-16 16:22:48 -04002789 kfree(nd);
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002790 return ret;
2791}
2792
Chuck Levera6fe23b2009-09-08 19:50:00 -04002793static int nfs4_try_mount(int flags, const char *dev_name,
2794 struct nfs_parsed_mount_data *data,
2795 struct vfsmount *mnt)
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002796{
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002797 char *export_path;
2798 struct vfsmount *root_mnt;
Chuck Levera6fe23b2009-09-08 19:50:00 -04002799 int error;
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002800
Chuck Levera6fe23b2009-09-08 19:50:00 -04002801 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002802
2803 export_path = data->nfs_server.export_path;
2804 data->nfs_server.export_path = "/";
2805 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2806 data->nfs_server.hostname);
2807 data->nfs_server.export_path = export_path;
2808
2809 error = PTR_ERR(root_mnt);
2810 if (IS_ERR(root_mnt))
2811 goto out;
2812
2813 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2814
2815out:
Chuck Levera6fe23b2009-09-08 19:50:00 -04002816 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2817 error != 0 ? " [error]" : "");
2818 return error;
2819}
2820
2821/*
2822 * Get the superblock for an NFS4 mountpoint
2823 */
2824static int nfs4_get_sb(struct file_system_type *fs_type,
2825 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2826{
2827 struct nfs_parsed_mount_data *data;
2828 int error = -ENOMEM;
2829
Trond Myklebustc5811db2009-10-06 15:40:15 -04002830 data = nfs_alloc_parsed_mount_data(4);
Chuck Levera6fe23b2009-09-08 19:50:00 -04002831 if (data == NULL)
2832 goto out_free_data;
2833
2834 /* Validate the mount data */
2835 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2836 if (error < 0)
2837 goto out;
2838
2839 error = nfs4_try_mount(flags, dev_name, data, mnt);
2840
2841out:
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002842 kfree(data->client_address);
2843 kfree(data->nfs_server.export_path);
2844 kfree(data->nfs_server.hostname);
2845 kfree(data->fscache_uniq);
2846out_free_data:
2847 kfree(data);
2848 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2849 error != 0 ? " [error]" : "");
2850 return error;
2851}
2852
David Howellsf7b422b2006-06-09 09:34:33 -04002853static void nfs4_kill_super(struct super_block *sb)
2854{
2855 struct nfs_server *server = NFS_SB(sb);
2856
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002857 dprintk("--> %s\n", __func__);
Trond Myklebust515d8612008-12-23 15:21:46 -05002858 nfs_super_return_all_delegations(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002859 kill_anon_super(sb);
David Howells08734042009-04-03 16:42:42 +01002860 nfs_fscache_release_super_cookie(sb);
David Howells54ceac42006-08-22 20:06:13 -04002861 nfs_free_server(server);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002862 dprintk("<-- %s\n", __func__);
David Howellsf7b422b2006-06-09 09:34:33 -04002863}
2864
2865/*
David Howells54ceac42006-08-22 20:06:13 -04002866 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002867 */
David Howells54ceac42006-08-22 20:06:13 -04002868static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2869 const char *dev_name, void *raw_data,
2870 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002871{
2872 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002873 struct super_block *s;
2874 struct nfs_server *server;
2875 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002876 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002877 struct nfs_sb_mountdata sb_mntdata = {
2878 .mntflags = flags,
2879 };
David Howells54ceac42006-08-22 20:06:13 -04002880 int error;
2881
2882 dprintk("--> nfs4_xdev_get_sb()\n");
2883
2884 /* create a new volume representation */
2885 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2886 if (IS_ERR(server)) {
2887 error = PTR_ERR(server);
2888 goto out_err_noserver;
2889 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002890 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002891
Trond Myklebust75180df2007-05-16 16:53:28 -04002892 if (server->flags & NFS4_MOUNT_UNSHARED)
2893 compare_super = NULL;
2894
David Howells54ceac42006-08-22 20:06:13 -04002895 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002896 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002897 if (IS_ERR(s)) {
2898 error = PTR_ERR(s);
2899 goto out_err_nosb;
2900 }
2901
2902 if (s->s_fs_info != server) {
2903 nfs_free_server(server);
2904 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002905 } else {
2906 error = nfs_bdi_register(server);
2907 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002908 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002909 }
2910
2911 if (!s->s_root) {
2912 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002913 nfs4_clone_super(s, data->sb);
David Howells2df54802009-09-23 14:36:39 -04002914 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04002915 }
2916
2917 mntroot = nfs4_get_root(s, data->fh);
2918 if (IS_ERR(mntroot)) {
2919 error = PTR_ERR(mntroot);
2920 goto error_splat_super;
2921 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002922 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2923 dput(mntroot);
2924 error = -ESTALE;
2925 goto error_splat_super;
2926 }
David Howells54ceac42006-08-22 20:06:13 -04002927
2928 s->s_flags |= MS_ACTIVE;
2929 mnt->mnt_sb = s;
2930 mnt->mnt_root = mntroot;
2931
Eric Paris46c8ac72008-05-02 13:42:42 -07002932 security_sb_clone_mnt_opts(data->sb, s);
2933
David Howells54ceac42006-08-22 20:06:13 -04002934 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2935 return 0;
2936
2937out_err_nosb:
2938 nfs_free_server(server);
2939out_err_noserver:
2940 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2941 return error;
2942
2943error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11002944 if (server && !s->s_root)
2945 bdi_unregister(&server->backing_dev_info);
2946error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04002947 deactivate_locked_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002948 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2949 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002950}
2951
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04002952static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2953 int flags, const char *dev_name, void *raw_data,
2954 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002955{
2956 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002957 struct super_block *s;
2958 struct nfs_server *server;
2959 struct dentry *mntroot;
Trond Myklebust4f727292010-04-16 16:22:48 -04002960 struct nfs_fh *mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002961 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002962 struct nfs_sb_mountdata sb_mntdata = {
2963 .mntflags = flags,
2964 };
Trond Myklebust4f727292010-04-16 16:22:48 -04002965 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04002966
2967 dprintk("--> nfs4_referral_get_sb()\n");
2968
Trond Myklebust4f727292010-04-16 16:22:48 -04002969 mntfh = nfs_alloc_fhandle();
2970 if (mntfh == NULL)
2971 goto out_err_nofh;
2972
David Howells54ceac42006-08-22 20:06:13 -04002973 /* create a new volume representation */
Trond Myklebust4f727292010-04-16 16:22:48 -04002974 server = nfs4_create_referral_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002975 if (IS_ERR(server)) {
2976 error = PTR_ERR(server);
2977 goto out_err_noserver;
2978 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002979 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002980
Trond Myklebust75180df2007-05-16 16:53:28 -04002981 if (server->flags & NFS4_MOUNT_UNSHARED)
2982 compare_super = NULL;
2983
David Howells54ceac42006-08-22 20:06:13 -04002984 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002985 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002986 if (IS_ERR(s)) {
2987 error = PTR_ERR(s);
2988 goto out_err_nosb;
2989 }
2990
2991 if (s->s_fs_info != server) {
2992 nfs_free_server(server);
2993 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002994 } else {
2995 error = nfs_bdi_register(server);
2996 if (error)
NeilBrowncfbc0682010-03-11 11:20:17 +11002997 goto error_splat_bdi;
David Howells54ceac42006-08-22 20:06:13 -04002998 }
2999
3000 if (!s->s_root) {
3001 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04003002 nfs4_fill_super(s);
David Howells2df54802009-09-23 14:36:39 -04003003 nfs_fscache_get_super_cookie(s, NULL, data);
David Howells54ceac42006-08-22 20:06:13 -04003004 }
3005
Trond Myklebust4f727292010-04-16 16:22:48 -04003006 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003007 if (IS_ERR(mntroot)) {
3008 error = PTR_ERR(mntroot);
3009 goto error_splat_super;
3010 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05003011 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
3012 dput(mntroot);
3013 error = -ESTALE;
3014 goto error_splat_super;
3015 }
David Howells54ceac42006-08-22 20:06:13 -04003016
3017 s->s_flags |= MS_ACTIVE;
3018 mnt->mnt_sb = s;
3019 mnt->mnt_root = mntroot;
3020
Eric Paris46c8ac72008-05-02 13:42:42 -07003021 security_sb_clone_mnt_opts(data->sb, s);
3022
Trond Myklebust4f727292010-04-16 16:22:48 -04003023 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003024 dprintk("<-- nfs4_referral_get_sb() = 0\n");
3025 return 0;
3026
3027out_err_nosb:
3028 nfs_free_server(server);
3029out_err_noserver:
Trond Myklebust4f727292010-04-16 16:22:48 -04003030 nfs_free_fhandle(mntfh);
3031out_err_nofh:
David Howells54ceac42006-08-22 20:06:13 -04003032 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
3033 return error;
3034
3035error_splat_super:
NeilBrowncfbc0682010-03-11 11:20:17 +11003036 if (server && !s->s_root)
3037 bdi_unregister(&server->backing_dev_info);
3038error_splat_bdi:
Al Viro6f5bbff2009-05-06 01:34:22 -04003039 deactivate_locked_super(s);
Trond Myklebust4f727292010-04-16 16:22:48 -04003040 nfs_free_fhandle(mntfh);
David Howells54ceac42006-08-22 20:06:13 -04003041 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
3042 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04003043}
3044
Trond Myklebustc02d7ad2009-06-22 15:09:14 -04003045/*
3046 * Create an NFS4 server record on referral traversal
3047 */
3048static int nfs4_referral_get_sb(struct file_system_type *fs_type,
3049 int flags, const char *dev_name, void *raw_data,
3050 struct vfsmount *mnt)
3051{
3052 struct nfs_clone_mount *data = raw_data;
3053 char *export_path;
3054 struct vfsmount *root_mnt;
3055 int error;
3056
3057 dprintk("--> nfs4_referral_get_sb()\n");
3058
3059 export_path = data->mnt_path;
3060 data->mnt_path = "/";
3061
3062 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
3063 flags, data, data->hostname);
3064 data->mnt_path = export_path;
3065
3066 error = PTR_ERR(root_mnt);
3067 if (IS_ERR(root_mnt))
3068 goto out;
3069
3070 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
3071out:
3072 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
3073 error != 0 ? " [error]" : "");
3074 return error;
3075}
3076
David Howells54ceac42006-08-22 20:06:13 -04003077#endif /* CONFIG_NFS_V4 */