blob: fda1635dd1336779cff5181eac91ccf659fea951 [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,
87 Opt_nfsprog, Opt_nfsvers,
88
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" },
142 { Opt_nfsprog, "nfsprog=%u" },
143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
145
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400151 { Opt_userspace, "mounthost=%s" },
152 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153
154 { Opt_err, NULL }
155};
156
157enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400158 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400159
160 Opt_xprt_err
161};
162
163static match_table_t nfs_xprt_protocol_tokens = {
164 { Opt_xprt_udp, "udp" },
165 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400166 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400167
168 { Opt_xprt_err, NULL }
169};
170
171enum {
172 Opt_sec_none, Opt_sec_sys,
173 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
174 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
175 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
176
177 Opt_sec_err
178};
179
180static match_table_t nfs_secflavor_tokens = {
181 { Opt_sec_none, "none" },
182 { Opt_sec_none, "null" },
183 { Opt_sec_sys, "sys" },
184
185 { Opt_sec_krb5, "krb5" },
186 { Opt_sec_krb5i, "krb5i" },
187 { Opt_sec_krb5p, "krb5p" },
188
189 { Opt_sec_lkey, "lkey" },
190 { Opt_sec_lkeyi, "lkeyi" },
191 { Opt_sec_lkeyp, "lkeyp" },
192
193 { Opt_sec_err, NULL }
194};
195
196
David Howellsf7b422b2006-06-09 09:34:33 -0400197static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400198static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400199static int nfs_show_options(struct seq_file *, struct vfsmount *);
200static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400201static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400202static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400203 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400204static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500205static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400206
207static struct file_system_type nfs_fs_type = {
208 .owner = THIS_MODULE,
209 .name = "nfs",
210 .get_sb = nfs_get_sb,
211 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700212 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400213};
214
David Howells54ceac42006-08-22 20:06:13 -0400215struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400216 .owner = THIS_MODULE,
217 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400218 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400219 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700220 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400221};
222
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800223static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400224 .alloc_inode = nfs_alloc_inode,
225 .destroy_inode = nfs_destroy_inode,
226 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500227 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400228 .statfs = nfs_statfs,
229 .clear_inode = nfs_clear_inode,
230 .umount_begin = nfs_umount_begin,
231 .show_options = nfs_show_options,
232 .show_stats = nfs_show_stats,
233};
234
235#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400236static int nfs4_get_sb(struct file_system_type *fs_type,
237 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400238static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
239 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
240static int nfs4_referral_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400242static void nfs4_kill_super(struct super_block *sb);
243
244static struct file_system_type nfs4_fs_type = {
245 .owner = THIS_MODULE,
246 .name = "nfs4",
247 .get_sb = nfs4_get_sb,
248 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700249 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400250};
251
David Howells54ceac42006-08-22 20:06:13 -0400252struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400253 .owner = THIS_MODULE,
254 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400255 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400256 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700257 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400258};
259
David Howells54ceac42006-08-22 20:06:13 -0400260struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400261 .owner = THIS_MODULE,
262 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400263 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400264 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700265 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400266};
267
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800268static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400269 .alloc_inode = nfs_alloc_inode,
270 .destroy_inode = nfs_destroy_inode,
271 .write_inode = nfs_write_inode,
272 .statfs = nfs_statfs,
273 .clear_inode = nfs4_clear_inode,
274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
277};
278#endif
279
Rusty Russell8e1f9362007-07-17 04:03:17 -0700280static struct shrinker acl_shrinker = {
281 .shrink = nfs_access_cache_shrinker,
282 .seeks = DEFAULT_SEEKS,
283};
Trond Myklebust979df722006-07-25 11:28:19 -0400284
David Howellsf7b422b2006-06-09 09:34:33 -0400285/*
286 * Register the NFS filesystems
287 */
288int __init register_nfs_fs(void)
289{
290 int ret;
291
292 ret = register_filesystem(&nfs_fs_type);
293 if (ret < 0)
294 goto error_0;
295
David Howellsf7b422b2006-06-09 09:34:33 -0400296 ret = nfs_register_sysctl();
297 if (ret < 0)
298 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800299#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400300 ret = register_filesystem(&nfs4_fs_type);
301 if (ret < 0)
302 goto error_2;
303#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700304 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400305 return 0;
306
307#ifdef CONFIG_NFS_V4
308error_2:
309 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800310#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400311error_1:
312 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400313error_0:
314 return ret;
315}
316
317/*
318 * Unregister the NFS filesystems
319 */
320void __exit unregister_nfs_fs(void)
321{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700322 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400323#ifdef CONFIG_NFS_V4
324 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400325#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700326 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400327 unregister_filesystem(&nfs_fs_type);
328}
329
Steve Dicksonef818a22007-11-08 04:05:04 -0500330void nfs_sb_active(struct nfs_server *server)
331{
332 atomic_inc(&server->active);
333}
334
335void nfs_sb_deactive(struct nfs_server *server)
336{
337 if (atomic_dec_and_test(&server->active))
338 wake_up(&server->active_wq);
339}
340
341static void nfs_put_super(struct super_block *sb)
342{
343 struct nfs_server *server = NFS_SB(sb);
344 /*
345 * Make sure there are no outstanding ops to this server.
346 * If so, wait for them to finish before allowing the
347 * unmount to continue.
348 */
349 wait_event(server->active_wq, atomic_read(&server->active) == 0);
350}
351
David Howellsf7b422b2006-06-09 09:34:33 -0400352/*
353 * Deliver file system statistics to userspace
354 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400355static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400356{
David Howells0c7d90c2006-08-22 20:06:10 -0400357 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400358 unsigned char blockbits;
359 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400360 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400361 struct nfs_fattr fattr;
362 struct nfs_fsstat res = {
363 .fattr = &fattr,
364 };
365 int error;
366
367 lock_kernel();
368
David Howells8fa5c002006-08-22 20:06:12 -0400369 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400370 if (error < 0)
371 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700372 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400373
374 /*
375 * Current versions of glibc do not correctly handle the
376 * case where f_frsize != f_bsize. Eventually we want to
377 * report the value of wtmult in this field.
378 */
David Howells0c7d90c2006-08-22 20:06:10 -0400379 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400380
381 /*
382 * On most *nix systems, f_blocks, f_bfree, and f_bavail
383 * are reported in units of f_frsize. Linux hasn't had
384 * an f_frsize field in its statfs struct until recently,
385 * thus historically Linux's sys_statfs reports these
386 * fields in units of f_bsize.
387 */
David Howells0c7d90c2006-08-22 20:06:10 -0400388 buf->f_bsize = dentry->d_sb->s_blocksize;
389 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400390 blockres = (1 << blockbits) - 1;
391 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
392 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
393 buf->f_bavail = (res.abytes + blockres) >> blockbits;
394
395 buf->f_files = res.tfiles;
396 buf->f_ffree = res.afiles;
397
398 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700399
David Howellsf7b422b2006-06-09 09:34:33 -0400400 unlock_kernel();
401 return 0;
402
403 out_err:
404 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700405 unlock_kernel();
406 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400407}
408
David Howells7d4e2742006-08-22 20:06:07 -0400409/*
410 * Map the security flavour number to a name
411 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400412static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
413{
David Howells7d4e2742006-08-22 20:06:07 -0400414 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400415 rpc_authflavor_t flavour;
416 const char *str;
417 } sec_flavours[] = {
418 { RPC_AUTH_NULL, "null" },
419 { RPC_AUTH_UNIX, "sys" },
420 { RPC_AUTH_GSS_KRB5, "krb5" },
421 { RPC_AUTH_GSS_KRB5I, "krb5i" },
422 { RPC_AUTH_GSS_KRB5P, "krb5p" },
423 { RPC_AUTH_GSS_LKEY, "lkey" },
424 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
425 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
426 { RPC_AUTH_GSS_SPKM, "spkm" },
427 { RPC_AUTH_GSS_SPKMI, "spkmi" },
428 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400429 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400430 };
431 int i;
432
Chuck Lever4d81cd12007-07-01 12:12:40 -0400433 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400434 if (sec_flavours[i].flavour == flavour)
435 break;
436 }
437 return sec_flavours[i].str;
438}
439
David Howellsf7b422b2006-06-09 09:34:33 -0400440/*
441 * Describe the mount options in force on this server representation
442 */
443static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
444{
David Howells509de812006-08-22 20:06:11 -0400445 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400446 int flag;
David Howells509de812006-08-22 20:06:11 -0400447 const char *str;
448 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400449 } nfs_info[] = {
450 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Leverbcf35612007-09-24 15:39:55 -0400451 { NFS_MOUNT_INTR, ",intr", ",nointr" },
David Howellsf7b422b2006-06-09 09:34:33 -0400452 { NFS_MOUNT_NOCTO, ",nocto", "" },
453 { NFS_MOUNT_NOAC, ",noac", "" },
454 { NFS_MOUNT_NONLM, ",nolock", "" },
455 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400456 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400457 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400458 { 0, NULL, NULL }
459 };
David Howells509de812006-08-22 20:06:11 -0400460 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400461 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400462
David Howells8fa5c002006-08-22 20:06:12 -0400463 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400464 seq_printf(m, ",rsize=%d", nfss->rsize);
465 seq_printf(m, ",wsize=%d", nfss->wsize);
466 if (nfss->acregmin != 3*HZ || showdefaults)
467 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
468 if (nfss->acregmax != 60*HZ || showdefaults)
469 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
470 if (nfss->acdirmin != 30*HZ || showdefaults)
471 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
472 if (nfss->acdirmax != 60*HZ || showdefaults)
473 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
474 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
475 if (nfss->flags & nfs_infop->flag)
476 seq_puts(m, nfs_infop->str);
477 else
478 seq_puts(m, nfs_infop->nostr);
479 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400480 seq_printf(m, ",proto=%s",
481 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
David Howells5006a762006-08-22 20:06:12 -0400482 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
483 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400484 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400485}
486
487/*
488 * Describe the mount options on this VFS mountpoint
489 */
490static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
491{
492 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
493
494 nfs_show_mount_options(m, nfss, 0);
495
Jeff Laytonddc01c02007-07-30 08:47:38 -0400496 seq_printf(m, ",addr="NIPQUAD_FMT,
497 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
David Howellsf7b422b2006-06-09 09:34:33 -0400498
499 return 0;
500}
501
502/*
503 * Present statistical information for this VFS mountpoint
504 */
505static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
506{
507 int i, cpu;
508 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
509 struct rpc_auth *auth = nfss->client->cl_auth;
510 struct nfs_iostats totals = { };
511
512 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
513
514 /*
515 * Display all mount option settings
516 */
517 seq_printf(m, "\n\topts:\t");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
522 nfs_show_mount_options(m, nfss, 1);
523
524 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
525
526 seq_printf(m, "\n\tcaps:\t");
527 seq_printf(m, "caps=0x%x", nfss->caps);
528 seq_printf(m, ",wtmult=%d", nfss->wtmult);
529 seq_printf(m, ",dtsize=%d", nfss->dtsize);
530 seq_printf(m, ",bsize=%d", nfss->bsize);
531 seq_printf(m, ",namelen=%d", nfss->namelen);
532
533#ifdef CONFIG_NFS_V4
David Howells8fa5c002006-08-22 20:06:12 -0400534 if (nfss->nfs_client->cl_nfsversion == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400535 seq_printf(m, "\n\tnfsv4:\t");
536 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
537 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
538 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
539 }
540#endif
541
542 /*
543 * Display security flavor in effect for this mount
544 */
545 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
546 if (auth->au_flavor)
547 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
548
549 /*
550 * Display superblock I/O counters
551 */
552 for_each_possible_cpu(cpu) {
553 struct nfs_iostats *stats;
554
555 preempt_disable();
556 stats = per_cpu_ptr(nfss->io_stats, cpu);
557
558 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
559 totals.events[i] += stats->events[i];
560 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
561 totals.bytes[i] += stats->bytes[i];
562
563 preempt_enable();
564 }
565
566 seq_printf(m, "\n\tevents:\t");
567 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
568 seq_printf(m, "%lu ", totals.events[i]);
569 seq_printf(m, "\n\tbytes:\t");
570 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
571 seq_printf(m, "%Lu ", totals.bytes[i]);
572 seq_printf(m, "\n");
573
574 rpc_print_iostats(m, nfss->client);
575
576 return 0;
577}
578
579/*
580 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400581 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400582 */
583static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
584{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400585 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
586 struct rpc_clnt *rpc;
587
David Howellsf7b422b2006-06-09 09:34:33 -0400588 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400589
590 if (!(flags & MNT_FORCE))
591 return;
592 /* -EIO all pending I/O */
593 rpc = server->client_acl;
594 if (!IS_ERR(rpc))
595 rpc_killall_tasks(rpc);
596 rpc = server->client;
597 if (!IS_ERR(rpc))
598 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400599}
600
601/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400602 * Sanity-check a server address provided by the mount command
603 */
604static int nfs_verify_server_address(struct sockaddr *addr)
605{
606 switch (addr->sa_family) {
607 case AF_INET: {
608 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
609 if (sa->sin_addr.s_addr != INADDR_ANY)
610 return 1;
611 break;
612 }
613 }
614
615 return 0;
616}
617
618/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400619 * Error-check and convert a string of mount options from user space into
620 * a data structure
621 */
622static int nfs_parse_mount_options(char *raw,
623 struct nfs_parsed_mount_data *mnt)
624{
625 char *p, *string;
626
627 if (!raw) {
628 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
629 return 1;
630 }
631 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
632
633 while ((p = strsep(&raw, ",")) != NULL) {
634 substring_t args[MAX_OPT_ARGS];
635 int option, token;
636
637 if (!*p)
638 continue;
639
640 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
641
642 token = match_token(p, nfs_mount_option_tokens, args);
643 switch (token) {
644 case Opt_soft:
645 mnt->flags |= NFS_MOUNT_SOFT;
646 break;
647 case Opt_hard:
648 mnt->flags &= ~NFS_MOUNT_SOFT;
649 break;
650 case Opt_intr:
651 mnt->flags |= NFS_MOUNT_INTR;
652 break;
653 case Opt_nointr:
654 mnt->flags &= ~NFS_MOUNT_INTR;
655 break;
656 case Opt_posix:
657 mnt->flags |= NFS_MOUNT_POSIX;
658 break;
659 case Opt_noposix:
660 mnt->flags &= ~NFS_MOUNT_POSIX;
661 break;
662 case Opt_cto:
663 mnt->flags &= ~NFS_MOUNT_NOCTO;
664 break;
665 case Opt_nocto:
666 mnt->flags |= NFS_MOUNT_NOCTO;
667 break;
668 case Opt_ac:
669 mnt->flags &= ~NFS_MOUNT_NOAC;
670 break;
671 case Opt_noac:
672 mnt->flags |= NFS_MOUNT_NOAC;
673 break;
674 case Opt_lock:
675 mnt->flags &= ~NFS_MOUNT_NONLM;
676 break;
677 case Opt_nolock:
678 mnt->flags |= NFS_MOUNT_NONLM;
679 break;
680 case Opt_v2:
681 mnt->flags &= ~NFS_MOUNT_VER3;
682 break;
683 case Opt_v3:
684 mnt->flags |= NFS_MOUNT_VER3;
685 break;
686 case Opt_udp:
687 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400688 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400689 mnt->timeo = 7;
690 mnt->retrans = 5;
691 break;
692 case Opt_tcp:
693 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400694 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400695 mnt->timeo = 600;
696 mnt->retrans = 2;
697 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400698 case Opt_rdma:
699 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
700 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
701 mnt->timeo = 600;
702 mnt->retrans = 2;
703 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400704 case Opt_acl:
705 mnt->flags &= ~NFS_MOUNT_NOACL;
706 break;
707 case Opt_noacl:
708 mnt->flags |= NFS_MOUNT_NOACL;
709 break;
710 case Opt_rdirplus:
711 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
712 break;
713 case Opt_nordirplus:
714 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
715 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400716 case Opt_sharecache:
717 mnt->flags &= ~NFS_MOUNT_UNSHARED;
718 break;
719 case Opt_nosharecache:
720 mnt->flags |= NFS_MOUNT_UNSHARED;
721 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400722
723 case Opt_port:
724 if (match_int(args, &option))
725 return 0;
726 if (option < 0 || option > 65535)
727 return 0;
Al Viro410896442007-07-22 10:59:06 +0100728 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400729 break;
730 case Opt_rsize:
731 if (match_int(args, &mnt->rsize))
732 return 0;
733 break;
734 case Opt_wsize:
735 if (match_int(args, &mnt->wsize))
736 return 0;
737 break;
738 case Opt_bsize:
739 if (match_int(args, &option))
740 return 0;
741 if (option < 0)
742 return 0;
743 mnt->bsize = option;
744 break;
745 case Opt_timeo:
746 if (match_int(args, &mnt->timeo))
747 return 0;
748 break;
749 case Opt_retrans:
750 if (match_int(args, &mnt->retrans))
751 return 0;
752 break;
753 case Opt_acregmin:
754 if (match_int(args, &mnt->acregmin))
755 return 0;
756 break;
757 case Opt_acregmax:
758 if (match_int(args, &mnt->acregmax))
759 return 0;
760 break;
761 case Opt_acdirmin:
762 if (match_int(args, &mnt->acdirmin))
763 return 0;
764 break;
765 case Opt_acdirmax:
766 if (match_int(args, &mnt->acdirmax))
767 return 0;
768 break;
769 case Opt_actimeo:
770 if (match_int(args, &option))
771 return 0;
772 if (option < 0)
773 return 0;
774 mnt->acregmin =
775 mnt->acregmax =
776 mnt->acdirmin =
777 mnt->acdirmax = option;
778 break;
779 case Opt_namelen:
780 if (match_int(args, &mnt->namlen))
781 return 0;
782 break;
783 case Opt_mountport:
784 if (match_int(args, &option))
785 return 0;
786 if (option < 0 || option > 65535)
787 return 0;
788 mnt->mount_server.port = option;
789 break;
790 case Opt_mountprog:
791 if (match_int(args, &option))
792 return 0;
793 if (option < 0)
794 return 0;
795 mnt->mount_server.program = option;
796 break;
797 case Opt_mountvers:
798 if (match_int(args, &option))
799 return 0;
800 if (option < 0)
801 return 0;
802 mnt->mount_server.version = option;
803 break;
804 case Opt_nfsprog:
805 if (match_int(args, &option))
806 return 0;
807 if (option < 0)
808 return 0;
809 mnt->nfs_server.program = option;
810 break;
811 case Opt_nfsvers:
812 if (match_int(args, &option))
813 return 0;
814 switch (option) {
815 case 2:
816 mnt->flags &= ~NFS_MOUNT_VER3;
817 break;
818 case 3:
819 mnt->flags |= NFS_MOUNT_VER3;
820 break;
821 default:
822 goto out_unrec_vers;
823 }
824 break;
825
826 case Opt_sec:
827 string = match_strdup(args);
828 if (string == NULL)
829 goto out_nomem;
830 token = match_token(string, nfs_secflavor_tokens, args);
831 kfree(string);
832
833 /*
834 * The flags setting is for v2/v3. The flavor_len
835 * setting is for v4. v2/v3 also need to know the
836 * difference between NULL and UNIX.
837 */
838 switch (token) {
839 case Opt_sec_none:
840 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
841 mnt->auth_flavor_len = 0;
842 mnt->auth_flavors[0] = RPC_AUTH_NULL;
843 break;
844 case Opt_sec_sys:
845 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
846 mnt->auth_flavor_len = 0;
847 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
848 break;
849 case Opt_sec_krb5:
850 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
851 mnt->auth_flavor_len = 1;
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
853 break;
854 case Opt_sec_krb5i:
855 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
856 mnt->auth_flavor_len = 1;
857 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
858 break;
859 case Opt_sec_krb5p:
860 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
861 mnt->auth_flavor_len = 1;
862 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
863 break;
864 case Opt_sec_lkey:
865 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
866 mnt->auth_flavor_len = 1;
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
868 break;
869 case Opt_sec_lkeyi:
870 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
871 mnt->auth_flavor_len = 1;
872 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
873 break;
874 case Opt_sec_lkeyp:
875 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
878 break;
879 case Opt_sec_spkm:
880 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
881 mnt->auth_flavor_len = 1;
882 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
883 break;
884 case Opt_sec_spkmi:
885 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
886 mnt->auth_flavor_len = 1;
887 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
888 break;
889 case Opt_sec_spkmp:
890 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
891 mnt->auth_flavor_len = 1;
892 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
893 break;
894 default:
895 goto out_unrec_sec;
896 }
897 break;
898 case Opt_proto:
899 string = match_strdup(args);
900 if (string == NULL)
901 goto out_nomem;
902 token = match_token(string,
903 nfs_xprt_protocol_tokens, args);
904 kfree(string);
905
906 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400907 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400908 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400909 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400910 mnt->timeo = 7;
911 mnt->retrans = 5;
912 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400913 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400914 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400915 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400916 mnt->timeo = 600;
917 mnt->retrans = 2;
918 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400919 case Opt_xprt_rdma:
920 /* vector side protocols to TCP */
921 mnt->flags |= NFS_MOUNT_TCP;
922 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
923 mnt->timeo = 600;
924 mnt->retrans = 2;
925 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400926 default:
927 goto out_unrec_xprt;
928 }
929 break;
930 case Opt_mountproto:
931 string = match_strdup(args);
932 if (string == NULL)
933 goto out_nomem;
934 token = match_token(string,
935 nfs_xprt_protocol_tokens, args);
936 kfree(string);
937
938 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400939 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400940 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400941 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400942 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400943 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400944 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400945 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400946 default:
947 goto out_unrec_xprt;
948 }
949 break;
950 case Opt_addr:
951 string = match_strdup(args);
952 if (string == NULL)
953 goto out_nomem;
954 mnt->nfs_server.address.sin_family = AF_INET;
955 mnt->nfs_server.address.sin_addr.s_addr =
956 in_aton(string);
957 kfree(string);
958 break;
959 case Opt_clientaddr:
960 string = match_strdup(args);
961 if (string == NULL)
962 goto out_nomem;
963 mnt->client_address = string;
964 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400965 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400966 string = match_strdup(args);
967 if (string == NULL)
968 goto out_nomem;
969 mnt->mount_server.address.sin_family = AF_INET;
970 mnt->mount_server.address.sin_addr.s_addr =
971 in_aton(string);
972 kfree(string);
973 break;
974
975 case Opt_userspace:
976 case Opt_deprecated:
977 break;
978
979 default:
980 goto out_unknown;
981 }
982 }
983
984 return 1;
985
986out_nomem:
987 printk(KERN_INFO "NFS: not enough memory to parse option\n");
988 return 0;
989
990out_unrec_vers:
991 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
992 return 0;
993
994out_unrec_xprt:
995 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
996 return 0;
997
998out_unrec_sec:
999 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1000 return 0;
1001
1002out_unknown:
1003 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1004 return 0;
1005}
1006
1007/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001008 * Use the remote server's MOUNT service to request the NFS file handle
1009 * corresponding to the provided path.
1010 */
1011static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1012 struct nfs_fh *root_fh)
1013{
1014 struct sockaddr_in sin;
1015 int status;
1016
1017 if (args->mount_server.version == 0) {
1018 if (args->flags & NFS_MOUNT_VER3)
1019 args->mount_server.version = NFS_MNT3_VERSION;
1020 else
1021 args->mount_server.version = NFS_MNT_VERSION;
1022 }
1023
1024 /*
1025 * Construct the mount server's address.
1026 */
1027 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1028 sin = args->mount_server.address;
1029 else
1030 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001031 /*
1032 * autobind will be used if mount_server.port == 0
1033 */
1034 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001035
1036 /*
1037 * Now ask the mount server to map our export path
1038 * to a file handle.
1039 */
1040 status = nfs_mount((struct sockaddr *) &sin,
1041 sizeof(sin),
1042 args->nfs_server.hostname,
1043 args->nfs_server.export_path,
1044 args->mount_server.version,
1045 args->mount_server.protocol,
1046 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001047 if (status == 0)
1048 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001049
Chuck Leverefd83402007-09-11 18:00:58 -04001050 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1051 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001052 return status;
1053}
1054
1055/*
David Howells54ceac42006-08-22 20:06:13 -04001056 * Validate the NFS2/NFS3 mount data
1057 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001058 *
1059 * For option strings, user space handles the following behaviors:
1060 *
1061 * + DNS: mapping server host name to IP address ("addr=" option)
1062 *
1063 * + failure mode: how to behave if a mount request can't be handled
1064 * immediately ("fg/bg" option)
1065 *
1066 * + retry: how often to retry a mount request ("retry=" option)
1067 *
1068 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1069 * mountproto=tcp after mountproto=udp, and so on
1070 *
1071 * XXX: as far as I can tell, changing the NFS program number is not
1072 * supported in the NFS client.
David Howellsf7b422b2006-06-09 09:34:33 -04001073 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001074static int nfs_validate_mount_data(void *options,
1075 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001076 struct nfs_fh *mntfh,
1077 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001078{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001079 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001080
Russell Kingf16c9602007-11-16 22:13:24 +00001081 memset(args, 0, sizeof(*args));
1082
Chuck Lever5df36e72007-07-01 12:12:56 -04001083 if (data == NULL)
1084 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001085
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001086 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1087 args->rsize = NFS_MAX_FILE_IO_SIZE;
1088 args->wsize = NFS_MAX_FILE_IO_SIZE;
1089 args->timeo = 600;
1090 args->retrans = 2;
1091 args->acregmin = 3;
1092 args->acregmax = 60;
1093 args->acdirmin = 30;
1094 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001095 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001096 args->mount_server.program = NFS_MNT_PROGRAM;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001097 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001098 args->nfs_server.program = NFS_PROGRAM;
1099
David Howellsf7b422b2006-06-09 09:34:33 -04001100 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001101 case 1:
1102 data->namlen = 0;
1103 case 2:
1104 data->bsize = 0;
1105 case 3:
1106 if (data->flags & NFS_MOUNT_VER3)
1107 goto out_no_v3;
1108 data->root.size = NFS2_FHSIZE;
1109 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1110 case 4:
1111 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1112 goto out_no_sec;
1113 case 5:
1114 memset(data->context, 0, sizeof(data->context));
1115 case 6:
1116 if (data->flags & NFS_MOUNT_VER3)
1117 mntfh->size = data->root.size;
1118 else
1119 mntfh->size = NFS2_FHSIZE;
1120
1121 if (mntfh->size > sizeof(mntfh->data))
1122 goto out_invalid_fh;
1123
1124 memcpy(mntfh->data, data->root.data, mntfh->size);
1125 if (mntfh->size < sizeof(mntfh->data))
1126 memset(mntfh->data + mntfh->size, 0,
1127 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001128
1129 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1130 goto out_no_address;
1131
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001132 /*
1133 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1134 * can deal with.
1135 */
1136 args->flags = data->flags;
1137 args->rsize = data->rsize;
1138 args->wsize = data->wsize;
1139 args->flags = data->flags;
1140 args->timeo = data->timeo;
1141 args->retrans = data->retrans;
1142 args->acregmin = data->acregmin;
1143 args->acregmax = data->acregmax;
1144 args->acdirmin = data->acdirmin;
1145 args->acdirmax = data->acdirmax;
1146 args->nfs_server.address = data->addr;
1147 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001148 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001149 /* N.B. caller will free nfs_server.hostname in all cases */
1150 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1151 args->namlen = data->namlen;
1152 args->bsize = data->bsize;
1153 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001154 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001155 default: {
1156 unsigned int len;
1157 char *c;
1158 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001159
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001160 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001161 return -EINVAL;
1162
Chuck Lever6e88e062007-09-24 15:39:50 -04001163 if (!nfs_verify_server_address((struct sockaddr *)
1164 &args->nfs_server.address))
1165 goto out_no_address;
1166
Chuck Lever136d5582007-07-01 12:13:54 -04001167 c = strchr(dev_name, ':');
1168 if (c == NULL)
1169 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001170 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001171 /* N.B. caller will free nfs_server.hostname in all cases */
1172 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001173
1174 c++;
1175 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001176 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001177 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001178
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001179 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001180 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001181 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001182
Chuck Lever136d5582007-07-01 12:13:54 -04001183 break;
1184 }
David Howellsf7b422b2006-06-09 09:34:33 -04001185 }
David Howells54ceac42006-08-22 20:06:13 -04001186
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001187 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1188 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001189
David Howellsf7b422b2006-06-09 09:34:33 -04001190#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001191 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001192 goto out_v3_not_compiled;
1193#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001194
David Howells54ceac42006-08-22 20:06:13 -04001195 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001196
1197out_no_data:
1198 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1199 return -EINVAL;
1200
1201out_no_v3:
1202 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1203 data->version);
1204 return -EINVAL;
1205
1206out_no_sec:
1207 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1208 return -EINVAL;
1209
Chuck Lever5df36e72007-07-01 12:12:56 -04001210#ifndef CONFIG_NFS_V3
1211out_v3_not_compiled:
1212 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1213 return -EPROTONOSUPPORT;
1214#endif /* !CONFIG_NFS_V3 */
1215
1216out_no_address:
1217 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1218 return -EINVAL;
1219
1220out_invalid_fh:
1221 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1222 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001223}
1224
1225/*
1226 * Initialise the common bits of the superblock
1227 */
1228static inline void nfs_initialise_sb(struct super_block *sb)
1229{
1230 struct nfs_server *server = NFS_SB(sb);
1231
1232 sb->s_magic = NFS_SUPER_MAGIC;
1233
1234 /* We probably want something more informative here */
1235 snprintf(sb->s_id, sizeof(sb->s_id),
1236 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1237
1238 if (sb->s_blocksize == 0)
1239 sb->s_blocksize = nfs_block_bits(server->wsize,
1240 &sb->s_blocksize_bits);
1241
1242 if (server->flags & NFS_MOUNT_NOAC)
1243 sb->s_flags |= MS_SYNCHRONOUS;
1244
1245 nfs_super_set_maxbytes(sb, server->maxfilesize);
1246}
1247
1248/*
1249 * Finish setting up an NFS2/3 superblock
1250 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001251static void nfs_fill_super(struct super_block *sb,
1252 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001253{
1254 struct nfs_server *server = NFS_SB(sb);
1255
1256 sb->s_blocksize_bits = 0;
1257 sb->s_blocksize = 0;
1258 if (data->bsize)
1259 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1260
1261 if (server->flags & NFS_MOUNT_VER3) {
1262 /* The VFS shouldn't apply the umask to mode bits. We will do
1263 * so ourselves when necessary.
1264 */
1265 sb->s_flags |= MS_POSIXACL;
1266 sb->s_time_gran = 1;
1267 }
1268
1269 sb->s_op = &nfs_sops;
1270 nfs_initialise_sb(sb);
1271}
1272
1273/*
1274 * Finish setting up a cloned NFS2/3 superblock
1275 */
1276static void nfs_clone_super(struct super_block *sb,
1277 const struct super_block *old_sb)
1278{
1279 struct nfs_server *server = NFS_SB(sb);
1280
1281 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1282 sb->s_blocksize = old_sb->s_blocksize;
1283 sb->s_maxbytes = old_sb->s_maxbytes;
1284
1285 if (server->flags & NFS_MOUNT_VER3) {
1286 /* The VFS shouldn't apply the umask to mode bits. We will do
1287 * so ourselves when necessary.
1288 */
1289 sb->s_flags |= MS_POSIXACL;
1290 sb->s_time_gran = 1;
1291 }
1292
1293 sb->s_op = old_sb->s_op;
1294 nfs_initialise_sb(sb);
1295}
1296
Trond Myklebust275a5d22007-05-16 16:53:28 -04001297#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1298
1299static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1300{
1301 const struct nfs_server *a = s->s_fs_info;
1302 const struct rpc_clnt *clnt_a = a->client;
1303 const struct rpc_clnt *clnt_b = b->client;
1304
1305 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1306 goto Ebusy;
1307 if (a->nfs_client != b->nfs_client)
1308 goto Ebusy;
1309 if (a->flags != b->flags)
1310 goto Ebusy;
1311 if (a->wsize != b->wsize)
1312 goto Ebusy;
1313 if (a->rsize != b->rsize)
1314 goto Ebusy;
1315 if (a->acregmin != b->acregmin)
1316 goto Ebusy;
1317 if (a->acregmax != b->acregmax)
1318 goto Ebusy;
1319 if (a->acdirmin != b->acdirmin)
1320 goto Ebusy;
1321 if (a->acdirmax != b->acdirmax)
1322 goto Ebusy;
1323 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1324 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001325 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001326Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001327 return 0;
1328}
1329
1330struct nfs_sb_mountdata {
1331 struct nfs_server *server;
1332 int mntflags;
1333};
1334
1335static int nfs_set_super(struct super_block *s, void *data)
1336{
1337 struct nfs_sb_mountdata *sb_mntdata = data;
1338 struct nfs_server *server = sb_mntdata->server;
1339 int ret;
1340
1341 s->s_flags = sb_mntdata->mntflags;
1342 s->s_fs_info = server;
1343 ret = set_anon_super(s, server);
1344 if (ret == 0)
1345 server->s_dev = s->s_dev;
1346 return ret;
1347}
1348
1349static int nfs_compare_super(struct super_block *sb, void *data)
1350{
1351 struct nfs_sb_mountdata *sb_mntdata = data;
1352 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1353 int mntflags = sb_mntdata->mntflags;
1354
1355 if (memcmp(&old->nfs_client->cl_addr,
1356 &server->nfs_client->cl_addr,
1357 sizeof(old->nfs_client->cl_addr)) != 0)
1358 return 0;
1359 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1360 if (old->flags & NFS_MOUNT_UNSHARED)
1361 return 0;
1362 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1363 return 0;
1364 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001365}
1366
David Howells54ceac42006-08-22 20:06:13 -04001367static int nfs_get_sb(struct file_system_type *fs_type,
1368 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1369{
1370 struct nfs_server *server = NULL;
1371 struct super_block *s;
1372 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001373 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001374 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001375 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001376 struct nfs_sb_mountdata sb_mntdata = {
1377 .mntflags = flags,
1378 };
David Howells54ceac42006-08-22 20:06:13 -04001379 int error;
1380
1381 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001382 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001383 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001384 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001385
1386 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001387 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001388 if (IS_ERR(server)) {
1389 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001390 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001391 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001392 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001393
Trond Myklebust75180df2007-05-16 16:53:28 -04001394 if (server->flags & NFS_MOUNT_UNSHARED)
1395 compare_super = NULL;
1396
David Howells54ceac42006-08-22 20:06:13 -04001397 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001398 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001399 if (IS_ERR(s)) {
1400 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001401 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001402 }
1403
David Howells54ceac42006-08-22 20:06:13 -04001404 if (s->s_fs_info != server) {
1405 nfs_free_server(server);
1406 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001407 }
David Howells54ceac42006-08-22 20:06:13 -04001408
1409 if (!s->s_root) {
1410 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001411 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001412 }
1413
1414 mntroot = nfs_get_root(s, &mntfh);
1415 if (IS_ERR(mntroot)) {
1416 error = PTR_ERR(mntroot);
1417 goto error_splat_super;
1418 }
1419
David Howellsf7b422b2006-06-09 09:34:33 -04001420 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001421 mnt->mnt_sb = s;
1422 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001423 error = 0;
1424
1425out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001426 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001427 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001428
David Howells54ceac42006-08-22 20:06:13 -04001429out_err_nosb:
1430 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001431 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001432
1433error_splat_super:
1434 up_write(&s->s_umount);
1435 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001436 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001437}
1438
David Howells54ceac42006-08-22 20:06:13 -04001439/*
1440 * Destroy an NFS2/3 superblock
1441 */
David Howellsf7b422b2006-06-09 09:34:33 -04001442static void nfs_kill_super(struct super_block *s)
1443{
1444 struct nfs_server *server = NFS_SB(s);
1445
1446 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001447 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001448}
1449
David Howells54ceac42006-08-22 20:06:13 -04001450/*
1451 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1452 */
1453static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1454 const char *dev_name, void *raw_data,
1455 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001456{
1457 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001458 struct super_block *s;
1459 struct nfs_server *server;
1460 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001461 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001462 struct nfs_sb_mountdata sb_mntdata = {
1463 .mntflags = flags,
1464 };
David Howells54ceac42006-08-22 20:06:13 -04001465 int error;
1466
1467 dprintk("--> nfs_xdev_get_sb()\n");
1468
1469 /* create a new volume representation */
1470 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1471 if (IS_ERR(server)) {
1472 error = PTR_ERR(server);
1473 goto out_err_noserver;
1474 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001475 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001476
Trond Myklebust75180df2007-05-16 16:53:28 -04001477 if (server->flags & NFS_MOUNT_UNSHARED)
1478 compare_super = NULL;
1479
David Howells54ceac42006-08-22 20:06:13 -04001480 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001481 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001482 if (IS_ERR(s)) {
1483 error = PTR_ERR(s);
1484 goto out_err_nosb;
1485 }
1486
1487 if (s->s_fs_info != server) {
1488 nfs_free_server(server);
1489 server = NULL;
1490 }
1491
1492 if (!s->s_root) {
1493 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001494 nfs_clone_super(s, data->sb);
1495 }
1496
1497 mntroot = nfs_get_root(s, data->fh);
1498 if (IS_ERR(mntroot)) {
1499 error = PTR_ERR(mntroot);
1500 goto error_splat_super;
1501 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001502 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001503 dput(mntroot);
1504 error = -ESTALE;
1505 goto error_splat_super;
1506 }
David Howells54ceac42006-08-22 20:06:13 -04001507
1508 s->s_flags |= MS_ACTIVE;
1509 mnt->mnt_sb = s;
1510 mnt->mnt_root = mntroot;
1511
1512 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1513 return 0;
1514
1515out_err_nosb:
1516 nfs_free_server(server);
1517out_err_noserver:
1518 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1519 return error;
1520
1521error_splat_super:
1522 up_write(&s->s_umount);
1523 deactivate_super(s);
1524 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1525 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001526}
1527
1528#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001529
1530/*
1531 * Finish setting up a cloned NFS4 superblock
1532 */
1533static void nfs4_clone_super(struct super_block *sb,
1534 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001535{
David Howells54ceac42006-08-22 20:06:13 -04001536 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1537 sb->s_blocksize = old_sb->s_blocksize;
1538 sb->s_maxbytes = old_sb->s_maxbytes;
1539 sb->s_time_gran = 1;
1540 sb->s_op = old_sb->s_op;
1541 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001542}
1543
1544/*
1545 * Set up an NFS4 superblock
1546 */
David Howells54ceac42006-08-22 20:06:13 -04001547static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001548{
David Howellsf7b422b2006-06-09 09:34:33 -04001549 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001550 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001551 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001552}
1553
David Howells54ceac42006-08-22 20:06:13 -04001554/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001555 * Validate NFSv4 mount options
1556 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001557static int nfs4_validate_mount_data(void *options,
1558 struct nfs_parsed_mount_data *args,
1559 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001560{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001561 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001562 char *c;
1563
Russell Kingf16c9602007-11-16 22:13:24 +00001564 memset(args, 0, sizeof(*args));
1565
Chuck Leverf0768eb2007-07-01 12:13:01 -04001566 if (data == NULL)
1567 goto out_no_data;
1568
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001569 args->rsize = NFS_MAX_FILE_IO_SIZE;
1570 args->wsize = NFS_MAX_FILE_IO_SIZE;
1571 args->timeo = 600;
1572 args->retrans = 2;
1573 args->acregmin = 3;
1574 args->acregmax = 60;
1575 args->acdirmin = 30;
1576 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001577 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001578
Chuck Leverf0768eb2007-07-01 12:13:01 -04001579 switch (data->version) {
1580 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001581 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001582 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001583 if (copy_from_user(&args->nfs_server.address,
1584 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001585 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001586 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001587 if (args->nfs_server.address.sin_port == 0)
1588 args->nfs_server.address.sin_port = htons(NFS_PORT);
1589 if (!nfs_verify_server_address((struct sockaddr *)
1590 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001591 goto out_no_address;
1592
1593 switch (data->auth_flavourlen) {
1594 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001595 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001596 break;
1597 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001598 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001599 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001600 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001601 return -EFAULT;
1602 break;
1603 default:
1604 goto out_inval_auth;
1605 }
1606
1607 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1608 if (IS_ERR(c))
1609 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001610 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001611
1612 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1613 if (IS_ERR(c))
1614 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001615 args->nfs_server.export_path = c;
1616 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001617
1618 c = strndup_user(data->client_addr.data, 16);
1619 if (IS_ERR(c))
1620 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001621 args->client_address = c;
1622
1623 /*
1624 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1625 * can deal with.
1626 */
1627
1628 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1629 args->rsize = data->rsize;
1630 args->wsize = data->wsize;
1631 args->timeo = data->timeo;
1632 args->retrans = data->retrans;
1633 args->acregmin = data->acregmin;
1634 args->acregmax = data->acregmax;
1635 args->acdirmin = data->acdirmin;
1636 args->acdirmax = data->acdirmax;
1637 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001638
1639 break;
Chuck Lever80071222007-07-01 12:13:59 -04001640 default: {
1641 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001642
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001643 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001644 return -EINVAL;
1645
1646 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001647 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001648 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001649
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001650 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001651 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001652 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001653 break;
1654 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001655 break;
1656 default:
1657 goto out_inval_auth;
1658 }
1659
1660 /*
Chuck Lever80071222007-07-01 12:13:59 -04001661 * Split "dev_name" into "hostname:mntpath".
1662 */
1663 c = strchr(dev_name, ':');
1664 if (c == NULL)
1665 return -EINVAL;
1666 /* while calculating len, pretend ':' is '\0' */
1667 len = c - dev_name;
1668 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001669 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001670 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1671 if (args->nfs_server.hostname == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001672 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001673 strncpy(args->nfs_server.hostname, dev_name, len - 1);
Chuck Lever80071222007-07-01 12:13:59 -04001674
1675 c++; /* step over the ':' */
1676 len = strlen(c);
1677 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001678 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001679 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1680 if (args->nfs_server.export_path == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001681 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001682 strncpy(args->nfs_server.export_path, c, len);
Chuck Lever80071222007-07-01 12:13:59 -04001683
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001684 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001685
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001686 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001687 goto out_no_client_address;
1688
Chuck Lever80071222007-07-01 12:13:59 -04001689 break;
1690 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001691 }
1692
1693 return 0;
1694
1695out_no_data:
1696 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1697 return -EINVAL;
1698
1699out_inval_auth:
1700 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1701 data->auth_flavourlen);
1702 return -EINVAL;
1703
1704out_no_address:
1705 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1706 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001707
1708out_no_client_address:
1709 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1710 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001711}
1712
1713/*
David Howells54ceac42006-08-22 20:06:13 -04001714 * Get the superblock for an NFS4 mountpoint
1715 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001716static int nfs4_get_sb(struct file_system_type *fs_type,
1717 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001718{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001719 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001720 struct super_block *s;
1721 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001722 struct nfs_fh mntfh;
1723 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001724 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001725 struct nfs_sb_mountdata sb_mntdata = {
1726 .mntflags = flags,
1727 };
David Howells54ceac42006-08-22 20:06:13 -04001728 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001729
Chuck Leverf0768eb2007-07-01 12:13:01 -04001730 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001731 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001732 if (error < 0)
1733 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001734
David Howells54ceac42006-08-22 20:06:13 -04001735 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001736 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001737 if (IS_ERR(server)) {
1738 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001739 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001740 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001741 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001742
Trond Myklebust75180df2007-05-16 16:53:28 -04001743 if (server->flags & NFS4_MOUNT_UNSHARED)
1744 compare_super = NULL;
1745
David Howells54ceac42006-08-22 20:06:13 -04001746 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001747 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001748 if (IS_ERR(s)) {
1749 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001750 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001751 }
1752
Trond Myklebust5dd31772006-08-24 01:03:05 -04001753 if (s->s_fs_info != server) {
1754 nfs_free_server(server);
1755 server = NULL;
1756 }
1757
David Howells54ceac42006-08-22 20:06:13 -04001758 if (!s->s_root) {
1759 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001760 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001761 }
David Howellsf7b422b2006-06-09 09:34:33 -04001762
David Howells54ceac42006-08-22 20:06:13 -04001763 mntroot = nfs4_get_root(s, &mntfh);
1764 if (IS_ERR(mntroot)) {
1765 error = PTR_ERR(mntroot);
1766 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001767 }
David Howells54ceac42006-08-22 20:06:13 -04001768
David Howellsf7b422b2006-06-09 09:34:33 -04001769 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001770 mnt->mnt_sb = s;
1771 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001772 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001773
Chuck Lever29eb9812007-07-01 12:12:30 -04001774out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001775 kfree(data.client_address);
1776 kfree(data.nfs_server.export_path);
1777 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001778 return error;
David Howells54ceac42006-08-22 20:06:13 -04001779
Chuck Lever29eb9812007-07-01 12:12:30 -04001780out_free:
1781 nfs_free_server(server);
1782 goto out;
1783
David Howells54ceac42006-08-22 20:06:13 -04001784error_splat_super:
1785 up_write(&s->s_umount);
1786 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001787 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001788}
1789
1790static void nfs4_kill_super(struct super_block *sb)
1791{
1792 struct nfs_server *server = NFS_SB(sb);
1793
1794 nfs_return_all_delegations(sb);
1795 kill_anon_super(sb);
1796
1797 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001798 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001799}
1800
1801/*
David Howells54ceac42006-08-22 20:06:13 -04001802 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001803 */
David Howells54ceac42006-08-22 20:06:13 -04001804static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1805 const char *dev_name, void *raw_data,
1806 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001807{
1808 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001809 struct super_block *s;
1810 struct nfs_server *server;
1811 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001812 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001813 struct nfs_sb_mountdata sb_mntdata = {
1814 .mntflags = flags,
1815 };
David Howells54ceac42006-08-22 20:06:13 -04001816 int error;
1817
1818 dprintk("--> nfs4_xdev_get_sb()\n");
1819
1820 /* create a new volume representation */
1821 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1822 if (IS_ERR(server)) {
1823 error = PTR_ERR(server);
1824 goto out_err_noserver;
1825 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001826 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001827
Trond Myklebust75180df2007-05-16 16:53:28 -04001828 if (server->flags & NFS4_MOUNT_UNSHARED)
1829 compare_super = NULL;
1830
David Howells54ceac42006-08-22 20:06:13 -04001831 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001832 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001833 if (IS_ERR(s)) {
1834 error = PTR_ERR(s);
1835 goto out_err_nosb;
1836 }
1837
1838 if (s->s_fs_info != server) {
1839 nfs_free_server(server);
1840 server = NULL;
1841 }
1842
1843 if (!s->s_root) {
1844 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001845 nfs4_clone_super(s, data->sb);
1846 }
1847
1848 mntroot = nfs4_get_root(s, data->fh);
1849 if (IS_ERR(mntroot)) {
1850 error = PTR_ERR(mntroot);
1851 goto error_splat_super;
1852 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001853 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1854 dput(mntroot);
1855 error = -ESTALE;
1856 goto error_splat_super;
1857 }
David Howells54ceac42006-08-22 20:06:13 -04001858
1859 s->s_flags |= MS_ACTIVE;
1860 mnt->mnt_sb = s;
1861 mnt->mnt_root = mntroot;
1862
1863 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1864 return 0;
1865
1866out_err_nosb:
1867 nfs_free_server(server);
1868out_err_noserver:
1869 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1870 return error;
1871
1872error_splat_super:
1873 up_write(&s->s_umount);
1874 deactivate_super(s);
1875 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1876 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001877}
1878
David Howells54ceac42006-08-22 20:06:13 -04001879/*
1880 * Create an NFS4 server record on referral traversal
1881 */
1882static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1883 const char *dev_name, void *raw_data,
1884 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001885{
1886 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001887 struct super_block *s;
1888 struct nfs_server *server;
1889 struct dentry *mntroot;
1890 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001891 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001892 struct nfs_sb_mountdata sb_mntdata = {
1893 .mntflags = flags,
1894 };
David Howells54ceac42006-08-22 20:06:13 -04001895 int error;
1896
1897 dprintk("--> nfs4_referral_get_sb()\n");
1898
1899 /* create a new volume representation */
1900 server = nfs4_create_referral_server(data, &mntfh);
1901 if (IS_ERR(server)) {
1902 error = PTR_ERR(server);
1903 goto out_err_noserver;
1904 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001905 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001906
Trond Myklebust75180df2007-05-16 16:53:28 -04001907 if (server->flags & NFS4_MOUNT_UNSHARED)
1908 compare_super = NULL;
1909
David Howells54ceac42006-08-22 20:06:13 -04001910 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001911 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001912 if (IS_ERR(s)) {
1913 error = PTR_ERR(s);
1914 goto out_err_nosb;
1915 }
1916
1917 if (s->s_fs_info != server) {
1918 nfs_free_server(server);
1919 server = NULL;
1920 }
1921
1922 if (!s->s_root) {
1923 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001924 nfs4_fill_super(s);
1925 }
1926
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001927 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001928 if (IS_ERR(mntroot)) {
1929 error = PTR_ERR(mntroot);
1930 goto error_splat_super;
1931 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001932 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1933 dput(mntroot);
1934 error = -ESTALE;
1935 goto error_splat_super;
1936 }
David Howells54ceac42006-08-22 20:06:13 -04001937
1938 s->s_flags |= MS_ACTIVE;
1939 mnt->mnt_sb = s;
1940 mnt->mnt_root = mntroot;
1941
1942 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1943 return 0;
1944
1945out_err_nosb:
1946 nfs_free_server(server);
1947out_err_noserver:
1948 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1949 return error;
1950
1951error_splat_super:
1952 up_write(&s->s_umount);
1953 deactivate_super(s);
1954 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1955 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001956}
1957
David Howells54ceac42006-08-22 20:06:13 -04001958#endif /* CONFIG_NFS_V4 */