blob: 75f3cbf922a30a5b6c2b107fa0d0b27ba4535e8a [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 *
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * 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>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
48#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080049#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040050#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040051
52#include <asm/system.h>
53#include <asm/uaccess.h>
54
55#include "nfs4_fs.h"
56#include "callback.h"
57#include "delegation.h"
58#include "iostat.h"
59#include "internal.h"
60
61#define NFSDBG_FACILITY NFSDBG_VFS
62
Chuck Leverbf0fd762007-07-01 12:13:44 -040063enum {
64 /* Mount options that take no arguments */
65 Opt_soft, Opt_hard,
66 Opt_intr, Opt_nointr,
67 Opt_posix, Opt_noposix,
68 Opt_cto, Opt_nocto,
69 Opt_ac, Opt_noac,
70 Opt_lock, Opt_nolock,
71 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040072 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040073 Opt_acl, Opt_noacl,
74 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040075 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040076
77 /* Mount options that take integer arguments */
78 Opt_port,
79 Opt_rsize, Opt_wsize, Opt_bsize,
80 Opt_timeo, Opt_retrans,
81 Opt_acregmin, Opt_acregmax,
82 Opt_acdirmin, Opt_acdirmax,
83 Opt_actimeo,
84 Opt_namelen,
85 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040086 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040087 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040088
89 /* Mount options that take string arguments */
90 Opt_sec, Opt_proto, Opt_mountproto,
Chuck Lever0ac83772007-09-11 18:01:04 -040091 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040092
93 /* Mount options that are ignored */
94 Opt_userspace, Opt_deprecated,
95
96 Opt_err
97};
98
99static match_table_t nfs_mount_option_tokens = {
100 { Opt_userspace, "bg" },
101 { Opt_userspace, "fg" },
102 { Opt_soft, "soft" },
103 { Opt_hard, "hard" },
104 { Opt_intr, "intr" },
105 { Opt_nointr, "nointr" },
106 { Opt_posix, "posix" },
107 { Opt_noposix, "noposix" },
108 { Opt_cto, "cto" },
109 { Opt_nocto, "nocto" },
110 { Opt_ac, "ac" },
111 { Opt_noac, "noac" },
112 { Opt_lock, "lock" },
113 { Opt_nolock, "nolock" },
114 { Opt_v2, "v2" },
115 { Opt_v3, "v3" },
116 { Opt_udp, "udp" },
117 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400118 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400119 { Opt_acl, "acl" },
120 { Opt_noacl, "noacl" },
121 { Opt_rdirplus, "rdirplus" },
122 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400123 { Opt_sharecache, "sharecache" },
124 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400125
126 { Opt_port, "port=%u" },
127 { Opt_rsize, "rsize=%u" },
128 { Opt_wsize, "wsize=%u" },
129 { Opt_bsize, "bsize=%u" },
130 { Opt_timeo, "timeo=%u" },
131 { Opt_retrans, "retrans=%u" },
132 { Opt_acregmin, "acregmin=%u" },
133 { Opt_acregmax, "acregmax=%u" },
134 { Opt_acdirmin, "acdirmin=%u" },
135 { Opt_acdirmax, "acdirmax=%u" },
136 { Opt_actimeo, "actimeo=%u" },
137 { Opt_userspace, "retry=%u" },
138 { Opt_namelen, "namlen=%u" },
139 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400140 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_nfsvers, "nfsvers=%u" },
142 { Opt_nfsvers, "vers=%u" },
143
144 { Opt_sec, "sec=%s" },
145 { Opt_proto, "proto=%s" },
146 { Opt_mountproto, "mountproto=%s" },
147 { Opt_addr, "addr=%s" },
148 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400149 { Opt_userspace, "mounthost=%s" },
150 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
152 { Opt_err, NULL }
153};
154
155enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400156 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400157
158 Opt_xprt_err
159};
160
161static match_table_t nfs_xprt_protocol_tokens = {
162 { Opt_xprt_udp, "udp" },
163 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400164 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400165
166 { Opt_xprt_err, NULL }
167};
168
169enum {
170 Opt_sec_none, Opt_sec_sys,
171 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
172 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
173 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
174
175 Opt_sec_err
176};
177
178static match_table_t nfs_secflavor_tokens = {
179 { Opt_sec_none, "none" },
180 { Opt_sec_none, "null" },
181 { Opt_sec_sys, "sys" },
182
183 { Opt_sec_krb5, "krb5" },
184 { Opt_sec_krb5i, "krb5i" },
185 { Opt_sec_krb5p, "krb5p" },
186
187 { Opt_sec_lkey, "lkey" },
188 { Opt_sec_lkeyi, "lkeyi" },
189 { Opt_sec_lkeyp, "lkeyp" },
190
191 { Opt_sec_err, NULL }
192};
193
194
David Howellsf7b422b2006-06-09 09:34:33 -0400195static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400196static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400197static int nfs_show_options(struct seq_file *, struct vfsmount *);
198static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400199static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400200static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400201 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400202static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500203static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400204
205static struct file_system_type nfs_fs_type = {
206 .owner = THIS_MODULE,
207 .name = "nfs",
208 .get_sb = nfs_get_sb,
209 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700210 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400211};
212
David Howells54ceac42006-08-22 20:06:13 -0400213struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400214 .owner = THIS_MODULE,
215 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400216 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400217 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700218 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400219};
220
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800221static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400222 .alloc_inode = nfs_alloc_inode,
223 .destroy_inode = nfs_destroy_inode,
224 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500225 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400226 .statfs = nfs_statfs,
227 .clear_inode = nfs_clear_inode,
228 .umount_begin = nfs_umount_begin,
229 .show_options = nfs_show_options,
230 .show_stats = nfs_show_stats,
231};
232
233#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400234static int nfs4_get_sb(struct file_system_type *fs_type,
235 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400236static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
237 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
238static int nfs4_referral_get_sb(struct file_system_type *fs_type,
239 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400240static void nfs4_kill_super(struct super_block *sb);
241
242static struct file_system_type nfs4_fs_type = {
243 .owner = THIS_MODULE,
244 .name = "nfs4",
245 .get_sb = nfs4_get_sb,
246 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700247 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400248};
249
David Howells54ceac42006-08-22 20:06:13 -0400250struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400251 .owner = THIS_MODULE,
252 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400253 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400254 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400256};
257
David Howells54ceac42006-08-22 20:06:13 -0400258struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .owner = THIS_MODULE,
260 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400261 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400262 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700263 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400264};
265
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800266static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400267 .alloc_inode = nfs_alloc_inode,
268 .destroy_inode = nfs_destroy_inode,
269 .write_inode = nfs_write_inode,
270 .statfs = nfs_statfs,
271 .clear_inode = nfs4_clear_inode,
272 .umount_begin = nfs_umount_begin,
273 .show_options = nfs_show_options,
274 .show_stats = nfs_show_stats,
275};
276#endif
277
Rusty Russell8e1f9362007-07-17 04:03:17 -0700278static struct shrinker acl_shrinker = {
279 .shrink = nfs_access_cache_shrinker,
280 .seeks = DEFAULT_SEEKS,
281};
Trond Myklebust979df722006-07-25 11:28:19 -0400282
David Howellsf7b422b2006-06-09 09:34:33 -0400283/*
284 * Register the NFS filesystems
285 */
286int __init register_nfs_fs(void)
287{
288 int ret;
289
290 ret = register_filesystem(&nfs_fs_type);
291 if (ret < 0)
292 goto error_0;
293
David Howellsf7b422b2006-06-09 09:34:33 -0400294 ret = nfs_register_sysctl();
295 if (ret < 0)
296 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800297#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400298 ret = register_filesystem(&nfs4_fs_type);
299 if (ret < 0)
300 goto error_2;
301#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700302 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400303 return 0;
304
305#ifdef CONFIG_NFS_V4
306error_2:
307 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800308#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400309error_1:
310 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400311error_0:
312 return ret;
313}
314
315/*
316 * Unregister the NFS filesystems
317 */
318void __exit unregister_nfs_fs(void)
319{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700320 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400321#ifdef CONFIG_NFS_V4
322 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400323#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700324 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400325 unregister_filesystem(&nfs_fs_type);
326}
327
Steve Dicksonef818a22007-11-08 04:05:04 -0500328void nfs_sb_active(struct nfs_server *server)
329{
330 atomic_inc(&server->active);
331}
332
333void nfs_sb_deactive(struct nfs_server *server)
334{
335 if (atomic_dec_and_test(&server->active))
336 wake_up(&server->active_wq);
337}
338
339static void nfs_put_super(struct super_block *sb)
340{
341 struct nfs_server *server = NFS_SB(sb);
342 /*
343 * Make sure there are no outstanding ops to this server.
344 * If so, wait for them to finish before allowing the
345 * unmount to continue.
346 */
347 wait_event(server->active_wq, atomic_read(&server->active) == 0);
348}
349
David Howellsf7b422b2006-06-09 09:34:33 -0400350/*
351 * Deliver file system statistics to userspace
352 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400353static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400354{
David Howells0c7d90c2006-08-22 20:06:10 -0400355 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400356 unsigned char blockbits;
357 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400358 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400359 struct nfs_fattr fattr;
360 struct nfs_fsstat res = {
361 .fattr = &fattr,
362 };
363 int error;
364
365 lock_kernel();
366
David Howells8fa5c002006-08-22 20:06:12 -0400367 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400368 if (error < 0)
369 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700370 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400371
372 /*
373 * Current versions of glibc do not correctly handle the
374 * case where f_frsize != f_bsize. Eventually we want to
375 * report the value of wtmult in this field.
376 */
David Howells0c7d90c2006-08-22 20:06:10 -0400377 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400378
379 /*
380 * On most *nix systems, f_blocks, f_bfree, and f_bavail
381 * are reported in units of f_frsize. Linux hasn't had
382 * an f_frsize field in its statfs struct until recently,
383 * thus historically Linux's sys_statfs reports these
384 * fields in units of f_bsize.
385 */
David Howells0c7d90c2006-08-22 20:06:10 -0400386 buf->f_bsize = dentry->d_sb->s_blocksize;
387 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400388 blockres = (1 << blockbits) - 1;
389 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
390 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
391 buf->f_bavail = (res.abytes + blockres) >> blockbits;
392
393 buf->f_files = res.tfiles;
394 buf->f_ffree = res.afiles;
395
396 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700397
David Howellsf7b422b2006-06-09 09:34:33 -0400398 unlock_kernel();
399 return 0;
400
401 out_err:
402 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700403 unlock_kernel();
404 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400405}
406
David Howells7d4e2742006-08-22 20:06:07 -0400407/*
408 * Map the security flavour number to a name
409 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400410static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
411{
David Howells7d4e2742006-08-22 20:06:07 -0400412 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400413 rpc_authflavor_t flavour;
414 const char *str;
415 } sec_flavours[] = {
416 { RPC_AUTH_NULL, "null" },
417 { RPC_AUTH_UNIX, "sys" },
418 { RPC_AUTH_GSS_KRB5, "krb5" },
419 { RPC_AUTH_GSS_KRB5I, "krb5i" },
420 { RPC_AUTH_GSS_KRB5P, "krb5p" },
421 { RPC_AUTH_GSS_LKEY, "lkey" },
422 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
423 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
424 { RPC_AUTH_GSS_SPKM, "spkm" },
425 { RPC_AUTH_GSS_SPKMI, "spkmi" },
426 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400427 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400428 };
429 int i;
430
Chuck Lever4d81cd12007-07-01 12:12:40 -0400431 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400432 if (sec_flavours[i].flavour == flavour)
433 break;
434 }
435 return sec_flavours[i].str;
436}
437
David Howellsf7b422b2006-06-09 09:34:33 -0400438/*
439 * Describe the mount options in force on this server representation
440 */
441static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
442{
David Howells509de812006-08-22 20:06:11 -0400443 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400444 int flag;
David Howells509de812006-08-22 20:06:11 -0400445 const char *str;
446 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400447 } nfs_info[] = {
448 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Leverbcf35612007-09-24 15:39:55 -0400449 { NFS_MOUNT_INTR, ",intr", ",nointr" },
David Howellsf7b422b2006-06-09 09:34:33 -0400450 { NFS_MOUNT_NOCTO, ",nocto", "" },
451 { NFS_MOUNT_NOAC, ",noac", "" },
452 { NFS_MOUNT_NONLM, ",nolock", "" },
453 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400454 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400455 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400456 { 0, NULL, NULL }
457 };
David Howells509de812006-08-22 20:06:11 -0400458 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400459 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400460
David Howells8fa5c002006-08-22 20:06:12 -0400461 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400462 seq_printf(m, ",rsize=%d", nfss->rsize);
463 seq_printf(m, ",wsize=%d", nfss->wsize);
464 if (nfss->acregmin != 3*HZ || showdefaults)
465 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
466 if (nfss->acregmax != 60*HZ || showdefaults)
467 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
468 if (nfss->acdirmin != 30*HZ || showdefaults)
469 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
470 if (nfss->acdirmax != 60*HZ || showdefaults)
471 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
472 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
473 if (nfss->flags & nfs_infop->flag)
474 seq_puts(m, nfs_infop->str);
475 else
476 seq_puts(m, nfs_infop->nostr);
477 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400478 seq_printf(m, ",proto=%s",
479 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
David Howells5006a762006-08-22 20:06:12 -0400480 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
481 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400482 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400483}
484
485/*
486 * Describe the mount options on this VFS mountpoint
487 */
488static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
489{
490 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
491
492 nfs_show_mount_options(m, nfss, 0);
493
Chuck Lever5d8515c2007-12-10 14:57:16 -0500494 seq_printf(m, ",addr=%s",
495 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
496 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400497
498 return 0;
499}
500
501/*
502 * Present statistical information for this VFS mountpoint
503 */
504static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
505{
506 int i, cpu;
507 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
508 struct rpc_auth *auth = nfss->client->cl_auth;
509 struct nfs_iostats totals = { };
510
511 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
512
513 /*
514 * Display all mount option settings
515 */
516 seq_printf(m, "\n\topts:\t");
517 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
521 nfs_show_mount_options(m, nfss, 1);
522
523 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
524
525 seq_printf(m, "\n\tcaps:\t");
526 seq_printf(m, "caps=0x%x", nfss->caps);
527 seq_printf(m, ",wtmult=%d", nfss->wtmult);
528 seq_printf(m, ",dtsize=%d", nfss->dtsize);
529 seq_printf(m, ",bsize=%d", nfss->bsize);
530 seq_printf(m, ",namelen=%d", nfss->namelen);
531
532#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500533 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400534 seq_printf(m, "\n\tnfsv4:\t");
535 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
536 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
537 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
538 }
539#endif
540
541 /*
542 * Display security flavor in effect for this mount
543 */
544 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
545 if (auth->au_flavor)
546 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
547
548 /*
549 * Display superblock I/O counters
550 */
551 for_each_possible_cpu(cpu) {
552 struct nfs_iostats *stats;
553
554 preempt_disable();
555 stats = per_cpu_ptr(nfss->io_stats, cpu);
556
557 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
558 totals.events[i] += stats->events[i];
559 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
560 totals.bytes[i] += stats->bytes[i];
561
562 preempt_enable();
563 }
564
565 seq_printf(m, "\n\tevents:\t");
566 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
567 seq_printf(m, "%lu ", totals.events[i]);
568 seq_printf(m, "\n\tbytes:\t");
569 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
570 seq_printf(m, "%Lu ", totals.bytes[i]);
571 seq_printf(m, "\n");
572
573 rpc_print_iostats(m, nfss->client);
574
575 return 0;
576}
577
578/*
579 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400580 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400581 */
582static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
583{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400584 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
585 struct rpc_clnt *rpc;
586
David Howellsf7b422b2006-06-09 09:34:33 -0400587 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400588
589 if (!(flags & MNT_FORCE))
590 return;
591 /* -EIO all pending I/O */
592 rpc = server->client_acl;
593 if (!IS_ERR(rpc))
594 rpc_killall_tasks(rpc);
595 rpc = server->client;
596 if (!IS_ERR(rpc))
597 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400598}
599
600/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400601 * Sanity-check a server address provided by the mount command
602 */
603static int nfs_verify_server_address(struct sockaddr *addr)
604{
605 switch (addr->sa_family) {
606 case AF_INET: {
607 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
608 if (sa->sin_addr.s_addr != INADDR_ANY)
609 return 1;
610 break;
611 }
612 }
613
614 return 0;
615}
616
617/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400618 * Error-check and convert a string of mount options from user space into
619 * a data structure
620 */
621static int nfs_parse_mount_options(char *raw,
622 struct nfs_parsed_mount_data *mnt)
623{
624 char *p, *string;
625
626 if (!raw) {
627 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
628 return 1;
629 }
630 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
631
632 while ((p = strsep(&raw, ",")) != NULL) {
633 substring_t args[MAX_OPT_ARGS];
634 int option, token;
635
636 if (!*p)
637 continue;
638
639 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
640
641 token = match_token(p, nfs_mount_option_tokens, args);
642 switch (token) {
643 case Opt_soft:
644 mnt->flags |= NFS_MOUNT_SOFT;
645 break;
646 case Opt_hard:
647 mnt->flags &= ~NFS_MOUNT_SOFT;
648 break;
649 case Opt_intr:
650 mnt->flags |= NFS_MOUNT_INTR;
651 break;
652 case Opt_nointr:
653 mnt->flags &= ~NFS_MOUNT_INTR;
654 break;
655 case Opt_posix:
656 mnt->flags |= NFS_MOUNT_POSIX;
657 break;
658 case Opt_noposix:
659 mnt->flags &= ~NFS_MOUNT_POSIX;
660 break;
661 case Opt_cto:
662 mnt->flags &= ~NFS_MOUNT_NOCTO;
663 break;
664 case Opt_nocto:
665 mnt->flags |= NFS_MOUNT_NOCTO;
666 break;
667 case Opt_ac:
668 mnt->flags &= ~NFS_MOUNT_NOAC;
669 break;
670 case Opt_noac:
671 mnt->flags |= NFS_MOUNT_NOAC;
672 break;
673 case Opt_lock:
674 mnt->flags &= ~NFS_MOUNT_NONLM;
675 break;
676 case Opt_nolock:
677 mnt->flags |= NFS_MOUNT_NONLM;
678 break;
679 case Opt_v2:
680 mnt->flags &= ~NFS_MOUNT_VER3;
681 break;
682 case Opt_v3:
683 mnt->flags |= NFS_MOUNT_VER3;
684 break;
685 case Opt_udp:
686 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400687 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400688 mnt->timeo = 7;
689 mnt->retrans = 5;
690 break;
691 case Opt_tcp:
692 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400693 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400694 mnt->timeo = 600;
695 mnt->retrans = 2;
696 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400697 case Opt_rdma:
698 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
699 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
700 mnt->timeo = 600;
701 mnt->retrans = 2;
702 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400703 case Opt_acl:
704 mnt->flags &= ~NFS_MOUNT_NOACL;
705 break;
706 case Opt_noacl:
707 mnt->flags |= NFS_MOUNT_NOACL;
708 break;
709 case Opt_rdirplus:
710 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
711 break;
712 case Opt_nordirplus:
713 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
714 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400715 case Opt_sharecache:
716 mnt->flags &= ~NFS_MOUNT_UNSHARED;
717 break;
718 case Opt_nosharecache:
719 mnt->flags |= NFS_MOUNT_UNSHARED;
720 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400721
722 case Opt_port:
723 if (match_int(args, &option))
724 return 0;
725 if (option < 0 || option > 65535)
726 return 0;
Al Viro410896442007-07-22 10:59:06 +0100727 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400728 break;
729 case Opt_rsize:
730 if (match_int(args, &mnt->rsize))
731 return 0;
732 break;
733 case Opt_wsize:
734 if (match_int(args, &mnt->wsize))
735 return 0;
736 break;
737 case Opt_bsize:
738 if (match_int(args, &option))
739 return 0;
740 if (option < 0)
741 return 0;
742 mnt->bsize = option;
743 break;
744 case Opt_timeo:
745 if (match_int(args, &mnt->timeo))
746 return 0;
747 break;
748 case Opt_retrans:
749 if (match_int(args, &mnt->retrans))
750 return 0;
751 break;
752 case Opt_acregmin:
753 if (match_int(args, &mnt->acregmin))
754 return 0;
755 break;
756 case Opt_acregmax:
757 if (match_int(args, &mnt->acregmax))
758 return 0;
759 break;
760 case Opt_acdirmin:
761 if (match_int(args, &mnt->acdirmin))
762 return 0;
763 break;
764 case Opt_acdirmax:
765 if (match_int(args, &mnt->acdirmax))
766 return 0;
767 break;
768 case Opt_actimeo:
769 if (match_int(args, &option))
770 return 0;
771 if (option < 0)
772 return 0;
773 mnt->acregmin =
774 mnt->acregmax =
775 mnt->acdirmin =
776 mnt->acdirmax = option;
777 break;
778 case Opt_namelen:
779 if (match_int(args, &mnt->namlen))
780 return 0;
781 break;
782 case Opt_mountport:
783 if (match_int(args, &option))
784 return 0;
785 if (option < 0 || option > 65535)
786 return 0;
787 mnt->mount_server.port = option;
788 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400789 case Opt_mountvers:
790 if (match_int(args, &option))
791 return 0;
792 if (option < 0)
793 return 0;
794 mnt->mount_server.version = option;
795 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400796 case Opt_nfsvers:
797 if (match_int(args, &option))
798 return 0;
799 switch (option) {
800 case 2:
801 mnt->flags &= ~NFS_MOUNT_VER3;
802 break;
803 case 3:
804 mnt->flags |= NFS_MOUNT_VER3;
805 break;
806 default:
807 goto out_unrec_vers;
808 }
809 break;
810
811 case Opt_sec:
812 string = match_strdup(args);
813 if (string == NULL)
814 goto out_nomem;
815 token = match_token(string, nfs_secflavor_tokens, args);
816 kfree(string);
817
818 /*
819 * The flags setting is for v2/v3. The flavor_len
820 * setting is for v4. v2/v3 also need to know the
821 * difference between NULL and UNIX.
822 */
823 switch (token) {
824 case Opt_sec_none:
825 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
826 mnt->auth_flavor_len = 0;
827 mnt->auth_flavors[0] = RPC_AUTH_NULL;
828 break;
829 case Opt_sec_sys:
830 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
831 mnt->auth_flavor_len = 0;
832 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
833 break;
834 case Opt_sec_krb5:
835 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
836 mnt->auth_flavor_len = 1;
837 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
838 break;
839 case Opt_sec_krb5i:
840 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
841 mnt->auth_flavor_len = 1;
842 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
843 break;
844 case Opt_sec_krb5p:
845 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
846 mnt->auth_flavor_len = 1;
847 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
848 break;
849 case Opt_sec_lkey:
850 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
851 mnt->auth_flavor_len = 1;
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
853 break;
854 case Opt_sec_lkeyi:
855 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
856 mnt->auth_flavor_len = 1;
857 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
858 break;
859 case Opt_sec_lkeyp:
860 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
861 mnt->auth_flavor_len = 1;
862 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
863 break;
864 case Opt_sec_spkm:
865 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
866 mnt->auth_flavor_len = 1;
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
868 break;
869 case Opt_sec_spkmi:
870 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
871 mnt->auth_flavor_len = 1;
872 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
873 break;
874 case Opt_sec_spkmp:
875 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
878 break;
879 default:
880 goto out_unrec_sec;
881 }
882 break;
883 case Opt_proto:
884 string = match_strdup(args);
885 if (string == NULL)
886 goto out_nomem;
887 token = match_token(string,
888 nfs_xprt_protocol_tokens, args);
889 kfree(string);
890
891 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400892 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400893 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400894 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400895 mnt->timeo = 7;
896 mnt->retrans = 5;
897 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400898 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400899 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400900 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400901 mnt->timeo = 600;
902 mnt->retrans = 2;
903 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400904 case Opt_xprt_rdma:
905 /* vector side protocols to TCP */
906 mnt->flags |= NFS_MOUNT_TCP;
907 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
908 mnt->timeo = 600;
909 mnt->retrans = 2;
910 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400911 default:
912 goto out_unrec_xprt;
913 }
914 break;
915 case Opt_mountproto:
916 string = match_strdup(args);
917 if (string == NULL)
918 goto out_nomem;
919 token = match_token(string,
920 nfs_xprt_protocol_tokens, args);
921 kfree(string);
922
923 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400924 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400925 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400926 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400927 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400928 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400929 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400930 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400931 default:
932 goto out_unrec_xprt;
933 }
934 break;
935 case Opt_addr:
936 string = match_strdup(args);
937 if (string == NULL)
938 goto out_nomem;
939 mnt->nfs_server.address.sin_family = AF_INET;
940 mnt->nfs_server.address.sin_addr.s_addr =
941 in_aton(string);
942 kfree(string);
943 break;
944 case Opt_clientaddr:
945 string = match_strdup(args);
946 if (string == NULL)
947 goto out_nomem;
948 mnt->client_address = string;
949 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400950 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400951 string = match_strdup(args);
952 if (string == NULL)
953 goto out_nomem;
954 mnt->mount_server.address.sin_family = AF_INET;
955 mnt->mount_server.address.sin_addr.s_addr =
956 in_aton(string);
957 kfree(string);
958 break;
959
960 case Opt_userspace:
961 case Opt_deprecated:
962 break;
963
964 default:
965 goto out_unknown;
966 }
967 }
968
969 return 1;
970
971out_nomem:
972 printk(KERN_INFO "NFS: not enough memory to parse option\n");
973 return 0;
974
975out_unrec_vers:
976 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
977 return 0;
978
979out_unrec_xprt:
980 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
981 return 0;
982
983out_unrec_sec:
984 printk(KERN_INFO "NFS: unrecognized security flavor\n");
985 return 0;
986
987out_unknown:
988 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
989 return 0;
990}
991
992/*
Chuck Lever0076d7b2007-07-01 12:13:49 -0400993 * Use the remote server's MOUNT service to request the NFS file handle
994 * corresponding to the provided path.
995 */
996static int nfs_try_mount(struct nfs_parsed_mount_data *args,
997 struct nfs_fh *root_fh)
998{
999 struct sockaddr_in sin;
1000 int status;
1001
1002 if (args->mount_server.version == 0) {
1003 if (args->flags & NFS_MOUNT_VER3)
1004 args->mount_server.version = NFS_MNT3_VERSION;
1005 else
1006 args->mount_server.version = NFS_MNT_VERSION;
1007 }
1008
1009 /*
1010 * Construct the mount server's address.
1011 */
1012 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1013 sin = args->mount_server.address;
1014 else
1015 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001016 /*
1017 * autobind will be used if mount_server.port == 0
1018 */
1019 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001020
1021 /*
1022 * Now ask the mount server to map our export path
1023 * to a file handle.
1024 */
1025 status = nfs_mount((struct sockaddr *) &sin,
1026 sizeof(sin),
1027 args->nfs_server.hostname,
1028 args->nfs_server.export_path,
1029 args->mount_server.version,
1030 args->mount_server.protocol,
1031 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001032 if (status == 0)
1033 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001034
Chuck Leverefd83402007-09-11 18:00:58 -04001035 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1036 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001037 return status;
1038}
1039
1040/*
David Howells54ceac42006-08-22 20:06:13 -04001041 * Validate the NFS2/NFS3 mount data
1042 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001043 *
1044 * For option strings, user space handles the following behaviors:
1045 *
1046 * + DNS: mapping server host name to IP address ("addr=" option)
1047 *
1048 * + failure mode: how to behave if a mount request can't be handled
1049 * immediately ("fg/bg" option)
1050 *
1051 * + retry: how often to retry a mount request ("retry=" option)
1052 *
1053 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1054 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001055 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001056static int nfs_validate_mount_data(void *options,
1057 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001058 struct nfs_fh *mntfh,
1059 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001060{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001061 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001062
Russell Kingf16c9602007-11-16 22:13:24 +00001063 memset(args, 0, sizeof(*args));
1064
Chuck Lever5df36e72007-07-01 12:12:56 -04001065 if (data == NULL)
1066 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001067
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001068 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1069 args->rsize = NFS_MAX_FILE_IO_SIZE;
1070 args->wsize = NFS_MAX_FILE_IO_SIZE;
1071 args->timeo = 600;
1072 args->retrans = 2;
1073 args->acregmin = 3;
1074 args->acregmax = 60;
1075 args->acdirmin = 30;
1076 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001077 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001078 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001079
David Howellsf7b422b2006-06-09 09:34:33 -04001080 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001081 case 1:
1082 data->namlen = 0;
1083 case 2:
1084 data->bsize = 0;
1085 case 3:
1086 if (data->flags & NFS_MOUNT_VER3)
1087 goto out_no_v3;
1088 data->root.size = NFS2_FHSIZE;
1089 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1090 case 4:
1091 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1092 goto out_no_sec;
1093 case 5:
1094 memset(data->context, 0, sizeof(data->context));
1095 case 6:
1096 if (data->flags & NFS_MOUNT_VER3)
1097 mntfh->size = data->root.size;
1098 else
1099 mntfh->size = NFS2_FHSIZE;
1100
1101 if (mntfh->size > sizeof(mntfh->data))
1102 goto out_invalid_fh;
1103
1104 memcpy(mntfh->data, data->root.data, mntfh->size);
1105 if (mntfh->size < sizeof(mntfh->data))
1106 memset(mntfh->data + mntfh->size, 0,
1107 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001108
1109 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1110 goto out_no_address;
1111
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001112 /*
1113 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1114 * can deal with.
1115 */
1116 args->flags = data->flags;
1117 args->rsize = data->rsize;
1118 args->wsize = data->wsize;
1119 args->flags = data->flags;
1120 args->timeo = data->timeo;
1121 args->retrans = data->retrans;
1122 args->acregmin = data->acregmin;
1123 args->acregmax = data->acregmax;
1124 args->acdirmin = data->acdirmin;
1125 args->acdirmax = data->acdirmax;
1126 args->nfs_server.address = data->addr;
1127 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001128 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001129 /* N.B. caller will free nfs_server.hostname in all cases */
1130 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1131 args->namlen = data->namlen;
1132 args->bsize = data->bsize;
1133 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001134 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001135 default: {
1136 unsigned int len;
1137 char *c;
1138 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001139
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001140 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001141 return -EINVAL;
1142
Chuck Lever6e88e062007-09-24 15:39:50 -04001143 if (!nfs_verify_server_address((struct sockaddr *)
1144 &args->nfs_server.address))
1145 goto out_no_address;
1146
Chuck Lever136d5582007-07-01 12:13:54 -04001147 c = strchr(dev_name, ':');
1148 if (c == NULL)
1149 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001150 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001151 /* N.B. caller will free nfs_server.hostname in all cases */
1152 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001153
1154 c++;
1155 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001156 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001157 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001158
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001159 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001160 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001161 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001162
Chuck Lever136d5582007-07-01 12:13:54 -04001163 break;
1164 }
David Howellsf7b422b2006-06-09 09:34:33 -04001165 }
David Howells54ceac42006-08-22 20:06:13 -04001166
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001167 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1168 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001169
David Howellsf7b422b2006-06-09 09:34:33 -04001170#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001171 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001172 goto out_v3_not_compiled;
1173#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001174
David Howells54ceac42006-08-22 20:06:13 -04001175 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001176
1177out_no_data:
1178 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1179 return -EINVAL;
1180
1181out_no_v3:
1182 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1183 data->version);
1184 return -EINVAL;
1185
1186out_no_sec:
1187 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1188 return -EINVAL;
1189
Chuck Lever5df36e72007-07-01 12:12:56 -04001190#ifndef CONFIG_NFS_V3
1191out_v3_not_compiled:
1192 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1193 return -EPROTONOSUPPORT;
1194#endif /* !CONFIG_NFS_V3 */
1195
1196out_no_address:
1197 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1198 return -EINVAL;
1199
1200out_invalid_fh:
1201 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1202 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001203}
1204
1205/*
1206 * Initialise the common bits of the superblock
1207 */
1208static inline void nfs_initialise_sb(struct super_block *sb)
1209{
1210 struct nfs_server *server = NFS_SB(sb);
1211
1212 sb->s_magic = NFS_SUPER_MAGIC;
1213
1214 /* We probably want something more informative here */
1215 snprintf(sb->s_id, sizeof(sb->s_id),
1216 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1217
1218 if (sb->s_blocksize == 0)
1219 sb->s_blocksize = nfs_block_bits(server->wsize,
1220 &sb->s_blocksize_bits);
1221
1222 if (server->flags & NFS_MOUNT_NOAC)
1223 sb->s_flags |= MS_SYNCHRONOUS;
1224
1225 nfs_super_set_maxbytes(sb, server->maxfilesize);
1226}
1227
1228/*
1229 * Finish setting up an NFS2/3 superblock
1230 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001231static void nfs_fill_super(struct super_block *sb,
1232 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001233{
1234 struct nfs_server *server = NFS_SB(sb);
1235
1236 sb->s_blocksize_bits = 0;
1237 sb->s_blocksize = 0;
1238 if (data->bsize)
1239 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1240
1241 if (server->flags & NFS_MOUNT_VER3) {
1242 /* The VFS shouldn't apply the umask to mode bits. We will do
1243 * so ourselves when necessary.
1244 */
1245 sb->s_flags |= MS_POSIXACL;
1246 sb->s_time_gran = 1;
1247 }
1248
1249 sb->s_op = &nfs_sops;
1250 nfs_initialise_sb(sb);
1251}
1252
1253/*
1254 * Finish setting up a cloned NFS2/3 superblock
1255 */
1256static void nfs_clone_super(struct super_block *sb,
1257 const struct super_block *old_sb)
1258{
1259 struct nfs_server *server = NFS_SB(sb);
1260
1261 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1262 sb->s_blocksize = old_sb->s_blocksize;
1263 sb->s_maxbytes = old_sb->s_maxbytes;
1264
1265 if (server->flags & NFS_MOUNT_VER3) {
1266 /* The VFS shouldn't apply the umask to mode bits. We will do
1267 * so ourselves when necessary.
1268 */
1269 sb->s_flags |= MS_POSIXACL;
1270 sb->s_time_gran = 1;
1271 }
1272
1273 sb->s_op = old_sb->s_op;
1274 nfs_initialise_sb(sb);
1275}
1276
Trond Myklebust275a5d22007-05-16 16:53:28 -04001277#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1278
1279static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1280{
1281 const struct nfs_server *a = s->s_fs_info;
1282 const struct rpc_clnt *clnt_a = a->client;
1283 const struct rpc_clnt *clnt_b = b->client;
1284
1285 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1286 goto Ebusy;
1287 if (a->nfs_client != b->nfs_client)
1288 goto Ebusy;
1289 if (a->flags != b->flags)
1290 goto Ebusy;
1291 if (a->wsize != b->wsize)
1292 goto Ebusy;
1293 if (a->rsize != b->rsize)
1294 goto Ebusy;
1295 if (a->acregmin != b->acregmin)
1296 goto Ebusy;
1297 if (a->acregmax != b->acregmax)
1298 goto Ebusy;
1299 if (a->acdirmin != b->acdirmin)
1300 goto Ebusy;
1301 if (a->acdirmax != b->acdirmax)
1302 goto Ebusy;
1303 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1304 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001305 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001306Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001307 return 0;
1308}
1309
1310struct nfs_sb_mountdata {
1311 struct nfs_server *server;
1312 int mntflags;
1313};
1314
1315static int nfs_set_super(struct super_block *s, void *data)
1316{
1317 struct nfs_sb_mountdata *sb_mntdata = data;
1318 struct nfs_server *server = sb_mntdata->server;
1319 int ret;
1320
1321 s->s_flags = sb_mntdata->mntflags;
1322 s->s_fs_info = server;
1323 ret = set_anon_super(s, server);
1324 if (ret == 0)
1325 server->s_dev = s->s_dev;
1326 return ret;
1327}
1328
1329static int nfs_compare_super(struct super_block *sb, void *data)
1330{
1331 struct nfs_sb_mountdata *sb_mntdata = data;
1332 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1333 int mntflags = sb_mntdata->mntflags;
1334
1335 if (memcmp(&old->nfs_client->cl_addr,
1336 &server->nfs_client->cl_addr,
1337 sizeof(old->nfs_client->cl_addr)) != 0)
1338 return 0;
1339 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1340 if (old->flags & NFS_MOUNT_UNSHARED)
1341 return 0;
1342 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1343 return 0;
1344 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001345}
1346
David Howells54ceac42006-08-22 20:06:13 -04001347static int nfs_get_sb(struct file_system_type *fs_type,
1348 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1349{
1350 struct nfs_server *server = NULL;
1351 struct super_block *s;
1352 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001353 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001354 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001355 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001356 struct nfs_sb_mountdata sb_mntdata = {
1357 .mntflags = flags,
1358 };
David Howells54ceac42006-08-22 20:06:13 -04001359 int error;
1360
1361 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001362 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001363 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001364 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001365
1366 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001367 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001368 if (IS_ERR(server)) {
1369 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001370 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001371 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001372 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001373
Trond Myklebust75180df2007-05-16 16:53:28 -04001374 if (server->flags & NFS_MOUNT_UNSHARED)
1375 compare_super = NULL;
1376
David Howells54ceac42006-08-22 20:06:13 -04001377 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001378 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001379 if (IS_ERR(s)) {
1380 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001381 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001382 }
1383
David Howells54ceac42006-08-22 20:06:13 -04001384 if (s->s_fs_info != server) {
1385 nfs_free_server(server);
1386 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001387 }
David Howells54ceac42006-08-22 20:06:13 -04001388
1389 if (!s->s_root) {
1390 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001391 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001392 }
1393
1394 mntroot = nfs_get_root(s, &mntfh);
1395 if (IS_ERR(mntroot)) {
1396 error = PTR_ERR(mntroot);
1397 goto error_splat_super;
1398 }
1399
David Howellsf7b422b2006-06-09 09:34:33 -04001400 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001401 mnt->mnt_sb = s;
1402 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001403 error = 0;
1404
1405out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001406 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001407 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001408
David Howells54ceac42006-08-22 20:06:13 -04001409out_err_nosb:
1410 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001411 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001412
1413error_splat_super:
1414 up_write(&s->s_umount);
1415 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001416 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001417}
1418
David Howells54ceac42006-08-22 20:06:13 -04001419/*
1420 * Destroy an NFS2/3 superblock
1421 */
David Howellsf7b422b2006-06-09 09:34:33 -04001422static void nfs_kill_super(struct super_block *s)
1423{
1424 struct nfs_server *server = NFS_SB(s);
1425
1426 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001427 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001428}
1429
David Howells54ceac42006-08-22 20:06:13 -04001430/*
1431 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1432 */
1433static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1434 const char *dev_name, void *raw_data,
1435 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001436{
1437 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001438 struct super_block *s;
1439 struct nfs_server *server;
1440 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001441 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001442 struct nfs_sb_mountdata sb_mntdata = {
1443 .mntflags = flags,
1444 };
David Howells54ceac42006-08-22 20:06:13 -04001445 int error;
1446
1447 dprintk("--> nfs_xdev_get_sb()\n");
1448
1449 /* create a new volume representation */
1450 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1451 if (IS_ERR(server)) {
1452 error = PTR_ERR(server);
1453 goto out_err_noserver;
1454 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001455 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001456
Trond Myklebust75180df2007-05-16 16:53:28 -04001457 if (server->flags & NFS_MOUNT_UNSHARED)
1458 compare_super = NULL;
1459
David Howells54ceac42006-08-22 20:06:13 -04001460 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001461 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001462 if (IS_ERR(s)) {
1463 error = PTR_ERR(s);
1464 goto out_err_nosb;
1465 }
1466
1467 if (s->s_fs_info != server) {
1468 nfs_free_server(server);
1469 server = NULL;
1470 }
1471
1472 if (!s->s_root) {
1473 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001474 nfs_clone_super(s, data->sb);
1475 }
1476
1477 mntroot = nfs_get_root(s, data->fh);
1478 if (IS_ERR(mntroot)) {
1479 error = PTR_ERR(mntroot);
1480 goto error_splat_super;
1481 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001482 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001483 dput(mntroot);
1484 error = -ESTALE;
1485 goto error_splat_super;
1486 }
David Howells54ceac42006-08-22 20:06:13 -04001487
1488 s->s_flags |= MS_ACTIVE;
1489 mnt->mnt_sb = s;
1490 mnt->mnt_root = mntroot;
1491
1492 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1493 return 0;
1494
1495out_err_nosb:
1496 nfs_free_server(server);
1497out_err_noserver:
1498 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1499 return error;
1500
1501error_splat_super:
1502 up_write(&s->s_umount);
1503 deactivate_super(s);
1504 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1505 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001506}
1507
1508#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001509
1510/*
1511 * Finish setting up a cloned NFS4 superblock
1512 */
1513static void nfs4_clone_super(struct super_block *sb,
1514 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001515{
David Howells54ceac42006-08-22 20:06:13 -04001516 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1517 sb->s_blocksize = old_sb->s_blocksize;
1518 sb->s_maxbytes = old_sb->s_maxbytes;
1519 sb->s_time_gran = 1;
1520 sb->s_op = old_sb->s_op;
1521 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001522}
1523
1524/*
1525 * Set up an NFS4 superblock
1526 */
David Howells54ceac42006-08-22 20:06:13 -04001527static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001528{
David Howellsf7b422b2006-06-09 09:34:33 -04001529 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001530 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001531 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001532}
1533
David Howells54ceac42006-08-22 20:06:13 -04001534/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001535 * Validate NFSv4 mount options
1536 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001537static int nfs4_validate_mount_data(void *options,
1538 struct nfs_parsed_mount_data *args,
1539 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001540{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001541 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001542 char *c;
1543
Russell Kingf16c9602007-11-16 22:13:24 +00001544 memset(args, 0, sizeof(*args));
1545
Chuck Leverf0768eb2007-07-01 12:13:01 -04001546 if (data == NULL)
1547 goto out_no_data;
1548
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001549 args->rsize = NFS_MAX_FILE_IO_SIZE;
1550 args->wsize = NFS_MAX_FILE_IO_SIZE;
1551 args->timeo = 600;
1552 args->retrans = 2;
1553 args->acregmin = 3;
1554 args->acregmax = 60;
1555 args->acdirmin = 30;
1556 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001557 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001558
Chuck Leverf0768eb2007-07-01 12:13:01 -04001559 switch (data->version) {
1560 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001561 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001562 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001563 if (copy_from_user(&args->nfs_server.address,
1564 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001565 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001566 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001567 if (args->nfs_server.address.sin_port == 0)
1568 args->nfs_server.address.sin_port = htons(NFS_PORT);
1569 if (!nfs_verify_server_address((struct sockaddr *)
1570 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001571 goto out_no_address;
1572
1573 switch (data->auth_flavourlen) {
1574 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001575 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001576 break;
1577 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001578 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001579 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001580 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001581 return -EFAULT;
1582 break;
1583 default:
1584 goto out_inval_auth;
1585 }
1586
1587 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1588 if (IS_ERR(c))
1589 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001590 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001591
1592 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1593 if (IS_ERR(c))
1594 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001595 args->nfs_server.export_path = c;
1596 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001597
1598 c = strndup_user(data->client_addr.data, 16);
1599 if (IS_ERR(c))
1600 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001601 args->client_address = c;
1602
1603 /*
1604 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1605 * can deal with.
1606 */
1607
1608 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1609 args->rsize = data->rsize;
1610 args->wsize = data->wsize;
1611 args->timeo = data->timeo;
1612 args->retrans = data->retrans;
1613 args->acregmin = data->acregmin;
1614 args->acregmax = data->acregmax;
1615 args->acdirmin = data->acdirmin;
1616 args->acdirmax = data->acdirmax;
1617 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001618
1619 break;
Chuck Lever80071222007-07-01 12:13:59 -04001620 default: {
1621 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001622
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001623 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001624 return -EINVAL;
1625
Chuck Lever0eb25742007-10-26 13:32:19 -04001626 if (args->nfs_server.address.sin_port == 0)
1627 args->nfs_server.address.sin_port = htons(NFS_PORT);
Chuck Lever80071222007-07-01 12:13:59 -04001628 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001629 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001630 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001631
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001632 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001633 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001634 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001635 break;
1636 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001637 break;
1638 default:
1639 goto out_inval_auth;
1640 }
1641
1642 /*
Chuck Lever80071222007-07-01 12:13:59 -04001643 * Split "dev_name" into "hostname:mntpath".
1644 */
1645 c = strchr(dev_name, ':');
1646 if (c == NULL)
1647 return -EINVAL;
1648 /* while calculating len, pretend ':' is '\0' */
1649 len = c - dev_name;
1650 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001651 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001652 /* N.B. caller will free nfs_server.hostname in all cases */
1653 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001654
1655 c++; /* step over the ':' */
1656 len = strlen(c);
1657 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001658 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001659 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001660
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001661 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001662
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001663 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001664 goto out_no_client_address;
1665
Chuck Lever80071222007-07-01 12:13:59 -04001666 break;
1667 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001668 }
1669
1670 return 0;
1671
1672out_no_data:
1673 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1674 return -EINVAL;
1675
1676out_inval_auth:
1677 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1678 data->auth_flavourlen);
1679 return -EINVAL;
1680
1681out_no_address:
1682 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1683 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001684
1685out_no_client_address:
1686 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1687 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001688}
1689
1690/*
David Howells54ceac42006-08-22 20:06:13 -04001691 * Get the superblock for an NFS4 mountpoint
1692 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001693static int nfs4_get_sb(struct file_system_type *fs_type,
1694 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001695{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001696 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001697 struct super_block *s;
1698 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001699 struct nfs_fh mntfh;
1700 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001701 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001702 struct nfs_sb_mountdata sb_mntdata = {
1703 .mntflags = flags,
1704 };
David Howells54ceac42006-08-22 20:06:13 -04001705 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001706
Chuck Leverf0768eb2007-07-01 12:13:01 -04001707 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001708 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001709 if (error < 0)
1710 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001711
David Howells54ceac42006-08-22 20:06:13 -04001712 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001713 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001714 if (IS_ERR(server)) {
1715 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001716 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001717 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001718 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001719
Trond Myklebust75180df2007-05-16 16:53:28 -04001720 if (server->flags & NFS4_MOUNT_UNSHARED)
1721 compare_super = NULL;
1722
David Howells54ceac42006-08-22 20:06:13 -04001723 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001724 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001725 if (IS_ERR(s)) {
1726 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001727 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001728 }
1729
Trond Myklebust5dd31772006-08-24 01:03:05 -04001730 if (s->s_fs_info != server) {
1731 nfs_free_server(server);
1732 server = NULL;
1733 }
1734
David Howells54ceac42006-08-22 20:06:13 -04001735 if (!s->s_root) {
1736 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001737 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001738 }
David Howellsf7b422b2006-06-09 09:34:33 -04001739
David Howells54ceac42006-08-22 20:06:13 -04001740 mntroot = nfs4_get_root(s, &mntfh);
1741 if (IS_ERR(mntroot)) {
1742 error = PTR_ERR(mntroot);
1743 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001744 }
David Howells54ceac42006-08-22 20:06:13 -04001745
David Howellsf7b422b2006-06-09 09:34:33 -04001746 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001747 mnt->mnt_sb = s;
1748 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001749 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001750
Chuck Lever29eb9812007-07-01 12:12:30 -04001751out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001752 kfree(data.client_address);
1753 kfree(data.nfs_server.export_path);
1754 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001755 return error;
David Howells54ceac42006-08-22 20:06:13 -04001756
Chuck Lever29eb9812007-07-01 12:12:30 -04001757out_free:
1758 nfs_free_server(server);
1759 goto out;
1760
David Howells54ceac42006-08-22 20:06:13 -04001761error_splat_super:
1762 up_write(&s->s_umount);
1763 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001764 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001765}
1766
1767static void nfs4_kill_super(struct super_block *sb)
1768{
1769 struct nfs_server *server = NFS_SB(sb);
1770
1771 nfs_return_all_delegations(sb);
1772 kill_anon_super(sb);
1773
1774 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001775 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001776}
1777
1778/*
David Howells54ceac42006-08-22 20:06:13 -04001779 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001780 */
David Howells54ceac42006-08-22 20:06:13 -04001781static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1782 const char *dev_name, void *raw_data,
1783 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001784{
1785 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001786 struct super_block *s;
1787 struct nfs_server *server;
1788 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001789 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001790 struct nfs_sb_mountdata sb_mntdata = {
1791 .mntflags = flags,
1792 };
David Howells54ceac42006-08-22 20:06:13 -04001793 int error;
1794
1795 dprintk("--> nfs4_xdev_get_sb()\n");
1796
1797 /* create a new volume representation */
1798 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1799 if (IS_ERR(server)) {
1800 error = PTR_ERR(server);
1801 goto out_err_noserver;
1802 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001803 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001804
Trond Myklebust75180df2007-05-16 16:53:28 -04001805 if (server->flags & NFS4_MOUNT_UNSHARED)
1806 compare_super = NULL;
1807
David Howells54ceac42006-08-22 20:06:13 -04001808 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001809 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001810 if (IS_ERR(s)) {
1811 error = PTR_ERR(s);
1812 goto out_err_nosb;
1813 }
1814
1815 if (s->s_fs_info != server) {
1816 nfs_free_server(server);
1817 server = NULL;
1818 }
1819
1820 if (!s->s_root) {
1821 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001822 nfs4_clone_super(s, data->sb);
1823 }
1824
1825 mntroot = nfs4_get_root(s, data->fh);
1826 if (IS_ERR(mntroot)) {
1827 error = PTR_ERR(mntroot);
1828 goto error_splat_super;
1829 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001830 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1831 dput(mntroot);
1832 error = -ESTALE;
1833 goto error_splat_super;
1834 }
David Howells54ceac42006-08-22 20:06:13 -04001835
1836 s->s_flags |= MS_ACTIVE;
1837 mnt->mnt_sb = s;
1838 mnt->mnt_root = mntroot;
1839
1840 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1841 return 0;
1842
1843out_err_nosb:
1844 nfs_free_server(server);
1845out_err_noserver:
1846 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1847 return error;
1848
1849error_splat_super:
1850 up_write(&s->s_umount);
1851 deactivate_super(s);
1852 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1853 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001854}
1855
David Howells54ceac42006-08-22 20:06:13 -04001856/*
1857 * Create an NFS4 server record on referral traversal
1858 */
1859static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1860 const char *dev_name, void *raw_data,
1861 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001862{
1863 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001864 struct super_block *s;
1865 struct nfs_server *server;
1866 struct dentry *mntroot;
1867 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001868 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001869 struct nfs_sb_mountdata sb_mntdata = {
1870 .mntflags = flags,
1871 };
David Howells54ceac42006-08-22 20:06:13 -04001872 int error;
1873
1874 dprintk("--> nfs4_referral_get_sb()\n");
1875
1876 /* create a new volume representation */
1877 server = nfs4_create_referral_server(data, &mntfh);
1878 if (IS_ERR(server)) {
1879 error = PTR_ERR(server);
1880 goto out_err_noserver;
1881 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001882 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001883
Trond Myklebust75180df2007-05-16 16:53:28 -04001884 if (server->flags & NFS4_MOUNT_UNSHARED)
1885 compare_super = NULL;
1886
David Howells54ceac42006-08-22 20:06:13 -04001887 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001888 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001889 if (IS_ERR(s)) {
1890 error = PTR_ERR(s);
1891 goto out_err_nosb;
1892 }
1893
1894 if (s->s_fs_info != server) {
1895 nfs_free_server(server);
1896 server = NULL;
1897 }
1898
1899 if (!s->s_root) {
1900 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001901 nfs4_fill_super(s);
1902 }
1903
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001904 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001905 if (IS_ERR(mntroot)) {
1906 error = PTR_ERR(mntroot);
1907 goto error_splat_super;
1908 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001909 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1910 dput(mntroot);
1911 error = -ESTALE;
1912 goto error_splat_super;
1913 }
David Howells54ceac42006-08-22 20:06:13 -04001914
1915 s->s_flags |= MS_ACTIVE;
1916 mnt->mnt_sb = s;
1917 mnt->mnt_root = mntroot;
1918
1919 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1920 return 0;
1921
1922out_err_nosb:
1923 nfs_free_server(server);
1924out_err_noserver:
1925 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1926 return error;
1927
1928error_splat_super:
1929 up_write(&s->s_umount);
1930 deactivate_super(s);
1931 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1932 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001933}
1934
David Howells54ceac42006-08-22 20:06:13 -04001935#endif /* CONFIG_NFS_V4 */