blob: 5608e6a4c1e11d7d38e5f2769e2834ba612b2135 [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
Jeff Laytonddc01c02007-07-30 08:47:38 -0400494 seq_printf(m, ",addr="NIPQUAD_FMT,
495 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
David Howellsf7b422b2006-06-09 09:34:33 -0400496
497 return 0;
498}
499
500/*
501 * Present statistical information for this VFS mountpoint
502 */
503static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
504{
505 int i, cpu;
506 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
507 struct rpc_auth *auth = nfss->client->cl_auth;
508 struct nfs_iostats totals = { };
509
510 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
511
512 /*
513 * Display all mount option settings
514 */
515 seq_printf(m, "\n\topts:\t");
516 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
517 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
520 nfs_show_mount_options(m, nfss, 1);
521
522 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
523
524 seq_printf(m, "\n\tcaps:\t");
525 seq_printf(m, "caps=0x%x", nfss->caps);
526 seq_printf(m, ",wtmult=%d", nfss->wtmult);
527 seq_printf(m, ",dtsize=%d", nfss->dtsize);
528 seq_printf(m, ",bsize=%d", nfss->bsize);
529 seq_printf(m, ",namelen=%d", nfss->namelen);
530
531#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500532 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400533 seq_printf(m, "\n\tnfsv4:\t");
534 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
535 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
536 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
537 }
538#endif
539
540 /*
541 * Display security flavor in effect for this mount
542 */
543 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
544 if (auth->au_flavor)
545 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
546
547 /*
548 * Display superblock I/O counters
549 */
550 for_each_possible_cpu(cpu) {
551 struct nfs_iostats *stats;
552
553 preempt_disable();
554 stats = per_cpu_ptr(nfss->io_stats, cpu);
555
556 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
557 totals.events[i] += stats->events[i];
558 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
559 totals.bytes[i] += stats->bytes[i];
560
561 preempt_enable();
562 }
563
564 seq_printf(m, "\n\tevents:\t");
565 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
566 seq_printf(m, "%lu ", totals.events[i]);
567 seq_printf(m, "\n\tbytes:\t");
568 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
569 seq_printf(m, "%Lu ", totals.bytes[i]);
570 seq_printf(m, "\n");
571
572 rpc_print_iostats(m, nfss->client);
573
574 return 0;
575}
576
577/*
578 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400579 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400580 */
581static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
582{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400583 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
584 struct rpc_clnt *rpc;
585
David Howellsf7b422b2006-06-09 09:34:33 -0400586 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400587
588 if (!(flags & MNT_FORCE))
589 return;
590 /* -EIO all pending I/O */
591 rpc = server->client_acl;
592 if (!IS_ERR(rpc))
593 rpc_killall_tasks(rpc);
594 rpc = server->client;
595 if (!IS_ERR(rpc))
596 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400597}
598
599/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400600 * Sanity-check a server address provided by the mount command
601 */
602static int nfs_verify_server_address(struct sockaddr *addr)
603{
604 switch (addr->sa_family) {
605 case AF_INET: {
606 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
607 if (sa->sin_addr.s_addr != INADDR_ANY)
608 return 1;
609 break;
610 }
611 }
612
613 return 0;
614}
615
616/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400617 * Error-check and convert a string of mount options from user space into
618 * a data structure
619 */
620static int nfs_parse_mount_options(char *raw,
621 struct nfs_parsed_mount_data *mnt)
622{
623 char *p, *string;
624
625 if (!raw) {
626 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
627 return 1;
628 }
629 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
630
631 while ((p = strsep(&raw, ",")) != NULL) {
632 substring_t args[MAX_OPT_ARGS];
633 int option, token;
634
635 if (!*p)
636 continue;
637
638 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
639
640 token = match_token(p, nfs_mount_option_tokens, args);
641 switch (token) {
642 case Opt_soft:
643 mnt->flags |= NFS_MOUNT_SOFT;
644 break;
645 case Opt_hard:
646 mnt->flags &= ~NFS_MOUNT_SOFT;
647 break;
648 case Opt_intr:
649 mnt->flags |= NFS_MOUNT_INTR;
650 break;
651 case Opt_nointr:
652 mnt->flags &= ~NFS_MOUNT_INTR;
653 break;
654 case Opt_posix:
655 mnt->flags |= NFS_MOUNT_POSIX;
656 break;
657 case Opt_noposix:
658 mnt->flags &= ~NFS_MOUNT_POSIX;
659 break;
660 case Opt_cto:
661 mnt->flags &= ~NFS_MOUNT_NOCTO;
662 break;
663 case Opt_nocto:
664 mnt->flags |= NFS_MOUNT_NOCTO;
665 break;
666 case Opt_ac:
667 mnt->flags &= ~NFS_MOUNT_NOAC;
668 break;
669 case Opt_noac:
670 mnt->flags |= NFS_MOUNT_NOAC;
671 break;
672 case Opt_lock:
673 mnt->flags &= ~NFS_MOUNT_NONLM;
674 break;
675 case Opt_nolock:
676 mnt->flags |= NFS_MOUNT_NONLM;
677 break;
678 case Opt_v2:
679 mnt->flags &= ~NFS_MOUNT_VER3;
680 break;
681 case Opt_v3:
682 mnt->flags |= NFS_MOUNT_VER3;
683 break;
684 case Opt_udp:
685 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400686 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400687 mnt->timeo = 7;
688 mnt->retrans = 5;
689 break;
690 case Opt_tcp:
691 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400692 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400693 mnt->timeo = 600;
694 mnt->retrans = 2;
695 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400696 case Opt_rdma:
697 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
698 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
699 mnt->timeo = 600;
700 mnt->retrans = 2;
701 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400702 case Opt_acl:
703 mnt->flags &= ~NFS_MOUNT_NOACL;
704 break;
705 case Opt_noacl:
706 mnt->flags |= NFS_MOUNT_NOACL;
707 break;
708 case Opt_rdirplus:
709 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
710 break;
711 case Opt_nordirplus:
712 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
713 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400714 case Opt_sharecache:
715 mnt->flags &= ~NFS_MOUNT_UNSHARED;
716 break;
717 case Opt_nosharecache:
718 mnt->flags |= NFS_MOUNT_UNSHARED;
719 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400720
721 case Opt_port:
722 if (match_int(args, &option))
723 return 0;
724 if (option < 0 || option > 65535)
725 return 0;
Al Viro410896442007-07-22 10:59:06 +0100726 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400727 break;
728 case Opt_rsize:
729 if (match_int(args, &mnt->rsize))
730 return 0;
731 break;
732 case Opt_wsize:
733 if (match_int(args, &mnt->wsize))
734 return 0;
735 break;
736 case Opt_bsize:
737 if (match_int(args, &option))
738 return 0;
739 if (option < 0)
740 return 0;
741 mnt->bsize = option;
742 break;
743 case Opt_timeo:
744 if (match_int(args, &mnt->timeo))
745 return 0;
746 break;
747 case Opt_retrans:
748 if (match_int(args, &mnt->retrans))
749 return 0;
750 break;
751 case Opt_acregmin:
752 if (match_int(args, &mnt->acregmin))
753 return 0;
754 break;
755 case Opt_acregmax:
756 if (match_int(args, &mnt->acregmax))
757 return 0;
758 break;
759 case Opt_acdirmin:
760 if (match_int(args, &mnt->acdirmin))
761 return 0;
762 break;
763 case Opt_acdirmax:
764 if (match_int(args, &mnt->acdirmax))
765 return 0;
766 break;
767 case Opt_actimeo:
768 if (match_int(args, &option))
769 return 0;
770 if (option < 0)
771 return 0;
772 mnt->acregmin =
773 mnt->acregmax =
774 mnt->acdirmin =
775 mnt->acdirmax = option;
776 break;
777 case Opt_namelen:
778 if (match_int(args, &mnt->namlen))
779 return 0;
780 break;
781 case Opt_mountport:
782 if (match_int(args, &option))
783 return 0;
784 if (option < 0 || option > 65535)
785 return 0;
786 mnt->mount_server.port = option;
787 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400788 case Opt_mountvers:
789 if (match_int(args, &option))
790 return 0;
791 if (option < 0)
792 return 0;
793 mnt->mount_server.version = option;
794 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400795 case Opt_nfsvers:
796 if (match_int(args, &option))
797 return 0;
798 switch (option) {
799 case 2:
800 mnt->flags &= ~NFS_MOUNT_VER3;
801 break;
802 case 3:
803 mnt->flags |= NFS_MOUNT_VER3;
804 break;
805 default:
806 goto out_unrec_vers;
807 }
808 break;
809
810 case Opt_sec:
811 string = match_strdup(args);
812 if (string == NULL)
813 goto out_nomem;
814 token = match_token(string, nfs_secflavor_tokens, args);
815 kfree(string);
816
817 /*
818 * The flags setting is for v2/v3. The flavor_len
819 * setting is for v4. v2/v3 also need to know the
820 * difference between NULL and UNIX.
821 */
822 switch (token) {
823 case Opt_sec_none:
824 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
825 mnt->auth_flavor_len = 0;
826 mnt->auth_flavors[0] = RPC_AUTH_NULL;
827 break;
828 case Opt_sec_sys:
829 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
830 mnt->auth_flavor_len = 0;
831 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
832 break;
833 case Opt_sec_krb5:
834 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
835 mnt->auth_flavor_len = 1;
836 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
837 break;
838 case Opt_sec_krb5i:
839 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
840 mnt->auth_flavor_len = 1;
841 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
842 break;
843 case Opt_sec_krb5p:
844 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
845 mnt->auth_flavor_len = 1;
846 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
847 break;
848 case Opt_sec_lkey:
849 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
850 mnt->auth_flavor_len = 1;
851 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
852 break;
853 case Opt_sec_lkeyi:
854 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
855 mnt->auth_flavor_len = 1;
856 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
857 break;
858 case Opt_sec_lkeyp:
859 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
860 mnt->auth_flavor_len = 1;
861 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
862 break;
863 case Opt_sec_spkm:
864 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
865 mnt->auth_flavor_len = 1;
866 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
867 break;
868 case Opt_sec_spkmi:
869 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
870 mnt->auth_flavor_len = 1;
871 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
872 break;
873 case Opt_sec_spkmp:
874 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
875 mnt->auth_flavor_len = 1;
876 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
877 break;
878 default:
879 goto out_unrec_sec;
880 }
881 break;
882 case Opt_proto:
883 string = match_strdup(args);
884 if (string == NULL)
885 goto out_nomem;
886 token = match_token(string,
887 nfs_xprt_protocol_tokens, args);
888 kfree(string);
889
890 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400891 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400892 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400893 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400894 mnt->timeo = 7;
895 mnt->retrans = 5;
896 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400897 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400898 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400899 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400900 mnt->timeo = 600;
901 mnt->retrans = 2;
902 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400903 case Opt_xprt_rdma:
904 /* vector side protocols to TCP */
905 mnt->flags |= NFS_MOUNT_TCP;
906 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
907 mnt->timeo = 600;
908 mnt->retrans = 2;
909 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400910 default:
911 goto out_unrec_xprt;
912 }
913 break;
914 case Opt_mountproto:
915 string = match_strdup(args);
916 if (string == NULL)
917 goto out_nomem;
918 token = match_token(string,
919 nfs_xprt_protocol_tokens, args);
920 kfree(string);
921
922 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400923 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400924 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400925 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400926 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400927 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400928 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400929 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400930 default:
931 goto out_unrec_xprt;
932 }
933 break;
934 case Opt_addr:
935 string = match_strdup(args);
936 if (string == NULL)
937 goto out_nomem;
938 mnt->nfs_server.address.sin_family = AF_INET;
939 mnt->nfs_server.address.sin_addr.s_addr =
940 in_aton(string);
941 kfree(string);
942 break;
943 case Opt_clientaddr:
944 string = match_strdup(args);
945 if (string == NULL)
946 goto out_nomem;
947 mnt->client_address = string;
948 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400949 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950 string = match_strdup(args);
951 if (string == NULL)
952 goto out_nomem;
953 mnt->mount_server.address.sin_family = AF_INET;
954 mnt->mount_server.address.sin_addr.s_addr =
955 in_aton(string);
956 kfree(string);
957 break;
958
959 case Opt_userspace:
960 case Opt_deprecated:
961 break;
962
963 default:
964 goto out_unknown;
965 }
966 }
967
968 return 1;
969
970out_nomem:
971 printk(KERN_INFO "NFS: not enough memory to parse option\n");
972 return 0;
973
974out_unrec_vers:
975 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
976 return 0;
977
978out_unrec_xprt:
979 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
980 return 0;
981
982out_unrec_sec:
983 printk(KERN_INFO "NFS: unrecognized security flavor\n");
984 return 0;
985
986out_unknown:
987 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
988 return 0;
989}
990
991/*
Chuck Lever0076d7b2007-07-01 12:13:49 -0400992 * Use the remote server's MOUNT service to request the NFS file handle
993 * corresponding to the provided path.
994 */
995static int nfs_try_mount(struct nfs_parsed_mount_data *args,
996 struct nfs_fh *root_fh)
997{
998 struct sockaddr_in sin;
999 int status;
1000
1001 if (args->mount_server.version == 0) {
1002 if (args->flags & NFS_MOUNT_VER3)
1003 args->mount_server.version = NFS_MNT3_VERSION;
1004 else
1005 args->mount_server.version = NFS_MNT_VERSION;
1006 }
1007
1008 /*
1009 * Construct the mount server's address.
1010 */
1011 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1012 sin = args->mount_server.address;
1013 else
1014 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001015 /*
1016 * autobind will be used if mount_server.port == 0
1017 */
1018 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001019
1020 /*
1021 * Now ask the mount server to map our export path
1022 * to a file handle.
1023 */
1024 status = nfs_mount((struct sockaddr *) &sin,
1025 sizeof(sin),
1026 args->nfs_server.hostname,
1027 args->nfs_server.export_path,
1028 args->mount_server.version,
1029 args->mount_server.protocol,
1030 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001031 if (status == 0)
1032 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001033
Chuck Leverefd83402007-09-11 18:00:58 -04001034 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1035 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001036 return status;
1037}
1038
1039/*
David Howells54ceac42006-08-22 20:06:13 -04001040 * Validate the NFS2/NFS3 mount data
1041 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001042 *
1043 * For option strings, user space handles the following behaviors:
1044 *
1045 * + DNS: mapping server host name to IP address ("addr=" option)
1046 *
1047 * + failure mode: how to behave if a mount request can't be handled
1048 * immediately ("fg/bg" option)
1049 *
1050 * + retry: how often to retry a mount request ("retry=" option)
1051 *
1052 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1053 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001054 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001055static int nfs_validate_mount_data(void *options,
1056 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001057 struct nfs_fh *mntfh,
1058 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001059{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001060 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001061
Russell Kingf16c9602007-11-16 22:13:24 +00001062 memset(args, 0, sizeof(*args));
1063
Chuck Lever5df36e72007-07-01 12:12:56 -04001064 if (data == NULL)
1065 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001066
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001067 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1068 args->rsize = NFS_MAX_FILE_IO_SIZE;
1069 args->wsize = NFS_MAX_FILE_IO_SIZE;
1070 args->timeo = 600;
1071 args->retrans = 2;
1072 args->acregmin = 3;
1073 args->acregmax = 60;
1074 args->acdirmin = 30;
1075 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001076 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001077 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001078
David Howellsf7b422b2006-06-09 09:34:33 -04001079 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001080 case 1:
1081 data->namlen = 0;
1082 case 2:
1083 data->bsize = 0;
1084 case 3:
1085 if (data->flags & NFS_MOUNT_VER3)
1086 goto out_no_v3;
1087 data->root.size = NFS2_FHSIZE;
1088 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1089 case 4:
1090 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1091 goto out_no_sec;
1092 case 5:
1093 memset(data->context, 0, sizeof(data->context));
1094 case 6:
1095 if (data->flags & NFS_MOUNT_VER3)
1096 mntfh->size = data->root.size;
1097 else
1098 mntfh->size = NFS2_FHSIZE;
1099
1100 if (mntfh->size > sizeof(mntfh->data))
1101 goto out_invalid_fh;
1102
1103 memcpy(mntfh->data, data->root.data, mntfh->size);
1104 if (mntfh->size < sizeof(mntfh->data))
1105 memset(mntfh->data + mntfh->size, 0,
1106 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001107
1108 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1109 goto out_no_address;
1110
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001111 /*
1112 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1113 * can deal with.
1114 */
1115 args->flags = data->flags;
1116 args->rsize = data->rsize;
1117 args->wsize = data->wsize;
1118 args->flags = data->flags;
1119 args->timeo = data->timeo;
1120 args->retrans = data->retrans;
1121 args->acregmin = data->acregmin;
1122 args->acregmax = data->acregmax;
1123 args->acdirmin = data->acdirmin;
1124 args->acdirmax = data->acdirmax;
1125 args->nfs_server.address = data->addr;
1126 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001127 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001128 /* N.B. caller will free nfs_server.hostname in all cases */
1129 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1130 args->namlen = data->namlen;
1131 args->bsize = data->bsize;
1132 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001133 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001134 default: {
1135 unsigned int len;
1136 char *c;
1137 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001138
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001139 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001140 return -EINVAL;
1141
Chuck Lever6e88e062007-09-24 15:39:50 -04001142 if (!nfs_verify_server_address((struct sockaddr *)
1143 &args->nfs_server.address))
1144 goto out_no_address;
1145
Chuck Lever136d5582007-07-01 12:13:54 -04001146 c = strchr(dev_name, ':');
1147 if (c == NULL)
1148 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001149 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001150 /* N.B. caller will free nfs_server.hostname in all cases */
1151 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001152
1153 c++;
1154 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001155 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001156 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001157
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001158 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001159 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001160 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001161
Chuck Lever136d5582007-07-01 12:13:54 -04001162 break;
1163 }
David Howellsf7b422b2006-06-09 09:34:33 -04001164 }
David Howells54ceac42006-08-22 20:06:13 -04001165
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001166 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1167 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001168
David Howellsf7b422b2006-06-09 09:34:33 -04001169#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001170 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001171 goto out_v3_not_compiled;
1172#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001173
David Howells54ceac42006-08-22 20:06:13 -04001174 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001175
1176out_no_data:
1177 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1178 return -EINVAL;
1179
1180out_no_v3:
1181 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1182 data->version);
1183 return -EINVAL;
1184
1185out_no_sec:
1186 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1187 return -EINVAL;
1188
Chuck Lever5df36e72007-07-01 12:12:56 -04001189#ifndef CONFIG_NFS_V3
1190out_v3_not_compiled:
1191 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1192 return -EPROTONOSUPPORT;
1193#endif /* !CONFIG_NFS_V3 */
1194
1195out_no_address:
1196 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1197 return -EINVAL;
1198
1199out_invalid_fh:
1200 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1201 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001202}
1203
1204/*
1205 * Initialise the common bits of the superblock
1206 */
1207static inline void nfs_initialise_sb(struct super_block *sb)
1208{
1209 struct nfs_server *server = NFS_SB(sb);
1210
1211 sb->s_magic = NFS_SUPER_MAGIC;
1212
1213 /* We probably want something more informative here */
1214 snprintf(sb->s_id, sizeof(sb->s_id),
1215 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1216
1217 if (sb->s_blocksize == 0)
1218 sb->s_blocksize = nfs_block_bits(server->wsize,
1219 &sb->s_blocksize_bits);
1220
1221 if (server->flags & NFS_MOUNT_NOAC)
1222 sb->s_flags |= MS_SYNCHRONOUS;
1223
1224 nfs_super_set_maxbytes(sb, server->maxfilesize);
1225}
1226
1227/*
1228 * Finish setting up an NFS2/3 superblock
1229 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001230static void nfs_fill_super(struct super_block *sb,
1231 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001232{
1233 struct nfs_server *server = NFS_SB(sb);
1234
1235 sb->s_blocksize_bits = 0;
1236 sb->s_blocksize = 0;
1237 if (data->bsize)
1238 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1239
1240 if (server->flags & NFS_MOUNT_VER3) {
1241 /* The VFS shouldn't apply the umask to mode bits. We will do
1242 * so ourselves when necessary.
1243 */
1244 sb->s_flags |= MS_POSIXACL;
1245 sb->s_time_gran = 1;
1246 }
1247
1248 sb->s_op = &nfs_sops;
1249 nfs_initialise_sb(sb);
1250}
1251
1252/*
1253 * Finish setting up a cloned NFS2/3 superblock
1254 */
1255static void nfs_clone_super(struct super_block *sb,
1256 const struct super_block *old_sb)
1257{
1258 struct nfs_server *server = NFS_SB(sb);
1259
1260 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1261 sb->s_blocksize = old_sb->s_blocksize;
1262 sb->s_maxbytes = old_sb->s_maxbytes;
1263
1264 if (server->flags & NFS_MOUNT_VER3) {
1265 /* The VFS shouldn't apply the umask to mode bits. We will do
1266 * so ourselves when necessary.
1267 */
1268 sb->s_flags |= MS_POSIXACL;
1269 sb->s_time_gran = 1;
1270 }
1271
1272 sb->s_op = old_sb->s_op;
1273 nfs_initialise_sb(sb);
1274}
1275
Trond Myklebust275a5d22007-05-16 16:53:28 -04001276#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1277
1278static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1279{
1280 const struct nfs_server *a = s->s_fs_info;
1281 const struct rpc_clnt *clnt_a = a->client;
1282 const struct rpc_clnt *clnt_b = b->client;
1283
1284 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1285 goto Ebusy;
1286 if (a->nfs_client != b->nfs_client)
1287 goto Ebusy;
1288 if (a->flags != b->flags)
1289 goto Ebusy;
1290 if (a->wsize != b->wsize)
1291 goto Ebusy;
1292 if (a->rsize != b->rsize)
1293 goto Ebusy;
1294 if (a->acregmin != b->acregmin)
1295 goto Ebusy;
1296 if (a->acregmax != b->acregmax)
1297 goto Ebusy;
1298 if (a->acdirmin != b->acdirmin)
1299 goto Ebusy;
1300 if (a->acdirmax != b->acdirmax)
1301 goto Ebusy;
1302 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1303 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001304 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001305Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001306 return 0;
1307}
1308
1309struct nfs_sb_mountdata {
1310 struct nfs_server *server;
1311 int mntflags;
1312};
1313
1314static int nfs_set_super(struct super_block *s, void *data)
1315{
1316 struct nfs_sb_mountdata *sb_mntdata = data;
1317 struct nfs_server *server = sb_mntdata->server;
1318 int ret;
1319
1320 s->s_flags = sb_mntdata->mntflags;
1321 s->s_fs_info = server;
1322 ret = set_anon_super(s, server);
1323 if (ret == 0)
1324 server->s_dev = s->s_dev;
1325 return ret;
1326}
1327
1328static int nfs_compare_super(struct super_block *sb, void *data)
1329{
1330 struct nfs_sb_mountdata *sb_mntdata = data;
1331 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1332 int mntflags = sb_mntdata->mntflags;
1333
1334 if (memcmp(&old->nfs_client->cl_addr,
1335 &server->nfs_client->cl_addr,
1336 sizeof(old->nfs_client->cl_addr)) != 0)
1337 return 0;
1338 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1339 if (old->flags & NFS_MOUNT_UNSHARED)
1340 return 0;
1341 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1342 return 0;
1343 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001344}
1345
David Howells54ceac42006-08-22 20:06:13 -04001346static int nfs_get_sb(struct file_system_type *fs_type,
1347 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1348{
1349 struct nfs_server *server = NULL;
1350 struct super_block *s;
1351 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001352 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001353 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001354 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001355 struct nfs_sb_mountdata sb_mntdata = {
1356 .mntflags = flags,
1357 };
David Howells54ceac42006-08-22 20:06:13 -04001358 int error;
1359
1360 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001361 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001362 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001363 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001364
1365 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001366 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001367 if (IS_ERR(server)) {
1368 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001369 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001370 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001371 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001372
Trond Myklebust75180df2007-05-16 16:53:28 -04001373 if (server->flags & NFS_MOUNT_UNSHARED)
1374 compare_super = NULL;
1375
David Howells54ceac42006-08-22 20:06:13 -04001376 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001377 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001378 if (IS_ERR(s)) {
1379 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001380 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001381 }
1382
David Howells54ceac42006-08-22 20:06:13 -04001383 if (s->s_fs_info != server) {
1384 nfs_free_server(server);
1385 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001386 }
David Howells54ceac42006-08-22 20:06:13 -04001387
1388 if (!s->s_root) {
1389 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001390 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001391 }
1392
1393 mntroot = nfs_get_root(s, &mntfh);
1394 if (IS_ERR(mntroot)) {
1395 error = PTR_ERR(mntroot);
1396 goto error_splat_super;
1397 }
1398
David Howellsf7b422b2006-06-09 09:34:33 -04001399 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001400 mnt->mnt_sb = s;
1401 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001402 error = 0;
1403
1404out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001405 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001406 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001407
David Howells54ceac42006-08-22 20:06:13 -04001408out_err_nosb:
1409 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001410 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001411
1412error_splat_super:
1413 up_write(&s->s_umount);
1414 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001415 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001416}
1417
David Howells54ceac42006-08-22 20:06:13 -04001418/*
1419 * Destroy an NFS2/3 superblock
1420 */
David Howellsf7b422b2006-06-09 09:34:33 -04001421static void nfs_kill_super(struct super_block *s)
1422{
1423 struct nfs_server *server = NFS_SB(s);
1424
1425 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001426 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001427}
1428
David Howells54ceac42006-08-22 20:06:13 -04001429/*
1430 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1431 */
1432static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1433 const char *dev_name, void *raw_data,
1434 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001435{
1436 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001437 struct super_block *s;
1438 struct nfs_server *server;
1439 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001440 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001441 struct nfs_sb_mountdata sb_mntdata = {
1442 .mntflags = flags,
1443 };
David Howells54ceac42006-08-22 20:06:13 -04001444 int error;
1445
1446 dprintk("--> nfs_xdev_get_sb()\n");
1447
1448 /* create a new volume representation */
1449 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1450 if (IS_ERR(server)) {
1451 error = PTR_ERR(server);
1452 goto out_err_noserver;
1453 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001454 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001455
Trond Myklebust75180df2007-05-16 16:53:28 -04001456 if (server->flags & NFS_MOUNT_UNSHARED)
1457 compare_super = NULL;
1458
David Howells54ceac42006-08-22 20:06:13 -04001459 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001460 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001461 if (IS_ERR(s)) {
1462 error = PTR_ERR(s);
1463 goto out_err_nosb;
1464 }
1465
1466 if (s->s_fs_info != server) {
1467 nfs_free_server(server);
1468 server = NULL;
1469 }
1470
1471 if (!s->s_root) {
1472 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001473 nfs_clone_super(s, data->sb);
1474 }
1475
1476 mntroot = nfs_get_root(s, data->fh);
1477 if (IS_ERR(mntroot)) {
1478 error = PTR_ERR(mntroot);
1479 goto error_splat_super;
1480 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001481 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001482 dput(mntroot);
1483 error = -ESTALE;
1484 goto error_splat_super;
1485 }
David Howells54ceac42006-08-22 20:06:13 -04001486
1487 s->s_flags |= MS_ACTIVE;
1488 mnt->mnt_sb = s;
1489 mnt->mnt_root = mntroot;
1490
1491 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1492 return 0;
1493
1494out_err_nosb:
1495 nfs_free_server(server);
1496out_err_noserver:
1497 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1498 return error;
1499
1500error_splat_super:
1501 up_write(&s->s_umount);
1502 deactivate_super(s);
1503 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1504 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001505}
1506
1507#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001508
1509/*
1510 * Finish setting up a cloned NFS4 superblock
1511 */
1512static void nfs4_clone_super(struct super_block *sb,
1513 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001514{
David Howells54ceac42006-08-22 20:06:13 -04001515 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1516 sb->s_blocksize = old_sb->s_blocksize;
1517 sb->s_maxbytes = old_sb->s_maxbytes;
1518 sb->s_time_gran = 1;
1519 sb->s_op = old_sb->s_op;
1520 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001521}
1522
1523/*
1524 * Set up an NFS4 superblock
1525 */
David Howells54ceac42006-08-22 20:06:13 -04001526static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001527{
David Howellsf7b422b2006-06-09 09:34:33 -04001528 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001529 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001530 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001531}
1532
David Howells54ceac42006-08-22 20:06:13 -04001533/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001534 * Validate NFSv4 mount options
1535 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001536static int nfs4_validate_mount_data(void *options,
1537 struct nfs_parsed_mount_data *args,
1538 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001539{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001540 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001541 char *c;
1542
Russell Kingf16c9602007-11-16 22:13:24 +00001543 memset(args, 0, sizeof(*args));
1544
Chuck Leverf0768eb2007-07-01 12:13:01 -04001545 if (data == NULL)
1546 goto out_no_data;
1547
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001548 args->rsize = NFS_MAX_FILE_IO_SIZE;
1549 args->wsize = NFS_MAX_FILE_IO_SIZE;
1550 args->timeo = 600;
1551 args->retrans = 2;
1552 args->acregmin = 3;
1553 args->acregmax = 60;
1554 args->acdirmin = 30;
1555 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001556 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001557
Chuck Leverf0768eb2007-07-01 12:13:01 -04001558 switch (data->version) {
1559 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001560 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001561 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001562 if (copy_from_user(&args->nfs_server.address,
1563 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001564 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001565 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001566 if (args->nfs_server.address.sin_port == 0)
1567 args->nfs_server.address.sin_port = htons(NFS_PORT);
1568 if (!nfs_verify_server_address((struct sockaddr *)
1569 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001570 goto out_no_address;
1571
1572 switch (data->auth_flavourlen) {
1573 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001574 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001575 break;
1576 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001577 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001578 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001579 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001580 return -EFAULT;
1581 break;
1582 default:
1583 goto out_inval_auth;
1584 }
1585
1586 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1587 if (IS_ERR(c))
1588 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001589 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001590
1591 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1592 if (IS_ERR(c))
1593 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001594 args->nfs_server.export_path = c;
1595 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001596
1597 c = strndup_user(data->client_addr.data, 16);
1598 if (IS_ERR(c))
1599 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001600 args->client_address = c;
1601
1602 /*
1603 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1604 * can deal with.
1605 */
1606
1607 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1608 args->rsize = data->rsize;
1609 args->wsize = data->wsize;
1610 args->timeo = data->timeo;
1611 args->retrans = data->retrans;
1612 args->acregmin = data->acregmin;
1613 args->acregmax = data->acregmax;
1614 args->acdirmin = data->acdirmin;
1615 args->acdirmax = data->acdirmax;
1616 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001617
1618 break;
Chuck Lever80071222007-07-01 12:13:59 -04001619 default: {
1620 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001621
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001622 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001623 return -EINVAL;
1624
Chuck Lever0eb25742007-10-26 13:32:19 -04001625 if (args->nfs_server.address.sin_port == 0)
1626 args->nfs_server.address.sin_port = htons(NFS_PORT);
Chuck Lever80071222007-07-01 12:13:59 -04001627 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001628 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001629 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001630
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001631 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001632 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001633 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001634 break;
1635 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001636 break;
1637 default:
1638 goto out_inval_auth;
1639 }
1640
1641 /*
Chuck Lever80071222007-07-01 12:13:59 -04001642 * Split "dev_name" into "hostname:mntpath".
1643 */
1644 c = strchr(dev_name, ':');
1645 if (c == NULL)
1646 return -EINVAL;
1647 /* while calculating len, pretend ':' is '\0' */
1648 len = c - dev_name;
1649 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001650 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001651 /* N.B. caller will free nfs_server.hostname in all cases */
1652 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001653
1654 c++; /* step over the ':' */
1655 len = strlen(c);
1656 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001657 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001658 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001659
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001660 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001661
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001662 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001663 goto out_no_client_address;
1664
Chuck Lever80071222007-07-01 12:13:59 -04001665 break;
1666 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001667 }
1668
1669 return 0;
1670
1671out_no_data:
1672 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1673 return -EINVAL;
1674
1675out_inval_auth:
1676 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1677 data->auth_flavourlen);
1678 return -EINVAL;
1679
1680out_no_address:
1681 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1682 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001683
1684out_no_client_address:
1685 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1686 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001687}
1688
1689/*
David Howells54ceac42006-08-22 20:06:13 -04001690 * Get the superblock for an NFS4 mountpoint
1691 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001692static int nfs4_get_sb(struct file_system_type *fs_type,
1693 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001694{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001695 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001696 struct super_block *s;
1697 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001698 struct nfs_fh mntfh;
1699 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001700 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001701 struct nfs_sb_mountdata sb_mntdata = {
1702 .mntflags = flags,
1703 };
David Howells54ceac42006-08-22 20:06:13 -04001704 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001705
Chuck Leverf0768eb2007-07-01 12:13:01 -04001706 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001707 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001708 if (error < 0)
1709 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001710
David Howells54ceac42006-08-22 20:06:13 -04001711 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001712 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001713 if (IS_ERR(server)) {
1714 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001715 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001716 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001717 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001718
Trond Myklebust75180df2007-05-16 16:53:28 -04001719 if (server->flags & NFS4_MOUNT_UNSHARED)
1720 compare_super = NULL;
1721
David Howells54ceac42006-08-22 20:06:13 -04001722 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001723 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001724 if (IS_ERR(s)) {
1725 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001726 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001727 }
1728
Trond Myklebust5dd31772006-08-24 01:03:05 -04001729 if (s->s_fs_info != server) {
1730 nfs_free_server(server);
1731 server = NULL;
1732 }
1733
David Howells54ceac42006-08-22 20:06:13 -04001734 if (!s->s_root) {
1735 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001736 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001737 }
David Howellsf7b422b2006-06-09 09:34:33 -04001738
David Howells54ceac42006-08-22 20:06:13 -04001739 mntroot = nfs4_get_root(s, &mntfh);
1740 if (IS_ERR(mntroot)) {
1741 error = PTR_ERR(mntroot);
1742 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001743 }
David Howells54ceac42006-08-22 20:06:13 -04001744
David Howellsf7b422b2006-06-09 09:34:33 -04001745 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001746 mnt->mnt_sb = s;
1747 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001748 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001749
Chuck Lever29eb9812007-07-01 12:12:30 -04001750out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001751 kfree(data.client_address);
1752 kfree(data.nfs_server.export_path);
1753 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001754 return error;
David Howells54ceac42006-08-22 20:06:13 -04001755
Chuck Lever29eb9812007-07-01 12:12:30 -04001756out_free:
1757 nfs_free_server(server);
1758 goto out;
1759
David Howells54ceac42006-08-22 20:06:13 -04001760error_splat_super:
1761 up_write(&s->s_umount);
1762 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001763 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001764}
1765
1766static void nfs4_kill_super(struct super_block *sb)
1767{
1768 struct nfs_server *server = NFS_SB(sb);
1769
1770 nfs_return_all_delegations(sb);
1771 kill_anon_super(sb);
1772
1773 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001774 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001775}
1776
1777/*
David Howells54ceac42006-08-22 20:06:13 -04001778 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001779 */
David Howells54ceac42006-08-22 20:06:13 -04001780static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1781 const char *dev_name, void *raw_data,
1782 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001783{
1784 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001785 struct super_block *s;
1786 struct nfs_server *server;
1787 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001788 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001789 struct nfs_sb_mountdata sb_mntdata = {
1790 .mntflags = flags,
1791 };
David Howells54ceac42006-08-22 20:06:13 -04001792 int error;
1793
1794 dprintk("--> nfs4_xdev_get_sb()\n");
1795
1796 /* create a new volume representation */
1797 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1798 if (IS_ERR(server)) {
1799 error = PTR_ERR(server);
1800 goto out_err_noserver;
1801 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001802 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001803
Trond Myklebust75180df2007-05-16 16:53:28 -04001804 if (server->flags & NFS4_MOUNT_UNSHARED)
1805 compare_super = NULL;
1806
David Howells54ceac42006-08-22 20:06:13 -04001807 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001808 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001809 if (IS_ERR(s)) {
1810 error = PTR_ERR(s);
1811 goto out_err_nosb;
1812 }
1813
1814 if (s->s_fs_info != server) {
1815 nfs_free_server(server);
1816 server = NULL;
1817 }
1818
1819 if (!s->s_root) {
1820 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001821 nfs4_clone_super(s, data->sb);
1822 }
1823
1824 mntroot = nfs4_get_root(s, data->fh);
1825 if (IS_ERR(mntroot)) {
1826 error = PTR_ERR(mntroot);
1827 goto error_splat_super;
1828 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001829 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1830 dput(mntroot);
1831 error = -ESTALE;
1832 goto error_splat_super;
1833 }
David Howells54ceac42006-08-22 20:06:13 -04001834
1835 s->s_flags |= MS_ACTIVE;
1836 mnt->mnt_sb = s;
1837 mnt->mnt_root = mntroot;
1838
1839 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1840 return 0;
1841
1842out_err_nosb:
1843 nfs_free_server(server);
1844out_err_noserver:
1845 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1846 return error;
1847
1848error_splat_super:
1849 up_write(&s->s_umount);
1850 deactivate_super(s);
1851 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1852 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001853}
1854
David Howells54ceac42006-08-22 20:06:13 -04001855/*
1856 * Create an NFS4 server record on referral traversal
1857 */
1858static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1859 const char *dev_name, void *raw_data,
1860 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001861{
1862 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001863 struct super_block *s;
1864 struct nfs_server *server;
1865 struct dentry *mntroot;
1866 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001867 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001868 struct nfs_sb_mountdata sb_mntdata = {
1869 .mntflags = flags,
1870 };
David Howells54ceac42006-08-22 20:06:13 -04001871 int error;
1872
1873 dprintk("--> nfs4_referral_get_sb()\n");
1874
1875 /* create a new volume representation */
1876 server = nfs4_create_referral_server(data, &mntfh);
1877 if (IS_ERR(server)) {
1878 error = PTR_ERR(server);
1879 goto out_err_noserver;
1880 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001881 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001882
Trond Myklebust75180df2007-05-16 16:53:28 -04001883 if (server->flags & NFS4_MOUNT_UNSHARED)
1884 compare_super = NULL;
1885
David Howells54ceac42006-08-22 20:06:13 -04001886 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001887 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001888 if (IS_ERR(s)) {
1889 error = PTR_ERR(s);
1890 goto out_err_nosb;
1891 }
1892
1893 if (s->s_fs_info != server) {
1894 nfs_free_server(server);
1895 server = NULL;
1896 }
1897
1898 if (!s->s_root) {
1899 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001900 nfs4_fill_super(s);
1901 }
1902
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001903 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001904 if (IS_ERR(mntroot)) {
1905 error = PTR_ERR(mntroot);
1906 goto error_splat_super;
1907 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001908 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1909 dput(mntroot);
1910 error = -ESTALE;
1911 goto error_splat_super;
1912 }
David Howells54ceac42006-08-22 20:06:13 -04001913
1914 s->s_flags |= MS_ACTIVE;
1915 mnt->mnt_sb = s;
1916 mnt->mnt_root = mntroot;
1917
1918 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1919 return 0;
1920
1921out_err_nosb:
1922 nfs_free_server(server);
1923out_err_noserver:
1924 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1925 return error;
1926
1927error_splat_super:
1928 up_write(&s->s_umount);
1929 deactivate_super(s);
1930 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1931 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001932}
1933
David Howells54ceac42006-08-22 20:06:13 -04001934#endif /* CONFIG_NFS_V4 */