blob: 038b20b38b220dddd54accdfb9725772a1b937f9 [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>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
David Howellsf7b422b2006-06-09 09:34:33 -040050#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080051#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040052#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053
54#include <asm/system.h>
55#include <asm/uaccess.h>
56
57#include "nfs4_fs.h"
58#include "callback.h"
59#include "delegation.h"
60#include "iostat.h"
61#include "internal.h"
62
63#define NFSDBG_FACILITY NFSDBG_VFS
64
Chuck Leverbf0fd762007-07-01 12:13:44 -040065enum {
66 /* Mount options that take no arguments */
67 Opt_soft, Opt_hard,
68 Opt_intr, Opt_nointr,
69 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac,
72 Opt_lock, Opt_nolock,
73 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040074 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075 Opt_acl, Opt_noacl,
76 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040077 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078
79 /* Mount options that take integer arguments */
80 Opt_port,
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
85 Opt_actimeo,
86 Opt_namelen,
87 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040088 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040089 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take string arguments */
92 Opt_sec, Opt_proto, Opt_mountproto,
Chuck Lever0ac83772007-09-11 18:01:04 -040093 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
97
98 Opt_err
99};
100
101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
110 { Opt_cto, "cto" },
111 { Opt_nocto, "nocto" },
112 { Opt_ac, "ac" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
116 { Opt_v2, "v2" },
117 { Opt_v3, "v3" },
118 { Opt_udp, "udp" },
119 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400120 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_acl, "acl" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { 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
Chuck Lever5d8515c2007-12-10 14:57:16 -0500496 seq_printf(m, ",addr=%s",
497 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
498 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400499
500 return 0;
501}
502
503/*
504 * Present statistical information for this VFS mountpoint
505 */
506static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
507{
508 int i, cpu;
509 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
510 struct rpc_auth *auth = nfss->client->cl_auth;
511 struct nfs_iostats totals = { };
512
513 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
514
515 /*
516 * Display all mount option settings
517 */
518 seq_printf(m, "\n\topts:\t");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
522 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
523 nfs_show_mount_options(m, nfss, 1);
524
525 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
526
527 seq_printf(m, "\n\tcaps:\t");
528 seq_printf(m, "caps=0x%x", nfss->caps);
529 seq_printf(m, ",wtmult=%d", nfss->wtmult);
530 seq_printf(m, ",dtsize=%d", nfss->dtsize);
531 seq_printf(m, ",bsize=%d", nfss->bsize);
532 seq_printf(m, ",namelen=%d", nfss->namelen);
533
534#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500535 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400536 seq_printf(m, "\n\tnfsv4:\t");
537 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
538 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
539 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
540 }
541#endif
542
543 /*
544 * Display security flavor in effect for this mount
545 */
546 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
547 if (auth->au_flavor)
548 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
549
550 /*
551 * Display superblock I/O counters
552 */
553 for_each_possible_cpu(cpu) {
554 struct nfs_iostats *stats;
555
556 preempt_disable();
557 stats = per_cpu_ptr(nfss->io_stats, cpu);
558
559 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
560 totals.events[i] += stats->events[i];
561 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
562 totals.bytes[i] += stats->bytes[i];
563
564 preempt_enable();
565 }
566
567 seq_printf(m, "\n\tevents:\t");
568 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
569 seq_printf(m, "%lu ", totals.events[i]);
570 seq_printf(m, "\n\tbytes:\t");
571 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
572 seq_printf(m, "%Lu ", totals.bytes[i]);
573 seq_printf(m, "\n");
574
575 rpc_print_iostats(m, nfss->client);
576
577 return 0;
578}
579
580/*
581 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400582 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400583 */
584static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
585{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400586 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
587 struct rpc_clnt *rpc;
588
David Howellsf7b422b2006-06-09 09:34:33 -0400589 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400590
591 if (!(flags & MNT_FORCE))
592 return;
593 /* -EIO all pending I/O */
594 rpc = server->client_acl;
595 if (!IS_ERR(rpc))
596 rpc_killall_tasks(rpc);
597 rpc = server->client;
598 if (!IS_ERR(rpc))
599 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400600}
601
602/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500603 * Sanity-check a server address provided by the mount command.
604 *
605 * Address family must be initialized, and address must not be
606 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400607 */
608static int nfs_verify_server_address(struct sockaddr *addr)
609{
610 switch (addr->sa_family) {
611 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500612 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
613 return sa->sin_addr.s_addr != INADDR_ANY;
614 }
615 case AF_INET6: {
616 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
617 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400618 }
619 }
620
621 return 0;
622}
623
624/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400625 * Error-check and convert a string of mount options from user space into
626 * a data structure
627 */
628static int nfs_parse_mount_options(char *raw,
629 struct nfs_parsed_mount_data *mnt)
630{
631 char *p, *string;
632
633 if (!raw) {
634 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
635 return 1;
636 }
637 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
638
639 while ((p = strsep(&raw, ",")) != NULL) {
640 substring_t args[MAX_OPT_ARGS];
641 int option, token;
642
643 if (!*p)
644 continue;
645
646 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
647
648 token = match_token(p, nfs_mount_option_tokens, args);
649 switch (token) {
650 case Opt_soft:
651 mnt->flags |= NFS_MOUNT_SOFT;
652 break;
653 case Opt_hard:
654 mnt->flags &= ~NFS_MOUNT_SOFT;
655 break;
656 case Opt_intr:
657 mnt->flags |= NFS_MOUNT_INTR;
658 break;
659 case Opt_nointr:
660 mnt->flags &= ~NFS_MOUNT_INTR;
661 break;
662 case Opt_posix:
663 mnt->flags |= NFS_MOUNT_POSIX;
664 break;
665 case Opt_noposix:
666 mnt->flags &= ~NFS_MOUNT_POSIX;
667 break;
668 case Opt_cto:
669 mnt->flags &= ~NFS_MOUNT_NOCTO;
670 break;
671 case Opt_nocto:
672 mnt->flags |= NFS_MOUNT_NOCTO;
673 break;
674 case Opt_ac:
675 mnt->flags &= ~NFS_MOUNT_NOAC;
676 break;
677 case Opt_noac:
678 mnt->flags |= NFS_MOUNT_NOAC;
679 break;
680 case Opt_lock:
681 mnt->flags &= ~NFS_MOUNT_NONLM;
682 break;
683 case Opt_nolock:
684 mnt->flags |= NFS_MOUNT_NONLM;
685 break;
686 case Opt_v2:
687 mnt->flags &= ~NFS_MOUNT_VER3;
688 break;
689 case Opt_v3:
690 mnt->flags |= NFS_MOUNT_VER3;
691 break;
692 case Opt_udp:
693 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400694 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400695 mnt->timeo = 7;
696 mnt->retrans = 5;
697 break;
698 case Opt_tcp:
699 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400700 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400701 mnt->timeo = 600;
702 mnt->retrans = 2;
703 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400704 case Opt_rdma:
705 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
706 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
707 mnt->timeo = 600;
708 mnt->retrans = 2;
709 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400710 case Opt_acl:
711 mnt->flags &= ~NFS_MOUNT_NOACL;
712 break;
713 case Opt_noacl:
714 mnt->flags |= NFS_MOUNT_NOACL;
715 break;
716 case Opt_rdirplus:
717 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
718 break;
719 case Opt_nordirplus:
720 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
721 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400722 case Opt_sharecache:
723 mnt->flags &= ~NFS_MOUNT_UNSHARED;
724 break;
725 case Opt_nosharecache:
726 mnt->flags |= NFS_MOUNT_UNSHARED;
727 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400728
729 case Opt_port:
730 if (match_int(args, &option))
731 return 0;
732 if (option < 0 || option > 65535)
733 return 0;
Al Viro410896442007-07-22 10:59:06 +0100734 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400735 break;
736 case Opt_rsize:
737 if (match_int(args, &mnt->rsize))
738 return 0;
739 break;
740 case Opt_wsize:
741 if (match_int(args, &mnt->wsize))
742 return 0;
743 break;
744 case Opt_bsize:
745 if (match_int(args, &option))
746 return 0;
747 if (option < 0)
748 return 0;
749 mnt->bsize = option;
750 break;
751 case Opt_timeo:
752 if (match_int(args, &mnt->timeo))
753 return 0;
754 break;
755 case Opt_retrans:
756 if (match_int(args, &mnt->retrans))
757 return 0;
758 break;
759 case Opt_acregmin:
760 if (match_int(args, &mnt->acregmin))
761 return 0;
762 break;
763 case Opt_acregmax:
764 if (match_int(args, &mnt->acregmax))
765 return 0;
766 break;
767 case Opt_acdirmin:
768 if (match_int(args, &mnt->acdirmin))
769 return 0;
770 break;
771 case Opt_acdirmax:
772 if (match_int(args, &mnt->acdirmax))
773 return 0;
774 break;
775 case Opt_actimeo:
776 if (match_int(args, &option))
777 return 0;
778 if (option < 0)
779 return 0;
780 mnt->acregmin =
781 mnt->acregmax =
782 mnt->acdirmin =
783 mnt->acdirmax = option;
784 break;
785 case Opt_namelen:
786 if (match_int(args, &mnt->namlen))
787 return 0;
788 break;
789 case Opt_mountport:
790 if (match_int(args, &option))
791 return 0;
792 if (option < 0 || option > 65535)
793 return 0;
794 mnt->mount_server.port = option;
795 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400796 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\0896a722007-09-10 13:48:23 -04001085 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001086
David Howellsf7b422b2006-06-09 09:34:33 -04001087 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001088 case 1:
1089 data->namlen = 0;
1090 case 2:
1091 data->bsize = 0;
1092 case 3:
1093 if (data->flags & NFS_MOUNT_VER3)
1094 goto out_no_v3;
1095 data->root.size = NFS2_FHSIZE;
1096 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1097 case 4:
1098 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1099 goto out_no_sec;
1100 case 5:
1101 memset(data->context, 0, sizeof(data->context));
1102 case 6:
1103 if (data->flags & NFS_MOUNT_VER3)
1104 mntfh->size = data->root.size;
1105 else
1106 mntfh->size = NFS2_FHSIZE;
1107
1108 if (mntfh->size > sizeof(mntfh->data))
1109 goto out_invalid_fh;
1110
1111 memcpy(mntfh->data, data->root.data, mntfh->size);
1112 if (mntfh->size < sizeof(mntfh->data))
1113 memset(mntfh->data + mntfh->size, 0,
1114 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001115
1116 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1117 goto out_no_address;
1118
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001119 /*
1120 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1121 * can deal with.
1122 */
1123 args->flags = data->flags;
1124 args->rsize = data->rsize;
1125 args->wsize = data->wsize;
1126 args->flags = data->flags;
1127 args->timeo = data->timeo;
1128 args->retrans = data->retrans;
1129 args->acregmin = data->acregmin;
1130 args->acregmax = data->acregmax;
1131 args->acdirmin = data->acdirmin;
1132 args->acdirmax = data->acdirmax;
1133 args->nfs_server.address = data->addr;
1134 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001135 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001136 /* N.B. caller will free nfs_server.hostname in all cases */
1137 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1138 args->namlen = data->namlen;
1139 args->bsize = data->bsize;
1140 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001141 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001142 default: {
1143 unsigned int len;
1144 char *c;
1145 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001146
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001147 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001148 return -EINVAL;
1149
Chuck Lever6e88e062007-09-24 15:39:50 -04001150 if (!nfs_verify_server_address((struct sockaddr *)
1151 &args->nfs_server.address))
1152 goto out_no_address;
1153
Chuck Lever136d5582007-07-01 12:13:54 -04001154 c = strchr(dev_name, ':');
1155 if (c == NULL)
1156 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001157 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001158 /* N.B. caller will free nfs_server.hostname in all cases */
1159 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001160
1161 c++;
1162 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001163 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001164 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001165
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001166 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001167 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001168 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001169
Chuck Lever136d5582007-07-01 12:13:54 -04001170 break;
1171 }
David Howellsf7b422b2006-06-09 09:34:33 -04001172 }
David Howells54ceac42006-08-22 20:06:13 -04001173
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001174 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1175 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001176
David Howellsf7b422b2006-06-09 09:34:33 -04001177#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001178 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001179 goto out_v3_not_compiled;
1180#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001181
David Howells54ceac42006-08-22 20:06:13 -04001182 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001183
1184out_no_data:
1185 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1186 return -EINVAL;
1187
1188out_no_v3:
1189 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1190 data->version);
1191 return -EINVAL;
1192
1193out_no_sec:
1194 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1195 return -EINVAL;
1196
Chuck Lever5df36e72007-07-01 12:12:56 -04001197#ifndef CONFIG_NFS_V3
1198out_v3_not_compiled:
1199 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1200 return -EPROTONOSUPPORT;
1201#endif /* !CONFIG_NFS_V3 */
1202
1203out_no_address:
1204 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1205 return -EINVAL;
1206
1207out_invalid_fh:
1208 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1209 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001210}
1211
1212/*
1213 * Initialise the common bits of the superblock
1214 */
1215static inline void nfs_initialise_sb(struct super_block *sb)
1216{
1217 struct nfs_server *server = NFS_SB(sb);
1218
1219 sb->s_magic = NFS_SUPER_MAGIC;
1220
1221 /* We probably want something more informative here */
1222 snprintf(sb->s_id, sizeof(sb->s_id),
1223 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1224
1225 if (sb->s_blocksize == 0)
1226 sb->s_blocksize = nfs_block_bits(server->wsize,
1227 &sb->s_blocksize_bits);
1228
1229 if (server->flags & NFS_MOUNT_NOAC)
1230 sb->s_flags |= MS_SYNCHRONOUS;
1231
1232 nfs_super_set_maxbytes(sb, server->maxfilesize);
1233}
1234
1235/*
1236 * Finish setting up an NFS2/3 superblock
1237 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001238static void nfs_fill_super(struct super_block *sb,
1239 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001240{
1241 struct nfs_server *server = NFS_SB(sb);
1242
1243 sb->s_blocksize_bits = 0;
1244 sb->s_blocksize = 0;
1245 if (data->bsize)
1246 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1247
1248 if (server->flags & NFS_MOUNT_VER3) {
1249 /* The VFS shouldn't apply the umask to mode bits. We will do
1250 * so ourselves when necessary.
1251 */
1252 sb->s_flags |= MS_POSIXACL;
1253 sb->s_time_gran = 1;
1254 }
1255
1256 sb->s_op = &nfs_sops;
1257 nfs_initialise_sb(sb);
1258}
1259
1260/*
1261 * Finish setting up a cloned NFS2/3 superblock
1262 */
1263static void nfs_clone_super(struct super_block *sb,
1264 const struct super_block *old_sb)
1265{
1266 struct nfs_server *server = NFS_SB(sb);
1267
1268 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1269 sb->s_blocksize = old_sb->s_blocksize;
1270 sb->s_maxbytes = old_sb->s_maxbytes;
1271
1272 if (server->flags & NFS_MOUNT_VER3) {
1273 /* The VFS shouldn't apply the umask to mode bits. We will do
1274 * so ourselves when necessary.
1275 */
1276 sb->s_flags |= MS_POSIXACL;
1277 sb->s_time_gran = 1;
1278 }
1279
1280 sb->s_op = old_sb->s_op;
1281 nfs_initialise_sb(sb);
1282}
1283
Trond Myklebust275a5d22007-05-16 16:53:28 -04001284#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1285
1286static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1287{
1288 const struct nfs_server *a = s->s_fs_info;
1289 const struct rpc_clnt *clnt_a = a->client;
1290 const struct rpc_clnt *clnt_b = b->client;
1291
1292 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1293 goto Ebusy;
1294 if (a->nfs_client != b->nfs_client)
1295 goto Ebusy;
1296 if (a->flags != b->flags)
1297 goto Ebusy;
1298 if (a->wsize != b->wsize)
1299 goto Ebusy;
1300 if (a->rsize != b->rsize)
1301 goto Ebusy;
1302 if (a->acregmin != b->acregmin)
1303 goto Ebusy;
1304 if (a->acregmax != b->acregmax)
1305 goto Ebusy;
1306 if (a->acdirmin != b->acdirmin)
1307 goto Ebusy;
1308 if (a->acdirmax != b->acdirmax)
1309 goto Ebusy;
1310 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1311 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001312 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001313Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001314 return 0;
1315}
1316
1317struct nfs_sb_mountdata {
1318 struct nfs_server *server;
1319 int mntflags;
1320};
1321
1322static int nfs_set_super(struct super_block *s, void *data)
1323{
1324 struct nfs_sb_mountdata *sb_mntdata = data;
1325 struct nfs_server *server = sb_mntdata->server;
1326 int ret;
1327
1328 s->s_flags = sb_mntdata->mntflags;
1329 s->s_fs_info = server;
1330 ret = set_anon_super(s, server);
1331 if (ret == 0)
1332 server->s_dev = s->s_dev;
1333 return ret;
1334}
1335
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001336static int nfs_compare_super_address(struct nfs_server *server1,
1337 struct nfs_server *server2)
1338{
1339 struct sockaddr *sap1, *sap2;
1340
1341 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1342 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1343
1344 if (sap1->sa_family != sap2->sa_family)
1345 return 0;
1346
1347 switch (sap1->sa_family) {
1348 case AF_INET: {
1349 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1350 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1351 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1352 return 0;
1353 if (sin1->sin_port != sin2->sin_port)
1354 return 0;
1355 break;
1356 }
1357 case AF_INET6: {
1358 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1359 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1360 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1361 return 0;
1362 if (sin1->sin6_port != sin2->sin6_port)
1363 return 0;
1364 break;
1365 }
1366 default:
1367 return 0;
1368 }
1369
1370 return 1;
1371}
1372
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001373static int nfs_compare_super(struct super_block *sb, void *data)
1374{
1375 struct nfs_sb_mountdata *sb_mntdata = data;
1376 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1377 int mntflags = sb_mntdata->mntflags;
1378
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001379 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001380 return 0;
1381 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1382 if (old->flags & NFS_MOUNT_UNSHARED)
1383 return 0;
1384 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1385 return 0;
1386 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001387}
1388
David Howells54ceac42006-08-22 20:06:13 -04001389static int nfs_get_sb(struct file_system_type *fs_type,
1390 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1391{
1392 struct nfs_server *server = NULL;
1393 struct super_block *s;
1394 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001395 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001396 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001397 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001398 struct nfs_sb_mountdata sb_mntdata = {
1399 .mntflags = flags,
1400 };
David Howells54ceac42006-08-22 20:06:13 -04001401 int error;
1402
1403 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001404 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001405 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001406 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001407
1408 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001409 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001410 if (IS_ERR(server)) {
1411 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001412 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001413 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001414 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001415
Trond Myklebust75180df2007-05-16 16:53:28 -04001416 if (server->flags & NFS_MOUNT_UNSHARED)
1417 compare_super = NULL;
1418
David Howells54ceac42006-08-22 20:06:13 -04001419 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001420 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001421 if (IS_ERR(s)) {
1422 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001423 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001424 }
1425
David Howells54ceac42006-08-22 20:06:13 -04001426 if (s->s_fs_info != server) {
1427 nfs_free_server(server);
1428 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001429 }
David Howells54ceac42006-08-22 20:06:13 -04001430
1431 if (!s->s_root) {
1432 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001433 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001434 }
1435
1436 mntroot = nfs_get_root(s, &mntfh);
1437 if (IS_ERR(mntroot)) {
1438 error = PTR_ERR(mntroot);
1439 goto error_splat_super;
1440 }
1441
David Howellsf7b422b2006-06-09 09:34:33 -04001442 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001443 mnt->mnt_sb = s;
1444 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001445 error = 0;
1446
1447out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001448 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001449 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001450
David Howells54ceac42006-08-22 20:06:13 -04001451out_err_nosb:
1452 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001453 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001454
1455error_splat_super:
1456 up_write(&s->s_umount);
1457 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001458 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001459}
1460
David Howells54ceac42006-08-22 20:06:13 -04001461/*
1462 * Destroy an NFS2/3 superblock
1463 */
David Howellsf7b422b2006-06-09 09:34:33 -04001464static void nfs_kill_super(struct super_block *s)
1465{
1466 struct nfs_server *server = NFS_SB(s);
1467
1468 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001469 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001470}
1471
David Howells54ceac42006-08-22 20:06:13 -04001472/*
1473 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1474 */
1475static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1476 const char *dev_name, void *raw_data,
1477 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001478{
1479 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001480 struct super_block *s;
1481 struct nfs_server *server;
1482 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001483 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001484 struct nfs_sb_mountdata sb_mntdata = {
1485 .mntflags = flags,
1486 };
David Howells54ceac42006-08-22 20:06:13 -04001487 int error;
1488
1489 dprintk("--> nfs_xdev_get_sb()\n");
1490
1491 /* create a new volume representation */
1492 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1493 if (IS_ERR(server)) {
1494 error = PTR_ERR(server);
1495 goto out_err_noserver;
1496 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001497 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001498
Trond Myklebust75180df2007-05-16 16:53:28 -04001499 if (server->flags & NFS_MOUNT_UNSHARED)
1500 compare_super = NULL;
1501
David Howells54ceac42006-08-22 20:06:13 -04001502 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001503 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001504 if (IS_ERR(s)) {
1505 error = PTR_ERR(s);
1506 goto out_err_nosb;
1507 }
1508
1509 if (s->s_fs_info != server) {
1510 nfs_free_server(server);
1511 server = NULL;
1512 }
1513
1514 if (!s->s_root) {
1515 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001516 nfs_clone_super(s, data->sb);
1517 }
1518
1519 mntroot = nfs_get_root(s, data->fh);
1520 if (IS_ERR(mntroot)) {
1521 error = PTR_ERR(mntroot);
1522 goto error_splat_super;
1523 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001524 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001525 dput(mntroot);
1526 error = -ESTALE;
1527 goto error_splat_super;
1528 }
David Howells54ceac42006-08-22 20:06:13 -04001529
1530 s->s_flags |= MS_ACTIVE;
1531 mnt->mnt_sb = s;
1532 mnt->mnt_root = mntroot;
1533
1534 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1535 return 0;
1536
1537out_err_nosb:
1538 nfs_free_server(server);
1539out_err_noserver:
1540 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1541 return error;
1542
1543error_splat_super:
1544 up_write(&s->s_umount);
1545 deactivate_super(s);
1546 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1547 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001548}
1549
1550#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001551
1552/*
1553 * Finish setting up a cloned NFS4 superblock
1554 */
1555static void nfs4_clone_super(struct super_block *sb,
1556 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001557{
David Howells54ceac42006-08-22 20:06:13 -04001558 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1559 sb->s_blocksize = old_sb->s_blocksize;
1560 sb->s_maxbytes = old_sb->s_maxbytes;
1561 sb->s_time_gran = 1;
1562 sb->s_op = old_sb->s_op;
1563 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001564}
1565
1566/*
1567 * Set up an NFS4 superblock
1568 */
David Howells54ceac42006-08-22 20:06:13 -04001569static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001570{
David Howellsf7b422b2006-06-09 09:34:33 -04001571 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001572 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001573 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001574}
1575
David Howells54ceac42006-08-22 20:06:13 -04001576/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001577 * Validate NFSv4 mount options
1578 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001579static int nfs4_validate_mount_data(void *options,
1580 struct nfs_parsed_mount_data *args,
1581 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001582{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001583 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001584 char *c;
1585
Russell Kingf16c9602007-11-16 22:13:24 +00001586 memset(args, 0, sizeof(*args));
1587
Chuck Leverf0768eb2007-07-01 12:13:01 -04001588 if (data == NULL)
1589 goto out_no_data;
1590
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001591 args->rsize = NFS_MAX_FILE_IO_SIZE;
1592 args->wsize = NFS_MAX_FILE_IO_SIZE;
1593 args->timeo = 600;
1594 args->retrans = 2;
1595 args->acregmin = 3;
1596 args->acregmax = 60;
1597 args->acdirmin = 30;
1598 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001599 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001600
Chuck Leverf0768eb2007-07-01 12:13:01 -04001601 switch (data->version) {
1602 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001603 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001604 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001605 if (copy_from_user(&args->nfs_server.address,
1606 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001607 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001608 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001609 if (args->nfs_server.address.sin_port == 0)
1610 args->nfs_server.address.sin_port = htons(NFS_PORT);
1611 if (!nfs_verify_server_address((struct sockaddr *)
1612 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001613 goto out_no_address;
1614
1615 switch (data->auth_flavourlen) {
1616 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001617 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001618 break;
1619 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001620 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001621 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001622 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001623 return -EFAULT;
1624 break;
1625 default:
1626 goto out_inval_auth;
1627 }
1628
1629 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1630 if (IS_ERR(c))
1631 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001632 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001633
1634 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1635 if (IS_ERR(c))
1636 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001637 args->nfs_server.export_path = c;
1638 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001639
1640 c = strndup_user(data->client_addr.data, 16);
1641 if (IS_ERR(c))
1642 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001643 args->client_address = c;
1644
1645 /*
1646 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1647 * can deal with.
1648 */
1649
1650 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1651 args->rsize = data->rsize;
1652 args->wsize = data->wsize;
1653 args->timeo = data->timeo;
1654 args->retrans = data->retrans;
1655 args->acregmin = data->acregmin;
1656 args->acregmax = data->acregmax;
1657 args->acdirmin = data->acdirmin;
1658 args->acdirmax = data->acdirmax;
1659 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001660
1661 break;
Chuck Lever80071222007-07-01 12:13:59 -04001662 default: {
1663 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001664
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001665 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001666 return -EINVAL;
1667
Chuck Lever0eb25742007-10-26 13:32:19 -04001668 if (args->nfs_server.address.sin_port == 0)
1669 args->nfs_server.address.sin_port = htons(NFS_PORT);
Chuck Lever80071222007-07-01 12:13:59 -04001670 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001671 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001672 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001673
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001674 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001675 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001676 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001677 break;
1678 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001679 break;
1680 default:
1681 goto out_inval_auth;
1682 }
1683
1684 /*
Chuck Lever80071222007-07-01 12:13:59 -04001685 * Split "dev_name" into "hostname:mntpath".
1686 */
1687 c = strchr(dev_name, ':');
1688 if (c == NULL)
1689 return -EINVAL;
1690 /* while calculating len, pretend ':' is '\0' */
1691 len = c - dev_name;
1692 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001693 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001694 /* N.B. caller will free nfs_server.hostname in all cases */
1695 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001696
1697 c++; /* step over the ':' */
1698 len = strlen(c);
1699 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001700 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001701 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001702
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001703 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001704
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001705 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001706 goto out_no_client_address;
1707
Chuck Lever80071222007-07-01 12:13:59 -04001708 break;
1709 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001710 }
1711
1712 return 0;
1713
1714out_no_data:
1715 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1716 return -EINVAL;
1717
1718out_inval_auth:
1719 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1720 data->auth_flavourlen);
1721 return -EINVAL;
1722
1723out_no_address:
1724 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1725 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001726
1727out_no_client_address:
1728 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1729 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001730}
1731
1732/*
David Howells54ceac42006-08-22 20:06:13 -04001733 * Get the superblock for an NFS4 mountpoint
1734 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001735static int nfs4_get_sb(struct file_system_type *fs_type,
1736 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001737{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001738 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001739 struct super_block *s;
1740 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001741 struct nfs_fh mntfh;
1742 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001743 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001744 struct nfs_sb_mountdata sb_mntdata = {
1745 .mntflags = flags,
1746 };
David Howells54ceac42006-08-22 20:06:13 -04001747 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001748
Chuck Leverf0768eb2007-07-01 12:13:01 -04001749 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001750 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001751 if (error < 0)
1752 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001753
David Howells54ceac42006-08-22 20:06:13 -04001754 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001755 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001756 if (IS_ERR(server)) {
1757 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001758 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001759 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001760 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001761
Trond Myklebust75180df2007-05-16 16:53:28 -04001762 if (server->flags & NFS4_MOUNT_UNSHARED)
1763 compare_super = NULL;
1764
David Howells54ceac42006-08-22 20:06:13 -04001765 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001766 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001767 if (IS_ERR(s)) {
1768 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001769 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001770 }
1771
Trond Myklebust5dd31772006-08-24 01:03:05 -04001772 if (s->s_fs_info != server) {
1773 nfs_free_server(server);
1774 server = NULL;
1775 }
1776
David Howells54ceac42006-08-22 20:06:13 -04001777 if (!s->s_root) {
1778 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001779 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001780 }
David Howellsf7b422b2006-06-09 09:34:33 -04001781
David Howells54ceac42006-08-22 20:06:13 -04001782 mntroot = nfs4_get_root(s, &mntfh);
1783 if (IS_ERR(mntroot)) {
1784 error = PTR_ERR(mntroot);
1785 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001786 }
David Howells54ceac42006-08-22 20:06:13 -04001787
David Howellsf7b422b2006-06-09 09:34:33 -04001788 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001789 mnt->mnt_sb = s;
1790 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001791 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001792
Chuck Lever29eb9812007-07-01 12:12:30 -04001793out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001794 kfree(data.client_address);
1795 kfree(data.nfs_server.export_path);
1796 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001797 return error;
David Howells54ceac42006-08-22 20:06:13 -04001798
Chuck Lever29eb9812007-07-01 12:12:30 -04001799out_free:
1800 nfs_free_server(server);
1801 goto out;
1802
David Howells54ceac42006-08-22 20:06:13 -04001803error_splat_super:
1804 up_write(&s->s_umount);
1805 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001806 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001807}
1808
1809static void nfs4_kill_super(struct super_block *sb)
1810{
1811 struct nfs_server *server = NFS_SB(sb);
1812
1813 nfs_return_all_delegations(sb);
1814 kill_anon_super(sb);
1815
1816 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001817 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001818}
1819
1820/*
David Howells54ceac42006-08-22 20:06:13 -04001821 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001822 */
David Howells54ceac42006-08-22 20:06:13 -04001823static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1824 const char *dev_name, void *raw_data,
1825 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001826{
1827 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001828 struct super_block *s;
1829 struct nfs_server *server;
1830 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001831 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001832 struct nfs_sb_mountdata sb_mntdata = {
1833 .mntflags = flags,
1834 };
David Howells54ceac42006-08-22 20:06:13 -04001835 int error;
1836
1837 dprintk("--> nfs4_xdev_get_sb()\n");
1838
1839 /* create a new volume representation */
1840 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1841 if (IS_ERR(server)) {
1842 error = PTR_ERR(server);
1843 goto out_err_noserver;
1844 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001845 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001846
Trond Myklebust75180df2007-05-16 16:53:28 -04001847 if (server->flags & NFS4_MOUNT_UNSHARED)
1848 compare_super = NULL;
1849
David Howells54ceac42006-08-22 20:06:13 -04001850 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001851 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001852 if (IS_ERR(s)) {
1853 error = PTR_ERR(s);
1854 goto out_err_nosb;
1855 }
1856
1857 if (s->s_fs_info != server) {
1858 nfs_free_server(server);
1859 server = NULL;
1860 }
1861
1862 if (!s->s_root) {
1863 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001864 nfs4_clone_super(s, data->sb);
1865 }
1866
1867 mntroot = nfs4_get_root(s, data->fh);
1868 if (IS_ERR(mntroot)) {
1869 error = PTR_ERR(mntroot);
1870 goto error_splat_super;
1871 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001872 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1873 dput(mntroot);
1874 error = -ESTALE;
1875 goto error_splat_super;
1876 }
David Howells54ceac42006-08-22 20:06:13 -04001877
1878 s->s_flags |= MS_ACTIVE;
1879 mnt->mnt_sb = s;
1880 mnt->mnt_root = mntroot;
1881
1882 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1883 return 0;
1884
1885out_err_nosb:
1886 nfs_free_server(server);
1887out_err_noserver:
1888 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1889 return error;
1890
1891error_splat_super:
1892 up_write(&s->s_umount);
1893 deactivate_super(s);
1894 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1895 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001896}
1897
David Howells54ceac42006-08-22 20:06:13 -04001898/*
1899 * Create an NFS4 server record on referral traversal
1900 */
1901static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1902 const char *dev_name, void *raw_data,
1903 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001904{
1905 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001906 struct super_block *s;
1907 struct nfs_server *server;
1908 struct dentry *mntroot;
1909 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001910 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001911 struct nfs_sb_mountdata sb_mntdata = {
1912 .mntflags = flags,
1913 };
David Howells54ceac42006-08-22 20:06:13 -04001914 int error;
1915
1916 dprintk("--> nfs4_referral_get_sb()\n");
1917
1918 /* create a new volume representation */
1919 server = nfs4_create_referral_server(data, &mntfh);
1920 if (IS_ERR(server)) {
1921 error = PTR_ERR(server);
1922 goto out_err_noserver;
1923 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001924 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001925
Trond Myklebust75180df2007-05-16 16:53:28 -04001926 if (server->flags & NFS4_MOUNT_UNSHARED)
1927 compare_super = NULL;
1928
David Howells54ceac42006-08-22 20:06:13 -04001929 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001930 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001931 if (IS_ERR(s)) {
1932 error = PTR_ERR(s);
1933 goto out_err_nosb;
1934 }
1935
1936 if (s->s_fs_info != server) {
1937 nfs_free_server(server);
1938 server = NULL;
1939 }
1940
1941 if (!s->s_root) {
1942 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001943 nfs4_fill_super(s);
1944 }
1945
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001946 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001947 if (IS_ERR(mntroot)) {
1948 error = PTR_ERR(mntroot);
1949 goto error_splat_super;
1950 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001951 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1952 dput(mntroot);
1953 error = -ESTALE;
1954 goto error_splat_super;
1955 }
David Howells54ceac42006-08-22 20:06:13 -04001956
1957 s->s_flags |= MS_ACTIVE;
1958 mnt->mnt_sb = s;
1959 mnt->mnt_root = mntroot;
1960
1961 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1962 return 0;
1963
1964out_err_nosb:
1965 nfs_free_server(server);
1966out_err_noserver:
1967 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1968 return error;
1969
1970error_splat_super:
1971 up_write(&s->s_umount);
1972 deactivate_super(s);
1973 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1974 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001975}
1976
David Howells54ceac42006-08-22 20:06:13 -04001977#endif /* CONFIG_NFS_V4 */