blob: 1a18ca390ddfe15a7077c014c7b45ca6bad30541 [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,
86 Opt_mountprog, 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" },
140 { Opt_mountprog, "mountprog=%u" },
141 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_nfsvers, "nfsvers=%u" },
143 { Opt_nfsvers, "vers=%u" },
144
145 { Opt_sec, "sec=%s" },
146 { Opt_proto, "proto=%s" },
147 { Opt_mountproto, "mountproto=%s" },
148 { Opt_addr, "addr=%s" },
149 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400150 { Opt_userspace, "mounthost=%s" },
151 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400152
153 { Opt_err, NULL }
154};
155
156enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400157 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400158
159 Opt_xprt_err
160};
161
162static match_table_t nfs_xprt_protocol_tokens = {
163 { Opt_xprt_udp, "udp" },
164 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400165 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400166
167 { Opt_xprt_err, NULL }
168};
169
170enum {
171 Opt_sec_none, Opt_sec_sys,
172 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
173 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
174 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
175
176 Opt_sec_err
177};
178
179static match_table_t nfs_secflavor_tokens = {
180 { Opt_sec_none, "none" },
181 { Opt_sec_none, "null" },
182 { Opt_sec_sys, "sys" },
183
184 { Opt_sec_krb5, "krb5" },
185 { Opt_sec_krb5i, "krb5i" },
186 { Opt_sec_krb5p, "krb5p" },
187
188 { Opt_sec_lkey, "lkey" },
189 { Opt_sec_lkeyi, "lkeyi" },
190 { Opt_sec_lkeyp, "lkeyp" },
191
192 { Opt_sec_err, NULL }
193};
194
195
David Howellsf7b422b2006-06-09 09:34:33 -0400196static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400197static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400198static int nfs_show_options(struct seq_file *, struct vfsmount *);
199static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400200static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400201static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400202 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400203static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500204static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400205
206static struct file_system_type nfs_fs_type = {
207 .owner = THIS_MODULE,
208 .name = "nfs",
209 .get_sb = nfs_get_sb,
210 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700211 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400212};
213
David Howells54ceac42006-08-22 20:06:13 -0400214struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400215 .owner = THIS_MODULE,
216 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400217 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400218 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700219 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400220};
221
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800222static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400223 .alloc_inode = nfs_alloc_inode,
224 .destroy_inode = nfs_destroy_inode,
225 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500226 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400227 .statfs = nfs_statfs,
228 .clear_inode = nfs_clear_inode,
229 .umount_begin = nfs_umount_begin,
230 .show_options = nfs_show_options,
231 .show_stats = nfs_show_stats,
232};
233
234#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400235static int nfs4_get_sb(struct file_system_type *fs_type,
236 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400237static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
238 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
239static int nfs4_referral_get_sb(struct file_system_type *fs_type,
240 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400241static void nfs4_kill_super(struct super_block *sb);
242
243static struct file_system_type nfs4_fs_type = {
244 .owner = THIS_MODULE,
245 .name = "nfs4",
246 .get_sb = nfs4_get_sb,
247 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700248 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400249};
250
David Howells54ceac42006-08-22 20:06:13 -0400251struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400252 .owner = THIS_MODULE,
253 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400254 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400255 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400257};
258
David Howells54ceac42006-08-22 20:06:13 -0400259struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400260 .owner = THIS_MODULE,
261 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400262 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400265};
266
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800267static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400268 .alloc_inode = nfs_alloc_inode,
269 .destroy_inode = nfs_destroy_inode,
270 .write_inode = nfs_write_inode,
271 .statfs = nfs_statfs,
272 .clear_inode = nfs4_clear_inode,
273 .umount_begin = nfs_umount_begin,
274 .show_options = nfs_show_options,
275 .show_stats = nfs_show_stats,
276};
277#endif
278
Rusty Russell8e1f9362007-07-17 04:03:17 -0700279static struct shrinker acl_shrinker = {
280 .shrink = nfs_access_cache_shrinker,
281 .seeks = DEFAULT_SEEKS,
282};
Trond Myklebust979df722006-07-25 11:28:19 -0400283
David Howellsf7b422b2006-06-09 09:34:33 -0400284/*
285 * Register the NFS filesystems
286 */
287int __init register_nfs_fs(void)
288{
289 int ret;
290
291 ret = register_filesystem(&nfs_fs_type);
292 if (ret < 0)
293 goto error_0;
294
David Howellsf7b422b2006-06-09 09:34:33 -0400295 ret = nfs_register_sysctl();
296 if (ret < 0)
297 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800298#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400299 ret = register_filesystem(&nfs4_fs_type);
300 if (ret < 0)
301 goto error_2;
302#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700303 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400304 return 0;
305
306#ifdef CONFIG_NFS_V4
307error_2:
308 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800309#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400310error_1:
311 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400312error_0:
313 return ret;
314}
315
316/*
317 * Unregister the NFS filesystems
318 */
319void __exit unregister_nfs_fs(void)
320{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700321 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400322#ifdef CONFIG_NFS_V4
323 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400324#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700325 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400326 unregister_filesystem(&nfs_fs_type);
327}
328
Steve Dicksonef818a22007-11-08 04:05:04 -0500329void nfs_sb_active(struct nfs_server *server)
330{
331 atomic_inc(&server->active);
332}
333
334void nfs_sb_deactive(struct nfs_server *server)
335{
336 if (atomic_dec_and_test(&server->active))
337 wake_up(&server->active_wq);
338}
339
340static void nfs_put_super(struct super_block *sb)
341{
342 struct nfs_server *server = NFS_SB(sb);
343 /*
344 * Make sure there are no outstanding ops to this server.
345 * If so, wait for them to finish before allowing the
346 * unmount to continue.
347 */
348 wait_event(server->active_wq, atomic_read(&server->active) == 0);
349}
350
David Howellsf7b422b2006-06-09 09:34:33 -0400351/*
352 * Deliver file system statistics to userspace
353 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400354static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400355{
David Howells0c7d90c2006-08-22 20:06:10 -0400356 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400357 unsigned char blockbits;
358 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400359 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400360 struct nfs_fattr fattr;
361 struct nfs_fsstat res = {
362 .fattr = &fattr,
363 };
364 int error;
365
366 lock_kernel();
367
David Howells8fa5c002006-08-22 20:06:12 -0400368 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400369 if (error < 0)
370 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700371 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400372
373 /*
374 * Current versions of glibc do not correctly handle the
375 * case where f_frsize != f_bsize. Eventually we want to
376 * report the value of wtmult in this field.
377 */
David Howells0c7d90c2006-08-22 20:06:10 -0400378 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400379
380 /*
381 * On most *nix systems, f_blocks, f_bfree, and f_bavail
382 * are reported in units of f_frsize. Linux hasn't had
383 * an f_frsize field in its statfs struct until recently,
384 * thus historically Linux's sys_statfs reports these
385 * fields in units of f_bsize.
386 */
David Howells0c7d90c2006-08-22 20:06:10 -0400387 buf->f_bsize = dentry->d_sb->s_blocksize;
388 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400389 blockres = (1 << blockbits) - 1;
390 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
391 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
392 buf->f_bavail = (res.abytes + blockres) >> blockbits;
393
394 buf->f_files = res.tfiles;
395 buf->f_ffree = res.afiles;
396
397 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700398
David Howellsf7b422b2006-06-09 09:34:33 -0400399 unlock_kernel();
400 return 0;
401
402 out_err:
403 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700404 unlock_kernel();
405 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400406}
407
David Howells7d4e2742006-08-22 20:06:07 -0400408/*
409 * Map the security flavour number to a name
410 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400411static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
412{
David Howells7d4e2742006-08-22 20:06:07 -0400413 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400414 rpc_authflavor_t flavour;
415 const char *str;
416 } sec_flavours[] = {
417 { RPC_AUTH_NULL, "null" },
418 { RPC_AUTH_UNIX, "sys" },
419 { RPC_AUTH_GSS_KRB5, "krb5" },
420 { RPC_AUTH_GSS_KRB5I, "krb5i" },
421 { RPC_AUTH_GSS_KRB5P, "krb5p" },
422 { RPC_AUTH_GSS_LKEY, "lkey" },
423 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
424 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
425 { RPC_AUTH_GSS_SPKM, "spkm" },
426 { RPC_AUTH_GSS_SPKMI, "spkmi" },
427 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400428 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400429 };
430 int i;
431
Chuck Lever4d81cd12007-07-01 12:12:40 -0400432 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400433 if (sec_flavours[i].flavour == flavour)
434 break;
435 }
436 return sec_flavours[i].str;
437}
438
David Howellsf7b422b2006-06-09 09:34:33 -0400439/*
440 * Describe the mount options in force on this server representation
441 */
442static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
443{
David Howells509de812006-08-22 20:06:11 -0400444 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400445 int flag;
David Howells509de812006-08-22 20:06:11 -0400446 const char *str;
447 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400448 } nfs_info[] = {
449 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Leverbcf35612007-09-24 15:39:55 -0400450 { NFS_MOUNT_INTR, ",intr", ",nointr" },
David Howellsf7b422b2006-06-09 09:34:33 -0400451 { NFS_MOUNT_NOCTO, ",nocto", "" },
452 { NFS_MOUNT_NOAC, ",noac", "" },
453 { NFS_MOUNT_NONLM, ",nolock", "" },
454 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400455 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400456 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400457 { 0, NULL, NULL }
458 };
David Howells509de812006-08-22 20:06:11 -0400459 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400460 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400461
David Howells8fa5c002006-08-22 20:06:12 -0400462 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400463 seq_printf(m, ",rsize=%d", nfss->rsize);
464 seq_printf(m, ",wsize=%d", nfss->wsize);
465 if (nfss->acregmin != 3*HZ || showdefaults)
466 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
467 if (nfss->acregmax != 60*HZ || showdefaults)
468 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
469 if (nfss->acdirmin != 30*HZ || showdefaults)
470 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
471 if (nfss->acdirmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
473 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
474 if (nfss->flags & nfs_infop->flag)
475 seq_puts(m, nfs_infop->str);
476 else
477 seq_puts(m, nfs_infop->nostr);
478 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400479 seq_printf(m, ",proto=%s",
480 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
David Howells5006a762006-08-22 20:06:12 -0400481 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
482 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400483 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400484}
485
486/*
487 * Describe the mount options on this VFS mountpoint
488 */
489static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
490{
491 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
492
493 nfs_show_mount_options(m, nfss, 0);
494
Jeff Laytonddc01c02007-07-30 08:47:38 -0400495 seq_printf(m, ",addr="NIPQUAD_FMT,
496 NIPQUAD(nfss->nfs_client->cl_addr.sin_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
David Howells8fa5c002006-08-22 20:06:12 -0400533 if (nfss->nfs_client->cl_nfsversion == 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;
789 case Opt_mountprog:
790 if (match_int(args, &option))
791 return 0;
792 if (option < 0)
793 return 0;
794 mnt->mount_server.program = option;
795 break;
796 case Opt_mountvers:
797 if (match_int(args, &option))
798 return 0;
799 if (option < 0)
800 return 0;
801 mnt->mount_server.version = option;
802 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400803 case Opt_nfsvers:
804 if (match_int(args, &option))
805 return 0;
806 switch (option) {
807 case 2:
808 mnt->flags &= ~NFS_MOUNT_VER3;
809 break;
810 case 3:
811 mnt->flags |= NFS_MOUNT_VER3;
812 break;
813 default:
814 goto out_unrec_vers;
815 }
816 break;
817
818 case Opt_sec:
819 string = match_strdup(args);
820 if (string == NULL)
821 goto out_nomem;
822 token = match_token(string, nfs_secflavor_tokens, args);
823 kfree(string);
824
825 /*
826 * The flags setting is for v2/v3. The flavor_len
827 * setting is for v4. v2/v3 also need to know the
828 * difference between NULL and UNIX.
829 */
830 switch (token) {
831 case Opt_sec_none:
832 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
833 mnt->auth_flavor_len = 0;
834 mnt->auth_flavors[0] = RPC_AUTH_NULL;
835 break;
836 case Opt_sec_sys:
837 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
838 mnt->auth_flavor_len = 0;
839 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
840 break;
841 case Opt_sec_krb5:
842 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
843 mnt->auth_flavor_len = 1;
844 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
845 break;
846 case Opt_sec_krb5i:
847 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 1;
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
850 break;
851 case Opt_sec_krb5p:
852 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 1;
854 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
855 break;
856 case Opt_sec_lkey:
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
860 break;
861 case Opt_sec_lkeyi:
862 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
863 mnt->auth_flavor_len = 1;
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
865 break;
866 case Opt_sec_lkeyp:
867 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
868 mnt->auth_flavor_len = 1;
869 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
870 break;
871 case Opt_sec_spkm:
872 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 1;
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
875 break;
876 case Opt_sec_spkmi:
877 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
880 break;
881 case Opt_sec_spkmp:
882 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 1;
884 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
885 break;
886 default:
887 goto out_unrec_sec;
888 }
889 break;
890 case Opt_proto:
891 string = match_strdup(args);
892 if (string == NULL)
893 goto out_nomem;
894 token = match_token(string,
895 nfs_xprt_protocol_tokens, args);
896 kfree(string);
897
898 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400899 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400900 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400901 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400902 mnt->timeo = 7;
903 mnt->retrans = 5;
904 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400905 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400906 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400907 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400908 mnt->timeo = 600;
909 mnt->retrans = 2;
910 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400911 case Opt_xprt_rdma:
912 /* vector side protocols to TCP */
913 mnt->flags |= NFS_MOUNT_TCP;
914 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
915 mnt->timeo = 600;
916 mnt->retrans = 2;
917 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400918 default:
919 goto out_unrec_xprt;
920 }
921 break;
922 case Opt_mountproto:
923 string = match_strdup(args);
924 if (string == NULL)
925 goto out_nomem;
926 token = match_token(string,
927 nfs_xprt_protocol_tokens, args);
928 kfree(string);
929
930 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400931 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400932 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400933 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400934 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400935 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400936 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400937 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400938 default:
939 goto out_unrec_xprt;
940 }
941 break;
942 case Opt_addr:
943 string = match_strdup(args);
944 if (string == NULL)
945 goto out_nomem;
946 mnt->nfs_server.address.sin_family = AF_INET;
947 mnt->nfs_server.address.sin_addr.s_addr =
948 in_aton(string);
949 kfree(string);
950 break;
951 case Opt_clientaddr:
952 string = match_strdup(args);
953 if (string == NULL)
954 goto out_nomem;
955 mnt->client_address = string;
956 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400957 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958 string = match_strdup(args);
959 if (string == NULL)
960 goto out_nomem;
961 mnt->mount_server.address.sin_family = AF_INET;
962 mnt->mount_server.address.sin_addr.s_addr =
963 in_aton(string);
964 kfree(string);
965 break;
966
967 case Opt_userspace:
968 case Opt_deprecated:
969 break;
970
971 default:
972 goto out_unknown;
973 }
974 }
975
976 return 1;
977
978out_nomem:
979 printk(KERN_INFO "NFS: not enough memory to parse option\n");
980 return 0;
981
982out_unrec_vers:
983 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
984 return 0;
985
986out_unrec_xprt:
987 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
988 return 0;
989
990out_unrec_sec:
991 printk(KERN_INFO "NFS: unrecognized security flavor\n");
992 return 0;
993
994out_unknown:
995 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
996 return 0;
997}
998
999/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001000 * Use the remote server's MOUNT service to request the NFS file handle
1001 * corresponding to the provided path.
1002 */
1003static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1004 struct nfs_fh *root_fh)
1005{
1006 struct sockaddr_in sin;
1007 int status;
1008
1009 if (args->mount_server.version == 0) {
1010 if (args->flags & NFS_MOUNT_VER3)
1011 args->mount_server.version = NFS_MNT3_VERSION;
1012 else
1013 args->mount_server.version = NFS_MNT_VERSION;
1014 }
1015
1016 /*
1017 * Construct the mount server's address.
1018 */
1019 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1020 sin = args->mount_server.address;
1021 else
1022 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001023 /*
1024 * autobind will be used if mount_server.port == 0
1025 */
1026 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001027
1028 /*
1029 * Now ask the mount server to map our export path
1030 * to a file handle.
1031 */
1032 status = nfs_mount((struct sockaddr *) &sin,
1033 sizeof(sin),
1034 args->nfs_server.hostname,
1035 args->nfs_server.export_path,
1036 args->mount_server.version,
1037 args->mount_server.protocol,
1038 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001039 if (status == 0)
1040 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001041
Chuck Leverefd83402007-09-11 18:00:58 -04001042 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1043 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001044 return status;
1045}
1046
1047/*
David Howells54ceac42006-08-22 20:06:13 -04001048 * Validate the NFS2/NFS3 mount data
1049 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001050 *
1051 * For option strings, user space handles the following behaviors:
1052 *
1053 * + DNS: mapping server host name to IP address ("addr=" option)
1054 *
1055 * + failure mode: how to behave if a mount request can't be handled
1056 * immediately ("fg/bg" option)
1057 *
1058 * + retry: how often to retry a mount request ("retry=" option)
1059 *
1060 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1061 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001062 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001063static int nfs_validate_mount_data(void *options,
1064 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001065 struct nfs_fh *mntfh,
1066 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001067{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001068 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001069
Russell Kingf16c9602007-11-16 22:13:24 +00001070 memset(args, 0, sizeof(*args));
1071
Chuck Lever5df36e72007-07-01 12:12:56 -04001072 if (data == NULL)
1073 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001074
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001075 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1076 args->rsize = NFS_MAX_FILE_IO_SIZE;
1077 args->wsize = NFS_MAX_FILE_IO_SIZE;
1078 args->timeo = 600;
1079 args->retrans = 2;
1080 args->acregmin = 3;
1081 args->acregmax = 60;
1082 args->acdirmin = 30;
1083 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001084 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001085 args->mount_server.program = NFS_MNT_PROGRAM;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001086 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001087
David Howellsf7b422b2006-06-09 09:34:33 -04001088 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001089 case 1:
1090 data->namlen = 0;
1091 case 2:
1092 data->bsize = 0;
1093 case 3:
1094 if (data->flags & NFS_MOUNT_VER3)
1095 goto out_no_v3;
1096 data->root.size = NFS2_FHSIZE;
1097 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1098 case 4:
1099 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1100 goto out_no_sec;
1101 case 5:
1102 memset(data->context, 0, sizeof(data->context));
1103 case 6:
1104 if (data->flags & NFS_MOUNT_VER3)
1105 mntfh->size = data->root.size;
1106 else
1107 mntfh->size = NFS2_FHSIZE;
1108
1109 if (mntfh->size > sizeof(mntfh->data))
1110 goto out_invalid_fh;
1111
1112 memcpy(mntfh->data, data->root.data, mntfh->size);
1113 if (mntfh->size < sizeof(mntfh->data))
1114 memset(mntfh->data + mntfh->size, 0,
1115 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001116
1117 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1118 goto out_no_address;
1119
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001120 /*
1121 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1122 * can deal with.
1123 */
1124 args->flags = data->flags;
1125 args->rsize = data->rsize;
1126 args->wsize = data->wsize;
1127 args->flags = data->flags;
1128 args->timeo = data->timeo;
1129 args->retrans = data->retrans;
1130 args->acregmin = data->acregmin;
1131 args->acregmax = data->acregmax;
1132 args->acdirmin = data->acdirmin;
1133 args->acdirmax = data->acdirmax;
1134 args->nfs_server.address = data->addr;
1135 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001136 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001137 /* N.B. caller will free nfs_server.hostname in all cases */
1138 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1139 args->namlen = data->namlen;
1140 args->bsize = data->bsize;
1141 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001142 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001143 default: {
1144 unsigned int len;
1145 char *c;
1146 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001147
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001148 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001149 return -EINVAL;
1150
Chuck Lever6e88e062007-09-24 15:39:50 -04001151 if (!nfs_verify_server_address((struct sockaddr *)
1152 &args->nfs_server.address))
1153 goto out_no_address;
1154
Chuck Lever136d5582007-07-01 12:13:54 -04001155 c = strchr(dev_name, ':');
1156 if (c == NULL)
1157 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001158 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001159 /* N.B. caller will free nfs_server.hostname in all cases */
1160 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001161
1162 c++;
1163 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001164 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001165 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001166
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001167 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001168 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001169 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001170
Chuck Lever136d5582007-07-01 12:13:54 -04001171 break;
1172 }
David Howellsf7b422b2006-06-09 09:34:33 -04001173 }
David Howells54ceac42006-08-22 20:06:13 -04001174
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001175 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1176 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001177
David Howellsf7b422b2006-06-09 09:34:33 -04001178#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001179 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001180 goto out_v3_not_compiled;
1181#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001182
David Howells54ceac42006-08-22 20:06:13 -04001183 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001184
1185out_no_data:
1186 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1187 return -EINVAL;
1188
1189out_no_v3:
1190 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1191 data->version);
1192 return -EINVAL;
1193
1194out_no_sec:
1195 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1196 return -EINVAL;
1197
Chuck Lever5df36e72007-07-01 12:12:56 -04001198#ifndef CONFIG_NFS_V3
1199out_v3_not_compiled:
1200 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1201 return -EPROTONOSUPPORT;
1202#endif /* !CONFIG_NFS_V3 */
1203
1204out_no_address:
1205 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1206 return -EINVAL;
1207
1208out_invalid_fh:
1209 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1210 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001211}
1212
1213/*
1214 * Initialise the common bits of the superblock
1215 */
1216static inline void nfs_initialise_sb(struct super_block *sb)
1217{
1218 struct nfs_server *server = NFS_SB(sb);
1219
1220 sb->s_magic = NFS_SUPER_MAGIC;
1221
1222 /* We probably want something more informative here */
1223 snprintf(sb->s_id, sizeof(sb->s_id),
1224 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1225
1226 if (sb->s_blocksize == 0)
1227 sb->s_blocksize = nfs_block_bits(server->wsize,
1228 &sb->s_blocksize_bits);
1229
1230 if (server->flags & NFS_MOUNT_NOAC)
1231 sb->s_flags |= MS_SYNCHRONOUS;
1232
1233 nfs_super_set_maxbytes(sb, server->maxfilesize);
1234}
1235
1236/*
1237 * Finish setting up an NFS2/3 superblock
1238 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001239static void nfs_fill_super(struct super_block *sb,
1240 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001241{
1242 struct nfs_server *server = NFS_SB(sb);
1243
1244 sb->s_blocksize_bits = 0;
1245 sb->s_blocksize = 0;
1246 if (data->bsize)
1247 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1248
1249 if (server->flags & NFS_MOUNT_VER3) {
1250 /* The VFS shouldn't apply the umask to mode bits. We will do
1251 * so ourselves when necessary.
1252 */
1253 sb->s_flags |= MS_POSIXACL;
1254 sb->s_time_gran = 1;
1255 }
1256
1257 sb->s_op = &nfs_sops;
1258 nfs_initialise_sb(sb);
1259}
1260
1261/*
1262 * Finish setting up a cloned NFS2/3 superblock
1263 */
1264static void nfs_clone_super(struct super_block *sb,
1265 const struct super_block *old_sb)
1266{
1267 struct nfs_server *server = NFS_SB(sb);
1268
1269 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1270 sb->s_blocksize = old_sb->s_blocksize;
1271 sb->s_maxbytes = old_sb->s_maxbytes;
1272
1273 if (server->flags & NFS_MOUNT_VER3) {
1274 /* The VFS shouldn't apply the umask to mode bits. We will do
1275 * so ourselves when necessary.
1276 */
1277 sb->s_flags |= MS_POSIXACL;
1278 sb->s_time_gran = 1;
1279 }
1280
1281 sb->s_op = old_sb->s_op;
1282 nfs_initialise_sb(sb);
1283}
1284
Trond Myklebust275a5d22007-05-16 16:53:28 -04001285#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1286
1287static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1288{
1289 const struct nfs_server *a = s->s_fs_info;
1290 const struct rpc_clnt *clnt_a = a->client;
1291 const struct rpc_clnt *clnt_b = b->client;
1292
1293 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1294 goto Ebusy;
1295 if (a->nfs_client != b->nfs_client)
1296 goto Ebusy;
1297 if (a->flags != b->flags)
1298 goto Ebusy;
1299 if (a->wsize != b->wsize)
1300 goto Ebusy;
1301 if (a->rsize != b->rsize)
1302 goto Ebusy;
1303 if (a->acregmin != b->acregmin)
1304 goto Ebusy;
1305 if (a->acregmax != b->acregmax)
1306 goto Ebusy;
1307 if (a->acdirmin != b->acdirmin)
1308 goto Ebusy;
1309 if (a->acdirmax != b->acdirmax)
1310 goto Ebusy;
1311 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1312 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001313 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001314Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001315 return 0;
1316}
1317
1318struct nfs_sb_mountdata {
1319 struct nfs_server *server;
1320 int mntflags;
1321};
1322
1323static int nfs_set_super(struct super_block *s, void *data)
1324{
1325 struct nfs_sb_mountdata *sb_mntdata = data;
1326 struct nfs_server *server = sb_mntdata->server;
1327 int ret;
1328
1329 s->s_flags = sb_mntdata->mntflags;
1330 s->s_fs_info = server;
1331 ret = set_anon_super(s, server);
1332 if (ret == 0)
1333 server->s_dev = s->s_dev;
1334 return ret;
1335}
1336
1337static int nfs_compare_super(struct super_block *sb, void *data)
1338{
1339 struct nfs_sb_mountdata *sb_mntdata = data;
1340 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1341 int mntflags = sb_mntdata->mntflags;
1342
1343 if (memcmp(&old->nfs_client->cl_addr,
1344 &server->nfs_client->cl_addr,
1345 sizeof(old->nfs_client->cl_addr)) != 0)
1346 return 0;
1347 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1348 if (old->flags & NFS_MOUNT_UNSHARED)
1349 return 0;
1350 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1351 return 0;
1352 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001353}
1354
David Howells54ceac42006-08-22 20:06:13 -04001355static int nfs_get_sb(struct file_system_type *fs_type,
1356 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1357{
1358 struct nfs_server *server = NULL;
1359 struct super_block *s;
1360 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001361 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001362 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001363 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001364 struct nfs_sb_mountdata sb_mntdata = {
1365 .mntflags = flags,
1366 };
David Howells54ceac42006-08-22 20:06:13 -04001367 int error;
1368
1369 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001370 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001371 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001372 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001373
1374 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001375 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001376 if (IS_ERR(server)) {
1377 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001378 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001379 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001380 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001381
Trond Myklebust75180df2007-05-16 16:53:28 -04001382 if (server->flags & NFS_MOUNT_UNSHARED)
1383 compare_super = NULL;
1384
David Howells54ceac42006-08-22 20:06:13 -04001385 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001386 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001387 if (IS_ERR(s)) {
1388 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001389 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001390 }
1391
David Howells54ceac42006-08-22 20:06:13 -04001392 if (s->s_fs_info != server) {
1393 nfs_free_server(server);
1394 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001395 }
David Howells54ceac42006-08-22 20:06:13 -04001396
1397 if (!s->s_root) {
1398 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001399 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001400 }
1401
1402 mntroot = nfs_get_root(s, &mntfh);
1403 if (IS_ERR(mntroot)) {
1404 error = PTR_ERR(mntroot);
1405 goto error_splat_super;
1406 }
1407
David Howellsf7b422b2006-06-09 09:34:33 -04001408 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001409 mnt->mnt_sb = s;
1410 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001411 error = 0;
1412
1413out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001414 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001415 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001416
David Howells54ceac42006-08-22 20:06:13 -04001417out_err_nosb:
1418 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001419 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001420
1421error_splat_super:
1422 up_write(&s->s_umount);
1423 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001424 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001425}
1426
David Howells54ceac42006-08-22 20:06:13 -04001427/*
1428 * Destroy an NFS2/3 superblock
1429 */
David Howellsf7b422b2006-06-09 09:34:33 -04001430static void nfs_kill_super(struct super_block *s)
1431{
1432 struct nfs_server *server = NFS_SB(s);
1433
1434 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001435 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001436}
1437
David Howells54ceac42006-08-22 20:06:13 -04001438/*
1439 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1440 */
1441static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1442 const char *dev_name, void *raw_data,
1443 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001444{
1445 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001446 struct super_block *s;
1447 struct nfs_server *server;
1448 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001449 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001450 struct nfs_sb_mountdata sb_mntdata = {
1451 .mntflags = flags,
1452 };
David Howells54ceac42006-08-22 20:06:13 -04001453 int error;
1454
1455 dprintk("--> nfs_xdev_get_sb()\n");
1456
1457 /* create a new volume representation */
1458 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1459 if (IS_ERR(server)) {
1460 error = PTR_ERR(server);
1461 goto out_err_noserver;
1462 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001463 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001464
Trond Myklebust75180df2007-05-16 16:53:28 -04001465 if (server->flags & NFS_MOUNT_UNSHARED)
1466 compare_super = NULL;
1467
David Howells54ceac42006-08-22 20:06:13 -04001468 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001469 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001470 if (IS_ERR(s)) {
1471 error = PTR_ERR(s);
1472 goto out_err_nosb;
1473 }
1474
1475 if (s->s_fs_info != server) {
1476 nfs_free_server(server);
1477 server = NULL;
1478 }
1479
1480 if (!s->s_root) {
1481 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001482 nfs_clone_super(s, data->sb);
1483 }
1484
1485 mntroot = nfs_get_root(s, data->fh);
1486 if (IS_ERR(mntroot)) {
1487 error = PTR_ERR(mntroot);
1488 goto error_splat_super;
1489 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001490 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001491 dput(mntroot);
1492 error = -ESTALE;
1493 goto error_splat_super;
1494 }
David Howells54ceac42006-08-22 20:06:13 -04001495
1496 s->s_flags |= MS_ACTIVE;
1497 mnt->mnt_sb = s;
1498 mnt->mnt_root = mntroot;
1499
1500 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1501 return 0;
1502
1503out_err_nosb:
1504 nfs_free_server(server);
1505out_err_noserver:
1506 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1507 return error;
1508
1509error_splat_super:
1510 up_write(&s->s_umount);
1511 deactivate_super(s);
1512 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1513 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001514}
1515
1516#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001517
1518/*
1519 * Finish setting up a cloned NFS4 superblock
1520 */
1521static void nfs4_clone_super(struct super_block *sb,
1522 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001523{
David Howells54ceac42006-08-22 20:06:13 -04001524 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1525 sb->s_blocksize = old_sb->s_blocksize;
1526 sb->s_maxbytes = old_sb->s_maxbytes;
1527 sb->s_time_gran = 1;
1528 sb->s_op = old_sb->s_op;
1529 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001530}
1531
1532/*
1533 * Set up an NFS4 superblock
1534 */
David Howells54ceac42006-08-22 20:06:13 -04001535static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001536{
David Howellsf7b422b2006-06-09 09:34:33 -04001537 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001538 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001539 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001540}
1541
David Howells54ceac42006-08-22 20:06:13 -04001542/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001543 * Validate NFSv4 mount options
1544 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001545static int nfs4_validate_mount_data(void *options,
1546 struct nfs_parsed_mount_data *args,
1547 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001548{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001549 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001550 char *c;
1551
Russell Kingf16c9602007-11-16 22:13:24 +00001552 memset(args, 0, sizeof(*args));
1553
Chuck Leverf0768eb2007-07-01 12:13:01 -04001554 if (data == NULL)
1555 goto out_no_data;
1556
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001557 args->rsize = NFS_MAX_FILE_IO_SIZE;
1558 args->wsize = NFS_MAX_FILE_IO_SIZE;
1559 args->timeo = 600;
1560 args->retrans = 2;
1561 args->acregmin = 3;
1562 args->acregmax = 60;
1563 args->acdirmin = 30;
1564 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001565 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001566
Chuck Leverf0768eb2007-07-01 12:13:01 -04001567 switch (data->version) {
1568 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001569 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001570 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001571 if (copy_from_user(&args->nfs_server.address,
1572 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001573 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001574 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001575 if (args->nfs_server.address.sin_port == 0)
1576 args->nfs_server.address.sin_port = htons(NFS_PORT);
1577 if (!nfs_verify_server_address((struct sockaddr *)
1578 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001579 goto out_no_address;
1580
1581 switch (data->auth_flavourlen) {
1582 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001583 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001584 break;
1585 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001586 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001587 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001588 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001589 return -EFAULT;
1590 break;
1591 default:
1592 goto out_inval_auth;
1593 }
1594
1595 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1596 if (IS_ERR(c))
1597 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001598 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001599
1600 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1601 if (IS_ERR(c))
1602 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001603 args->nfs_server.export_path = c;
1604 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001605
1606 c = strndup_user(data->client_addr.data, 16);
1607 if (IS_ERR(c))
1608 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001609 args->client_address = c;
1610
1611 /*
1612 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1613 * can deal with.
1614 */
1615
1616 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1617 args->rsize = data->rsize;
1618 args->wsize = data->wsize;
1619 args->timeo = data->timeo;
1620 args->retrans = data->retrans;
1621 args->acregmin = data->acregmin;
1622 args->acregmax = data->acregmax;
1623 args->acdirmin = data->acdirmin;
1624 args->acdirmax = data->acdirmax;
1625 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001626
1627 break;
Chuck Lever80071222007-07-01 12:13:59 -04001628 default: {
1629 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001630
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001631 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001632 return -EINVAL;
1633
Chuck Lever0eb25742007-10-26 13:32:19 -04001634 if (args->nfs_server.address.sin_port == 0)
1635 args->nfs_server.address.sin_port = htons(NFS_PORT);
Chuck Lever80071222007-07-01 12:13:59 -04001636 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001637 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001638 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001639
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001640 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001641 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001642 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001643 break;
1644 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001645 break;
1646 default:
1647 goto out_inval_auth;
1648 }
1649
1650 /*
Chuck Lever80071222007-07-01 12:13:59 -04001651 * Split "dev_name" into "hostname:mntpath".
1652 */
1653 c = strchr(dev_name, ':');
1654 if (c == NULL)
1655 return -EINVAL;
1656 /* while calculating len, pretend ':' is '\0' */
1657 len = c - dev_name;
1658 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001659 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001660 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1661 if (args->nfs_server.hostname == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001662 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001663 strncpy(args->nfs_server.hostname, dev_name, len - 1);
Chuck Lever80071222007-07-01 12:13:59 -04001664
1665 c++; /* step over the ':' */
1666 len = strlen(c);
1667 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001668 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001669 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1670 if (args->nfs_server.export_path == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001671 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001672 strncpy(args->nfs_server.export_path, c, len);
Chuck Lever80071222007-07-01 12:13:59 -04001673
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001674 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001675
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001676 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001677 goto out_no_client_address;
1678
Chuck Lever80071222007-07-01 12:13:59 -04001679 break;
1680 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001681 }
1682
1683 return 0;
1684
1685out_no_data:
1686 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1687 return -EINVAL;
1688
1689out_inval_auth:
1690 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1691 data->auth_flavourlen);
1692 return -EINVAL;
1693
1694out_no_address:
1695 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1696 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001697
1698out_no_client_address:
1699 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1700 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001701}
1702
1703/*
David Howells54ceac42006-08-22 20:06:13 -04001704 * Get the superblock for an NFS4 mountpoint
1705 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001706static int nfs4_get_sb(struct file_system_type *fs_type,
1707 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001708{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001709 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001710 struct super_block *s;
1711 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001712 struct nfs_fh mntfh;
1713 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001714 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001715 struct nfs_sb_mountdata sb_mntdata = {
1716 .mntflags = flags,
1717 };
David Howells54ceac42006-08-22 20:06:13 -04001718 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001719
Chuck Leverf0768eb2007-07-01 12:13:01 -04001720 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001721 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001722 if (error < 0)
1723 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001724
David Howells54ceac42006-08-22 20:06:13 -04001725 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001726 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001727 if (IS_ERR(server)) {
1728 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001729 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001730 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001731 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001732
Trond Myklebust75180df2007-05-16 16:53:28 -04001733 if (server->flags & NFS4_MOUNT_UNSHARED)
1734 compare_super = NULL;
1735
David Howells54ceac42006-08-22 20:06:13 -04001736 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001737 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001738 if (IS_ERR(s)) {
1739 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001740 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001741 }
1742
Trond Myklebust5dd31772006-08-24 01:03:05 -04001743 if (s->s_fs_info != server) {
1744 nfs_free_server(server);
1745 server = NULL;
1746 }
1747
David Howells54ceac42006-08-22 20:06:13 -04001748 if (!s->s_root) {
1749 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001750 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001751 }
David Howellsf7b422b2006-06-09 09:34:33 -04001752
David Howells54ceac42006-08-22 20:06:13 -04001753 mntroot = nfs4_get_root(s, &mntfh);
1754 if (IS_ERR(mntroot)) {
1755 error = PTR_ERR(mntroot);
1756 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001757 }
David Howells54ceac42006-08-22 20:06:13 -04001758
David Howellsf7b422b2006-06-09 09:34:33 -04001759 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001760 mnt->mnt_sb = s;
1761 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001762 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001763
Chuck Lever29eb9812007-07-01 12:12:30 -04001764out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001765 kfree(data.client_address);
1766 kfree(data.nfs_server.export_path);
1767 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001768 return error;
David Howells54ceac42006-08-22 20:06:13 -04001769
Chuck Lever29eb9812007-07-01 12:12:30 -04001770out_free:
1771 nfs_free_server(server);
1772 goto out;
1773
David Howells54ceac42006-08-22 20:06:13 -04001774error_splat_super:
1775 up_write(&s->s_umount);
1776 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001777 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001778}
1779
1780static void nfs4_kill_super(struct super_block *sb)
1781{
1782 struct nfs_server *server = NFS_SB(sb);
1783
1784 nfs_return_all_delegations(sb);
1785 kill_anon_super(sb);
1786
1787 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001788 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001789}
1790
1791/*
David Howells54ceac42006-08-22 20:06:13 -04001792 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001793 */
David Howells54ceac42006-08-22 20:06:13 -04001794static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1795 const char *dev_name, void *raw_data,
1796 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001797{
1798 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001799 struct super_block *s;
1800 struct nfs_server *server;
1801 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001802 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001803 struct nfs_sb_mountdata sb_mntdata = {
1804 .mntflags = flags,
1805 };
David Howells54ceac42006-08-22 20:06:13 -04001806 int error;
1807
1808 dprintk("--> nfs4_xdev_get_sb()\n");
1809
1810 /* create a new volume representation */
1811 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1812 if (IS_ERR(server)) {
1813 error = PTR_ERR(server);
1814 goto out_err_noserver;
1815 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001816 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001817
Trond Myklebust75180df2007-05-16 16:53:28 -04001818 if (server->flags & NFS4_MOUNT_UNSHARED)
1819 compare_super = NULL;
1820
David Howells54ceac42006-08-22 20:06:13 -04001821 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001822 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001823 if (IS_ERR(s)) {
1824 error = PTR_ERR(s);
1825 goto out_err_nosb;
1826 }
1827
1828 if (s->s_fs_info != server) {
1829 nfs_free_server(server);
1830 server = NULL;
1831 }
1832
1833 if (!s->s_root) {
1834 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001835 nfs4_clone_super(s, data->sb);
1836 }
1837
1838 mntroot = nfs4_get_root(s, data->fh);
1839 if (IS_ERR(mntroot)) {
1840 error = PTR_ERR(mntroot);
1841 goto error_splat_super;
1842 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001843 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1844 dput(mntroot);
1845 error = -ESTALE;
1846 goto error_splat_super;
1847 }
David Howells54ceac42006-08-22 20:06:13 -04001848
1849 s->s_flags |= MS_ACTIVE;
1850 mnt->mnt_sb = s;
1851 mnt->mnt_root = mntroot;
1852
1853 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1854 return 0;
1855
1856out_err_nosb:
1857 nfs_free_server(server);
1858out_err_noserver:
1859 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1860 return error;
1861
1862error_splat_super:
1863 up_write(&s->s_umount);
1864 deactivate_super(s);
1865 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1866 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001867}
1868
David Howells54ceac42006-08-22 20:06:13 -04001869/*
1870 * Create an NFS4 server record on referral traversal
1871 */
1872static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1873 const char *dev_name, void *raw_data,
1874 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001875{
1876 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001877 struct super_block *s;
1878 struct nfs_server *server;
1879 struct dentry *mntroot;
1880 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001881 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001882 struct nfs_sb_mountdata sb_mntdata = {
1883 .mntflags = flags,
1884 };
David Howells54ceac42006-08-22 20:06:13 -04001885 int error;
1886
1887 dprintk("--> nfs4_referral_get_sb()\n");
1888
1889 /* create a new volume representation */
1890 server = nfs4_create_referral_server(data, &mntfh);
1891 if (IS_ERR(server)) {
1892 error = PTR_ERR(server);
1893 goto out_err_noserver;
1894 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001895 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001896
Trond Myklebust75180df2007-05-16 16:53:28 -04001897 if (server->flags & NFS4_MOUNT_UNSHARED)
1898 compare_super = NULL;
1899
David Howells54ceac42006-08-22 20:06:13 -04001900 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001901 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001902 if (IS_ERR(s)) {
1903 error = PTR_ERR(s);
1904 goto out_err_nosb;
1905 }
1906
1907 if (s->s_fs_info != server) {
1908 nfs_free_server(server);
1909 server = NULL;
1910 }
1911
1912 if (!s->s_root) {
1913 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001914 nfs4_fill_super(s);
1915 }
1916
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001917 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001918 if (IS_ERR(mntroot)) {
1919 error = PTR_ERR(mntroot);
1920 goto error_splat_super;
1921 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001922 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1923 dput(mntroot);
1924 error = -ESTALE;
1925 goto error_splat_super;
1926 }
David Howells54ceac42006-08-22 20:06:13 -04001927
1928 s->s_flags |= MS_ACTIVE;
1929 mnt->mnt_sb = s;
1930 mnt->mnt_root = mntroot;
1931
1932 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1933 return 0;
1934
1935out_err_nosb:
1936 nfs_free_server(server);
1937out_err_noserver:
1938 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1939 return error;
1940
1941error_splat_super:
1942 up_write(&s->s_umount);
1943 deactivate_super(s);
1944 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1945 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001946}
1947
David Howells54ceac42006-08-22 20:06:13 -04001948#endif /* CONFIG_NFS_V4 */