blob: 1fb3818436501bc7bfd7637d7744576fe09e6041 [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 */
Chuck Lever33832032007-12-10 14:59:13 -050092 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
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 Lever33832032007-12-10 14:59:13 -0500151 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400152 { 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
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500193 { Opt_sec_spkm, "spkm3" },
194 { Opt_sec_spkmi, "spkm3i" },
195 { Opt_sec_spkmp, "spkm3p" },
196
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197 { Opt_sec_err, NULL }
198};
199
200
David Howellsf7b422b2006-06-09 09:34:33 -0400201static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400202static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400203static int nfs_show_options(struct seq_file *, struct vfsmount *);
204static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400205static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400206static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400207 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400208static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500209static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400210
211static struct file_system_type nfs_fs_type = {
212 .owner = THIS_MODULE,
213 .name = "nfs",
214 .get_sb = nfs_get_sb,
215 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700216 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400217};
218
David Howells54ceac42006-08-22 20:06:13 -0400219struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400220 .owner = THIS_MODULE,
221 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400222 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400223 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700224 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400225};
226
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800227static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400228 .alloc_inode = nfs_alloc_inode,
229 .destroy_inode = nfs_destroy_inode,
230 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500231 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400232 .statfs = nfs_statfs,
233 .clear_inode = nfs_clear_inode,
234 .umount_begin = nfs_umount_begin,
235 .show_options = nfs_show_options,
236 .show_stats = nfs_show_stats,
237};
238
239#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400240static int nfs4_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400242static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
244static int nfs4_referral_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400246static void nfs4_kill_super(struct super_block *sb);
247
248static struct file_system_type nfs4_fs_type = {
249 .owner = THIS_MODULE,
250 .name = "nfs4",
251 .get_sb = nfs4_get_sb,
252 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700253 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400254};
255
David Howells54ceac42006-08-22 20:06:13 -0400256struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400257 .owner = THIS_MODULE,
258 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400259 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400260 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700261 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400262};
263
David Howells54ceac42006-08-22 20:06:13 -0400264struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400265 .owner = THIS_MODULE,
266 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400267 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400268 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700269 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400270};
271
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800272static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400273 .alloc_inode = nfs_alloc_inode,
274 .destroy_inode = nfs_destroy_inode,
275 .write_inode = nfs_write_inode,
276 .statfs = nfs_statfs,
277 .clear_inode = nfs4_clear_inode,
278 .umount_begin = nfs_umount_begin,
279 .show_options = nfs_show_options,
280 .show_stats = nfs_show_stats,
281};
282#endif
283
Rusty Russell8e1f9362007-07-17 04:03:17 -0700284static struct shrinker acl_shrinker = {
285 .shrink = nfs_access_cache_shrinker,
286 .seeks = DEFAULT_SEEKS,
287};
Trond Myklebust979df722006-07-25 11:28:19 -0400288
David Howellsf7b422b2006-06-09 09:34:33 -0400289/*
290 * Register the NFS filesystems
291 */
292int __init register_nfs_fs(void)
293{
294 int ret;
295
296 ret = register_filesystem(&nfs_fs_type);
297 if (ret < 0)
298 goto error_0;
299
David Howellsf7b422b2006-06-09 09:34:33 -0400300 ret = nfs_register_sysctl();
301 if (ret < 0)
302 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800303#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400304 ret = register_filesystem(&nfs4_fs_type);
305 if (ret < 0)
306 goto error_2;
307#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700308 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400309 return 0;
310
311#ifdef CONFIG_NFS_V4
312error_2:
313 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800314#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400315error_1:
316 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400317error_0:
318 return ret;
319}
320
321/*
322 * Unregister the NFS filesystems
323 */
324void __exit unregister_nfs_fs(void)
325{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700326 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400327#ifdef CONFIG_NFS_V4
328 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400329#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700330 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400331 unregister_filesystem(&nfs_fs_type);
332}
333
Steve Dicksonef818a22007-11-08 04:05:04 -0500334void nfs_sb_active(struct nfs_server *server)
335{
336 atomic_inc(&server->active);
337}
338
339void nfs_sb_deactive(struct nfs_server *server)
340{
341 if (atomic_dec_and_test(&server->active))
342 wake_up(&server->active_wq);
343}
344
345static void nfs_put_super(struct super_block *sb)
346{
347 struct nfs_server *server = NFS_SB(sb);
348 /*
349 * Make sure there are no outstanding ops to this server.
350 * If so, wait for them to finish before allowing the
351 * unmount to continue.
352 */
353 wait_event(server->active_wq, atomic_read(&server->active) == 0);
354}
355
David Howellsf7b422b2006-06-09 09:34:33 -0400356/*
357 * Deliver file system statistics to userspace
358 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400359static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400360{
David Howells0c7d90c2006-08-22 20:06:10 -0400361 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400362 unsigned char blockbits;
363 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400364 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400365 struct nfs_fattr fattr;
366 struct nfs_fsstat res = {
367 .fattr = &fattr,
368 };
369 int error;
370
371 lock_kernel();
372
David Howells8fa5c002006-08-22 20:06:12 -0400373 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400374 if (error < 0)
375 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700376 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400377
378 /*
379 * Current versions of glibc do not correctly handle the
380 * case where f_frsize != f_bsize. Eventually we want to
381 * report the value of wtmult in this field.
382 */
David Howells0c7d90c2006-08-22 20:06:10 -0400383 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400384
385 /*
386 * On most *nix systems, f_blocks, f_bfree, and f_bavail
387 * are reported in units of f_frsize. Linux hasn't had
388 * an f_frsize field in its statfs struct until recently,
389 * thus historically Linux's sys_statfs reports these
390 * fields in units of f_bsize.
391 */
David Howells0c7d90c2006-08-22 20:06:10 -0400392 buf->f_bsize = dentry->d_sb->s_blocksize;
393 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400394 blockres = (1 << blockbits) - 1;
395 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
396 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
397 buf->f_bavail = (res.abytes + blockres) >> blockbits;
398
399 buf->f_files = res.tfiles;
400 buf->f_ffree = res.afiles;
401
402 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700403
David Howellsf7b422b2006-06-09 09:34:33 -0400404 unlock_kernel();
405 return 0;
406
407 out_err:
408 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700409 unlock_kernel();
410 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400411}
412
David Howells7d4e2742006-08-22 20:06:07 -0400413/*
414 * Map the security flavour number to a name
415 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400416static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
417{
David Howells7d4e2742006-08-22 20:06:07 -0400418 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400419 rpc_authflavor_t flavour;
420 const char *str;
421 } sec_flavours[] = {
422 { RPC_AUTH_NULL, "null" },
423 { RPC_AUTH_UNIX, "sys" },
424 { RPC_AUTH_GSS_KRB5, "krb5" },
425 { RPC_AUTH_GSS_KRB5I, "krb5i" },
426 { RPC_AUTH_GSS_KRB5P, "krb5p" },
427 { RPC_AUTH_GSS_LKEY, "lkey" },
428 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
429 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
430 { RPC_AUTH_GSS_SPKM, "spkm" },
431 { RPC_AUTH_GSS_SPKMI, "spkmi" },
432 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400433 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400434 };
435 int i;
436
Chuck Lever4d81cd12007-07-01 12:12:40 -0400437 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400438 if (sec_flavours[i].flavour == flavour)
439 break;
440 }
441 return sec_flavours[i].str;
442}
443
David Howellsf7b422b2006-06-09 09:34:33 -0400444/*
445 * Describe the mount options in force on this server representation
446 */
447static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
448{
David Howells509de812006-08-22 20:06:11 -0400449 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400450 int flag;
David Howells509de812006-08-22 20:06:11 -0400451 const char *str;
452 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400453 } nfs_info[] = {
454 { NFS_MOUNT_SOFT, ",soft", ",hard" },
David Howellsf7b422b2006-06-09 09:34:33 -0400455 { NFS_MOUNT_NOCTO, ",nocto", "" },
456 { NFS_MOUNT_NOAC, ",noac", "" },
457 { NFS_MOUNT_NONLM, ",nolock", "" },
458 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400459 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400460 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400461 { 0, NULL, NULL }
462 };
David Howells509de812006-08-22 20:06:11 -0400463 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400464 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400465
David Howells8fa5c002006-08-22 20:06:12 -0400466 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400467 seq_printf(m, ",rsize=%d", nfss->rsize);
468 seq_printf(m, ",wsize=%d", nfss->wsize);
469 if (nfss->acregmin != 3*HZ || showdefaults)
470 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
471 if (nfss->acregmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
473 if (nfss->acdirmin != 30*HZ || showdefaults)
474 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
475 if (nfss->acdirmax != 60*HZ || showdefaults)
476 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
477 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
478 if (nfss->flags & nfs_infop->flag)
479 seq_puts(m, nfs_infop->str);
480 else
481 seq_puts(m, nfs_infop->nostr);
482 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400483 seq_printf(m, ",proto=%s",
484 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Trond Myklebust33170232007-12-20 16:03:59 -0500485 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
486 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400487 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400488}
489
490/*
491 * Describe the mount options on this VFS mountpoint
492 */
493static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
494{
495 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
496
497 nfs_show_mount_options(m, nfss, 0);
498
Chuck Lever5d8515c2007-12-10 14:57:16 -0500499 seq_printf(m, ",addr=%s",
500 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
501 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400502
503 return 0;
504}
505
506/*
507 * Present statistical information for this VFS mountpoint
508 */
509static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
510{
511 int i, cpu;
512 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
513 struct rpc_auth *auth = nfss->client->cl_auth;
514 struct nfs_iostats totals = { };
515
516 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
517
518 /*
519 * Display all mount option settings
520 */
521 seq_printf(m, "\n\topts:\t");
522 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
523 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
524 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
525 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
526 nfs_show_mount_options(m, nfss, 1);
527
528 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
529
530 seq_printf(m, "\n\tcaps:\t");
531 seq_printf(m, "caps=0x%x", nfss->caps);
532 seq_printf(m, ",wtmult=%d", nfss->wtmult);
533 seq_printf(m, ",dtsize=%d", nfss->dtsize);
534 seq_printf(m, ",bsize=%d", nfss->bsize);
535 seq_printf(m, ",namelen=%d", nfss->namelen);
536
537#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500538 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400539 seq_printf(m, "\n\tnfsv4:\t");
540 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
541 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
542 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
543 }
544#endif
545
546 /*
547 * Display security flavor in effect for this mount
548 */
549 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
550 if (auth->au_flavor)
551 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
552
553 /*
554 * Display superblock I/O counters
555 */
556 for_each_possible_cpu(cpu) {
557 struct nfs_iostats *stats;
558
559 preempt_disable();
560 stats = per_cpu_ptr(nfss->io_stats, cpu);
561
562 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
563 totals.events[i] += stats->events[i];
564 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
565 totals.bytes[i] += stats->bytes[i];
566
567 preempt_enable();
568 }
569
570 seq_printf(m, "\n\tevents:\t");
571 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
572 seq_printf(m, "%lu ", totals.events[i]);
573 seq_printf(m, "\n\tbytes:\t");
574 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
575 seq_printf(m, "%Lu ", totals.bytes[i]);
576 seq_printf(m, "\n");
577
578 rpc_print_iostats(m, nfss->client);
579
580 return 0;
581}
582
583/*
584 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400585 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400586 */
587static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
588{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400589 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
590 struct rpc_clnt *rpc;
591
David Howellsf7b422b2006-06-09 09:34:33 -0400592 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400593
594 if (!(flags & MNT_FORCE))
595 return;
596 /* -EIO all pending I/O */
597 rpc = server->client_acl;
598 if (!IS_ERR(rpc))
599 rpc_killall_tasks(rpc);
600 rpc = server->client;
601 if (!IS_ERR(rpc))
602 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400603}
604
605/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500606 * Set the port number in an address. Be agnostic about the address family.
607 */
608static void nfs_set_port(struct sockaddr *sap, unsigned short port)
609{
610 switch (sap->sa_family) {
611 case AF_INET: {
612 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
613 ap->sin_port = htons(port);
614 break;
615 }
616 case AF_INET6: {
617 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
618 ap->sin6_port = htons(port);
619 break;
620 }
621 }
622}
623
624/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500625 * Sanity-check a server address provided by the mount command.
626 *
627 * Address family must be initialized, and address must not be
628 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400629 */
630static int nfs_verify_server_address(struct sockaddr *addr)
631{
632 switch (addr->sa_family) {
633 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500634 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
635 return sa->sin_addr.s_addr != INADDR_ANY;
636 }
637 case AF_INET6: {
638 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
639 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400640 }
641 }
642
643 return 0;
644}
645
646/*
Chuck Lever9412b922007-12-10 14:59:21 -0500647 * Parse string addresses passed in via a mount option,
648 * and construct a sockaddr based on the result.
649 *
650 * If address parsing fails, set the sockaddr's address
651 * family to AF_UNSPEC to force nfs_verify_server_address()
652 * to punt the mount.
653 */
654static void nfs_parse_server_address(char *value,
Chuck Lever4c568012007-12-10 14:59:28 -0500655 struct sockaddr *sap,
656 size_t *len)
Chuck Lever9412b922007-12-10 14:59:21 -0500657{
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500658 if (strchr(value, ':')) {
659 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
660 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
Chuck Lever9412b922007-12-10 14:59:21 -0500661
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500662 ap->sin6_family = AF_INET6;
663 *len = sizeof(*ap);
664 if (in6_pton(value, -1, addr, '\0', NULL))
665 return;
666 } else {
667 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
668 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
669
670 ap->sin_family = AF_INET;
671 *len = sizeof(*ap);
672 if (in4_pton(value, -1, addr, '\0', NULL))
673 return;
674 }
Chuck Lever9412b922007-12-10 14:59:21 -0500675
676 sap->sa_family = AF_UNSPEC;
Chuck Lever4c568012007-12-10 14:59:28 -0500677 *len = 0;
Chuck Lever9412b922007-12-10 14:59:21 -0500678}
679
680/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400681 * Error-check and convert a string of mount options from user space into
682 * a data structure
683 */
684static int nfs_parse_mount_options(char *raw,
685 struct nfs_parsed_mount_data *mnt)
686{
687 char *p, *string;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500688 unsigned short port = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400689
690 if (!raw) {
691 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
692 return 1;
693 }
694 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
695
696 while ((p = strsep(&raw, ",")) != NULL) {
697 substring_t args[MAX_OPT_ARGS];
698 int option, token;
699
700 if (!*p)
701 continue;
702
703 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
704
705 token = match_token(p, nfs_mount_option_tokens, args);
706 switch (token) {
707 case Opt_soft:
708 mnt->flags |= NFS_MOUNT_SOFT;
709 break;
710 case Opt_hard:
711 mnt->flags &= ~NFS_MOUNT_SOFT;
712 break;
713 case Opt_intr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400714 case Opt_nointr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400715 break;
716 case Opt_posix:
717 mnt->flags |= NFS_MOUNT_POSIX;
718 break;
719 case Opt_noposix:
720 mnt->flags &= ~NFS_MOUNT_POSIX;
721 break;
722 case Opt_cto:
723 mnt->flags &= ~NFS_MOUNT_NOCTO;
724 break;
725 case Opt_nocto:
726 mnt->flags |= NFS_MOUNT_NOCTO;
727 break;
728 case Opt_ac:
729 mnt->flags &= ~NFS_MOUNT_NOAC;
730 break;
731 case Opt_noac:
732 mnt->flags |= NFS_MOUNT_NOAC;
733 break;
734 case Opt_lock:
735 mnt->flags &= ~NFS_MOUNT_NONLM;
736 break;
737 case Opt_nolock:
738 mnt->flags |= NFS_MOUNT_NONLM;
739 break;
740 case Opt_v2:
741 mnt->flags &= ~NFS_MOUNT_VER3;
742 break;
743 case Opt_v3:
744 mnt->flags |= NFS_MOUNT_VER3;
745 break;
746 case Opt_udp:
747 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400748 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400749 mnt->timeo = 7;
750 mnt->retrans = 5;
751 break;
752 case Opt_tcp:
753 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400754 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400755 mnt->timeo = 600;
756 mnt->retrans = 2;
757 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400758 case Opt_rdma:
759 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
760 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
761 mnt->timeo = 600;
762 mnt->retrans = 2;
763 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400764 case Opt_acl:
765 mnt->flags &= ~NFS_MOUNT_NOACL;
766 break;
767 case Opt_noacl:
768 mnt->flags |= NFS_MOUNT_NOACL;
769 break;
770 case Opt_rdirplus:
771 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
772 break;
773 case Opt_nordirplus:
774 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
775 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400776 case Opt_sharecache:
777 mnt->flags &= ~NFS_MOUNT_UNSHARED;
778 break;
779 case Opt_nosharecache:
780 mnt->flags |= NFS_MOUNT_UNSHARED;
781 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400782
783 case Opt_port:
784 if (match_int(args, &option))
785 return 0;
786 if (option < 0 || option > 65535)
787 return 0;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500788 port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400789 break;
790 case Opt_rsize:
791 if (match_int(args, &mnt->rsize))
792 return 0;
793 break;
794 case Opt_wsize:
795 if (match_int(args, &mnt->wsize))
796 return 0;
797 break;
798 case Opt_bsize:
799 if (match_int(args, &option))
800 return 0;
801 if (option < 0)
802 return 0;
803 mnt->bsize = option;
804 break;
805 case Opt_timeo:
806 if (match_int(args, &mnt->timeo))
807 return 0;
808 break;
809 case Opt_retrans:
810 if (match_int(args, &mnt->retrans))
811 return 0;
812 break;
813 case Opt_acregmin:
814 if (match_int(args, &mnt->acregmin))
815 return 0;
816 break;
817 case Opt_acregmax:
818 if (match_int(args, &mnt->acregmax))
819 return 0;
820 break;
821 case Opt_acdirmin:
822 if (match_int(args, &mnt->acdirmin))
823 return 0;
824 break;
825 case Opt_acdirmax:
826 if (match_int(args, &mnt->acdirmax))
827 return 0;
828 break;
829 case Opt_actimeo:
830 if (match_int(args, &option))
831 return 0;
832 if (option < 0)
833 return 0;
834 mnt->acregmin =
835 mnt->acregmax =
836 mnt->acdirmin =
837 mnt->acdirmax = option;
838 break;
839 case Opt_namelen:
840 if (match_int(args, &mnt->namlen))
841 return 0;
842 break;
843 case Opt_mountport:
844 if (match_int(args, &option))
845 return 0;
846 if (option < 0 || option > 65535)
847 return 0;
848 mnt->mount_server.port = option;
849 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400850 case Opt_mountvers:
851 if (match_int(args, &option))
852 return 0;
853 if (option < 0)
854 return 0;
855 mnt->mount_server.version = option;
856 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400857 case Opt_nfsvers:
858 if (match_int(args, &option))
859 return 0;
860 switch (option) {
861 case 2:
862 mnt->flags &= ~NFS_MOUNT_VER3;
863 break;
864 case 3:
865 mnt->flags |= NFS_MOUNT_VER3;
866 break;
867 default:
868 goto out_unrec_vers;
869 }
870 break;
871
872 case Opt_sec:
873 string = match_strdup(args);
874 if (string == NULL)
875 goto out_nomem;
876 token = match_token(string, nfs_secflavor_tokens, args);
877 kfree(string);
878
879 /*
880 * The flags setting is for v2/v3. The flavor_len
881 * setting is for v4. v2/v3 also need to know the
882 * difference between NULL and UNIX.
883 */
884 switch (token) {
885 case Opt_sec_none:
886 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
887 mnt->auth_flavor_len = 0;
888 mnt->auth_flavors[0] = RPC_AUTH_NULL;
889 break;
890 case Opt_sec_sys:
891 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
892 mnt->auth_flavor_len = 0;
893 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
894 break;
895 case Opt_sec_krb5:
896 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
897 mnt->auth_flavor_len = 1;
898 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
899 break;
900 case Opt_sec_krb5i:
901 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
902 mnt->auth_flavor_len = 1;
903 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
904 break;
905 case Opt_sec_krb5p:
906 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
907 mnt->auth_flavor_len = 1;
908 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
909 break;
910 case Opt_sec_lkey:
911 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
912 mnt->auth_flavor_len = 1;
913 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
914 break;
915 case Opt_sec_lkeyi:
916 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
917 mnt->auth_flavor_len = 1;
918 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
919 break;
920 case Opt_sec_lkeyp:
921 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
922 mnt->auth_flavor_len = 1;
923 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
924 break;
925 case Opt_sec_spkm:
926 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
927 mnt->auth_flavor_len = 1;
928 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
929 break;
930 case Opt_sec_spkmi:
931 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
932 mnt->auth_flavor_len = 1;
933 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
934 break;
935 case Opt_sec_spkmp:
936 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
937 mnt->auth_flavor_len = 1;
938 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
939 break;
940 default:
941 goto out_unrec_sec;
942 }
943 break;
944 case Opt_proto:
945 string = match_strdup(args);
946 if (string == NULL)
947 goto out_nomem;
948 token = match_token(string,
949 nfs_xprt_protocol_tokens, args);
950 kfree(string);
951
952 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400953 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400954 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400955 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400956 mnt->timeo = 7;
957 mnt->retrans = 5;
958 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400959 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400960 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400961 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400962 mnt->timeo = 600;
963 mnt->retrans = 2;
964 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400965 case Opt_xprt_rdma:
966 /* vector side protocols to TCP */
967 mnt->flags |= NFS_MOUNT_TCP;
968 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
969 mnt->timeo = 600;
970 mnt->retrans = 2;
971 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400972 default:
973 goto out_unrec_xprt;
974 }
975 break;
976 case Opt_mountproto:
977 string = match_strdup(args);
978 if (string == NULL)
979 goto out_nomem;
980 token = match_token(string,
981 nfs_xprt_protocol_tokens, args);
982 kfree(string);
983
984 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400985 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400986 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400987 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400988 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400989 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400990 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400991 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400992 default:
993 goto out_unrec_xprt;
994 }
995 break;
996 case Opt_addr:
997 string = match_strdup(args);
998 if (string == NULL)
999 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001000 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001001 &mnt->nfs_server.address,
1002 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001003 kfree(string);
1004 break;
1005 case Opt_clientaddr:
1006 string = match_strdup(args);
1007 if (string == NULL)
1008 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001009 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001010 mnt->client_address = string;
1011 break;
Chuck Lever33832032007-12-10 14:59:13 -05001012 case Opt_mounthost:
1013 string = match_strdup(args);
1014 if (string == NULL)
1015 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001016 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001017 mnt->mount_server.hostname = string;
1018 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001019 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001020 string = match_strdup(args);
1021 if (string == NULL)
1022 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001023 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001024 &mnt->mount_server.address,
1025 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001026 kfree(string);
1027 break;
1028
1029 case Opt_userspace:
1030 case Opt_deprecated:
1031 break;
1032
1033 default:
1034 goto out_unknown;
1035 }
1036 }
1037
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001038 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port);
1039
Chuck Leverbf0fd762007-07-01 12:13:44 -04001040 return 1;
1041
1042out_nomem:
1043 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1044 return 0;
1045
1046out_unrec_vers:
1047 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1048 return 0;
1049
1050out_unrec_xprt:
1051 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1052 return 0;
1053
1054out_unrec_sec:
1055 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1056 return 0;
1057
1058out_unknown:
1059 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1060 return 0;
1061}
1062
1063/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001064 * Use the remote server's MOUNT service to request the NFS file handle
1065 * corresponding to the provided path.
1066 */
1067static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1068 struct nfs_fh *root_fh)
1069{
Chuck Lever4c568012007-12-10 14:59:28 -05001070 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001071 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001072 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001073
1074 if (args->mount_server.version == 0) {
1075 if (args->flags & NFS_MOUNT_VER3)
1076 args->mount_server.version = NFS_MNT3_VERSION;
1077 else
1078 args->mount_server.version = NFS_MNT_VERSION;
1079 }
1080
Chuck Lever33832032007-12-10 14:59:13 -05001081 if (args->mount_server.hostname)
1082 hostname = args->mount_server.hostname;
1083 else
1084 hostname = args->nfs_server.hostname;
1085
Chuck Lever0076d7b2007-07-01 12:13:49 -04001086 /*
1087 * Construct the mount server's address.
1088 */
Chuck Lever4c568012007-12-10 14:59:28 -05001089 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1090 memcpy(sap, &args->nfs_server.address,
1091 args->nfs_server.addrlen);
1092 args->mount_server.addrlen = args->nfs_server.addrlen;
1093 }
1094
James Lentiniaad70002007-09-24 17:32:49 -04001095 /*
1096 * autobind will be used if mount_server.port == 0
1097 */
Chuck Lever4c568012007-12-10 14:59:28 -05001098 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001099
1100 /*
1101 * Now ask the mount server to map our export path
1102 * to a file handle.
1103 */
Chuck Lever4c568012007-12-10 14:59:28 -05001104 status = nfs_mount(sap,
1105 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001106 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001107 args->nfs_server.export_path,
1108 args->mount_server.version,
1109 args->mount_server.protocol,
1110 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001111 if (status == 0)
1112 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001113
Chuck Lever33832032007-12-10 14:59:13 -05001114 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1115 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001116 return status;
1117}
1118
1119/*
David Howells54ceac42006-08-22 20:06:13 -04001120 * Validate the NFS2/NFS3 mount data
1121 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001122 *
1123 * For option strings, user space handles the following behaviors:
1124 *
1125 * + DNS: mapping server host name to IP address ("addr=" option)
1126 *
1127 * + failure mode: how to behave if a mount request can't be handled
1128 * immediately ("fg/bg" option)
1129 *
1130 * + retry: how often to retry a mount request ("retry=" option)
1131 *
1132 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1133 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001134 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001135static int nfs_validate_mount_data(void *options,
1136 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001137 struct nfs_fh *mntfh,
1138 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001139{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001140 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001141
Russell Kingf16c9602007-11-16 22:13:24 +00001142 memset(args, 0, sizeof(*args));
1143
Chuck Lever5df36e72007-07-01 12:12:56 -04001144 if (data == NULL)
1145 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001146
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001147 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1148 args->rsize = NFS_MAX_FILE_IO_SIZE;
1149 args->wsize = NFS_MAX_FILE_IO_SIZE;
1150 args->timeo = 600;
1151 args->retrans = 2;
1152 args->acregmin = 3;
1153 args->acregmax = 60;
1154 args->acdirmin = 30;
1155 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001156 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001157 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001158
David Howellsf7b422b2006-06-09 09:34:33 -04001159 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001160 case 1:
1161 data->namlen = 0;
1162 case 2:
1163 data->bsize = 0;
1164 case 3:
1165 if (data->flags & NFS_MOUNT_VER3)
1166 goto out_no_v3;
1167 data->root.size = NFS2_FHSIZE;
1168 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1169 case 4:
1170 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1171 goto out_no_sec;
1172 case 5:
1173 memset(data->context, 0, sizeof(data->context));
1174 case 6:
1175 if (data->flags & NFS_MOUNT_VER3)
1176 mntfh->size = data->root.size;
1177 else
1178 mntfh->size = NFS2_FHSIZE;
1179
1180 if (mntfh->size > sizeof(mntfh->data))
1181 goto out_invalid_fh;
1182
1183 memcpy(mntfh->data, data->root.data, mntfh->size);
1184 if (mntfh->size < sizeof(mntfh->data))
1185 memset(mntfh->data + mntfh->size, 0,
1186 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001187
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001188 /*
1189 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1190 * can deal with.
1191 */
1192 args->flags = data->flags;
1193 args->rsize = data->rsize;
1194 args->wsize = data->wsize;
1195 args->flags = data->flags;
1196 args->timeo = data->timeo;
1197 args->retrans = data->retrans;
1198 args->acregmin = data->acregmin;
1199 args->acregmax = data->acregmax;
1200 args->acdirmin = data->acdirmin;
1201 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001202
1203 memcpy(&args->nfs_server.address, &data->addr,
1204 sizeof(data->addr));
1205 args->nfs_server.addrlen = sizeof(data->addr);
1206 if (!nfs_verify_server_address((struct sockaddr *)
1207 &args->nfs_server.address))
1208 goto out_no_address;
1209
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001210 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001211 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001212 /* N.B. caller will free nfs_server.hostname in all cases */
1213 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1214 args->namlen = data->namlen;
1215 args->bsize = data->bsize;
1216 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001217 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001218 default: {
1219 unsigned int len;
1220 char *c;
1221 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001222
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001223 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001224 return -EINVAL;
1225
Chuck Lever6e88e062007-09-24 15:39:50 -04001226 if (!nfs_verify_server_address((struct sockaddr *)
1227 &args->nfs_server.address))
1228 goto out_no_address;
1229
Chuck Lever136d5582007-07-01 12:13:54 -04001230 c = strchr(dev_name, ':');
1231 if (c == NULL)
1232 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001233 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001234 /* N.B. caller will free nfs_server.hostname in all cases */
1235 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001236
1237 c++;
1238 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001239 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001240 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001241
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001242 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001243 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001244 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001245
Chuck Lever136d5582007-07-01 12:13:54 -04001246 break;
1247 }
David Howellsf7b422b2006-06-09 09:34:33 -04001248 }
David Howells54ceac42006-08-22 20:06:13 -04001249
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001250 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1251 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001252
David Howellsf7b422b2006-06-09 09:34:33 -04001253#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001254 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001255 goto out_v3_not_compiled;
1256#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001257
David Howells54ceac42006-08-22 20:06:13 -04001258 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001259
1260out_no_data:
1261 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1262 return -EINVAL;
1263
1264out_no_v3:
1265 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1266 data->version);
1267 return -EINVAL;
1268
1269out_no_sec:
1270 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1271 return -EINVAL;
1272
Chuck Lever5df36e72007-07-01 12:12:56 -04001273#ifndef CONFIG_NFS_V3
1274out_v3_not_compiled:
1275 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1276 return -EPROTONOSUPPORT;
1277#endif /* !CONFIG_NFS_V3 */
1278
1279out_no_address:
1280 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1281 return -EINVAL;
1282
1283out_invalid_fh:
1284 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1285 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001286}
1287
1288/*
1289 * Initialise the common bits of the superblock
1290 */
1291static inline void nfs_initialise_sb(struct super_block *sb)
1292{
1293 struct nfs_server *server = NFS_SB(sb);
1294
1295 sb->s_magic = NFS_SUPER_MAGIC;
1296
1297 /* We probably want something more informative here */
1298 snprintf(sb->s_id, sizeof(sb->s_id),
1299 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1300
1301 if (sb->s_blocksize == 0)
1302 sb->s_blocksize = nfs_block_bits(server->wsize,
1303 &sb->s_blocksize_bits);
1304
1305 if (server->flags & NFS_MOUNT_NOAC)
1306 sb->s_flags |= MS_SYNCHRONOUS;
1307
1308 nfs_super_set_maxbytes(sb, server->maxfilesize);
1309}
1310
1311/*
1312 * Finish setting up an NFS2/3 superblock
1313 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001314static void nfs_fill_super(struct super_block *sb,
1315 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001316{
1317 struct nfs_server *server = NFS_SB(sb);
1318
1319 sb->s_blocksize_bits = 0;
1320 sb->s_blocksize = 0;
1321 if (data->bsize)
1322 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1323
1324 if (server->flags & NFS_MOUNT_VER3) {
1325 /* The VFS shouldn't apply the umask to mode bits. We will do
1326 * so ourselves when necessary.
1327 */
1328 sb->s_flags |= MS_POSIXACL;
1329 sb->s_time_gran = 1;
1330 }
1331
1332 sb->s_op = &nfs_sops;
1333 nfs_initialise_sb(sb);
1334}
1335
1336/*
1337 * Finish setting up a cloned NFS2/3 superblock
1338 */
1339static void nfs_clone_super(struct super_block *sb,
1340 const struct super_block *old_sb)
1341{
1342 struct nfs_server *server = NFS_SB(sb);
1343
1344 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1345 sb->s_blocksize = old_sb->s_blocksize;
1346 sb->s_maxbytes = old_sb->s_maxbytes;
1347
1348 if (server->flags & NFS_MOUNT_VER3) {
1349 /* The VFS shouldn't apply the umask to mode bits. We will do
1350 * so ourselves when necessary.
1351 */
1352 sb->s_flags |= MS_POSIXACL;
1353 sb->s_time_gran = 1;
1354 }
1355
1356 sb->s_op = old_sb->s_op;
1357 nfs_initialise_sb(sb);
1358}
1359
Trond Myklebust275a5d22007-05-16 16:53:28 -04001360#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1361
1362static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1363{
1364 const struct nfs_server *a = s->s_fs_info;
1365 const struct rpc_clnt *clnt_a = a->client;
1366 const struct rpc_clnt *clnt_b = b->client;
1367
1368 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1369 goto Ebusy;
1370 if (a->nfs_client != b->nfs_client)
1371 goto Ebusy;
1372 if (a->flags != b->flags)
1373 goto Ebusy;
1374 if (a->wsize != b->wsize)
1375 goto Ebusy;
1376 if (a->rsize != b->rsize)
1377 goto Ebusy;
1378 if (a->acregmin != b->acregmin)
1379 goto Ebusy;
1380 if (a->acregmax != b->acregmax)
1381 goto Ebusy;
1382 if (a->acdirmin != b->acdirmin)
1383 goto Ebusy;
1384 if (a->acdirmax != b->acdirmax)
1385 goto Ebusy;
1386 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1387 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001388 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001389Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001390 return 0;
1391}
1392
1393struct nfs_sb_mountdata {
1394 struct nfs_server *server;
1395 int mntflags;
1396};
1397
1398static int nfs_set_super(struct super_block *s, void *data)
1399{
1400 struct nfs_sb_mountdata *sb_mntdata = data;
1401 struct nfs_server *server = sb_mntdata->server;
1402 int ret;
1403
1404 s->s_flags = sb_mntdata->mntflags;
1405 s->s_fs_info = server;
1406 ret = set_anon_super(s, server);
1407 if (ret == 0)
1408 server->s_dev = s->s_dev;
1409 return ret;
1410}
1411
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001412static int nfs_compare_super_address(struct nfs_server *server1,
1413 struct nfs_server *server2)
1414{
1415 struct sockaddr *sap1, *sap2;
1416
1417 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1418 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1419
1420 if (sap1->sa_family != sap2->sa_family)
1421 return 0;
1422
1423 switch (sap1->sa_family) {
1424 case AF_INET: {
1425 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1426 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1427 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1428 return 0;
1429 if (sin1->sin_port != sin2->sin_port)
1430 return 0;
1431 break;
1432 }
1433 case AF_INET6: {
1434 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1435 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1436 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1437 return 0;
1438 if (sin1->sin6_port != sin2->sin6_port)
1439 return 0;
1440 break;
1441 }
1442 default:
1443 return 0;
1444 }
1445
1446 return 1;
1447}
1448
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001449static int nfs_compare_super(struct super_block *sb, void *data)
1450{
1451 struct nfs_sb_mountdata *sb_mntdata = data;
1452 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1453 int mntflags = sb_mntdata->mntflags;
1454
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001455 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001456 return 0;
1457 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1458 if (old->flags & NFS_MOUNT_UNSHARED)
1459 return 0;
1460 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1461 return 0;
1462 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001463}
1464
David Howells54ceac42006-08-22 20:06:13 -04001465static int nfs_get_sb(struct file_system_type *fs_type,
1466 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1467{
1468 struct nfs_server *server = NULL;
1469 struct super_block *s;
1470 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001471 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001472 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001473 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001474 struct nfs_sb_mountdata sb_mntdata = {
1475 .mntflags = flags,
1476 };
David Howells54ceac42006-08-22 20:06:13 -04001477 int error;
1478
1479 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001480 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001481 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001482 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001483
1484 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001485 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001486 if (IS_ERR(server)) {
1487 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001488 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001489 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001490 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001491
Trond Myklebust75180df2007-05-16 16:53:28 -04001492 if (server->flags & NFS_MOUNT_UNSHARED)
1493 compare_super = NULL;
1494
David Howells54ceac42006-08-22 20:06:13 -04001495 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001496 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001497 if (IS_ERR(s)) {
1498 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001499 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001500 }
1501
David Howells54ceac42006-08-22 20:06:13 -04001502 if (s->s_fs_info != server) {
1503 nfs_free_server(server);
1504 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001505 }
David Howells54ceac42006-08-22 20:06:13 -04001506
1507 if (!s->s_root) {
1508 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001509 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001510 }
1511
1512 mntroot = nfs_get_root(s, &mntfh);
1513 if (IS_ERR(mntroot)) {
1514 error = PTR_ERR(mntroot);
1515 goto error_splat_super;
1516 }
1517
David Howellsf7b422b2006-06-09 09:34:33 -04001518 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001519 mnt->mnt_sb = s;
1520 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001521 error = 0;
1522
1523out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001524 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001525 kfree(data.mount_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001526 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001527
David Howells54ceac42006-08-22 20:06:13 -04001528out_err_nosb:
1529 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001530 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001531
1532error_splat_super:
1533 up_write(&s->s_umount);
1534 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001535 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001536}
1537
David Howells54ceac42006-08-22 20:06:13 -04001538/*
1539 * Destroy an NFS2/3 superblock
1540 */
David Howellsf7b422b2006-06-09 09:34:33 -04001541static void nfs_kill_super(struct super_block *s)
1542{
1543 struct nfs_server *server = NFS_SB(s);
1544
1545 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001546 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001547}
1548
David Howells54ceac42006-08-22 20:06:13 -04001549/*
1550 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1551 */
1552static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1553 const char *dev_name, void *raw_data,
1554 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001555{
1556 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001557 struct super_block *s;
1558 struct nfs_server *server;
1559 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001560 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001561 struct nfs_sb_mountdata sb_mntdata = {
1562 .mntflags = flags,
1563 };
David Howells54ceac42006-08-22 20:06:13 -04001564 int error;
1565
1566 dprintk("--> nfs_xdev_get_sb()\n");
1567
1568 /* create a new volume representation */
1569 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1570 if (IS_ERR(server)) {
1571 error = PTR_ERR(server);
1572 goto out_err_noserver;
1573 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001574 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001575
Trond Myklebust75180df2007-05-16 16:53:28 -04001576 if (server->flags & NFS_MOUNT_UNSHARED)
1577 compare_super = NULL;
1578
David Howells54ceac42006-08-22 20:06:13 -04001579 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001580 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001581 if (IS_ERR(s)) {
1582 error = PTR_ERR(s);
1583 goto out_err_nosb;
1584 }
1585
1586 if (s->s_fs_info != server) {
1587 nfs_free_server(server);
1588 server = NULL;
1589 }
1590
1591 if (!s->s_root) {
1592 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001593 nfs_clone_super(s, data->sb);
1594 }
1595
1596 mntroot = nfs_get_root(s, data->fh);
1597 if (IS_ERR(mntroot)) {
1598 error = PTR_ERR(mntroot);
1599 goto error_splat_super;
1600 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001601 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001602 dput(mntroot);
1603 error = -ESTALE;
1604 goto error_splat_super;
1605 }
David Howells54ceac42006-08-22 20:06:13 -04001606
1607 s->s_flags |= MS_ACTIVE;
1608 mnt->mnt_sb = s;
1609 mnt->mnt_root = mntroot;
1610
1611 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1612 return 0;
1613
1614out_err_nosb:
1615 nfs_free_server(server);
1616out_err_noserver:
1617 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1618 return error;
1619
1620error_splat_super:
1621 up_write(&s->s_umount);
1622 deactivate_super(s);
1623 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1624 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001625}
1626
1627#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001628
1629/*
1630 * Finish setting up a cloned NFS4 superblock
1631 */
1632static void nfs4_clone_super(struct super_block *sb,
1633 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001634{
David Howells54ceac42006-08-22 20:06:13 -04001635 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1636 sb->s_blocksize = old_sb->s_blocksize;
1637 sb->s_maxbytes = old_sb->s_maxbytes;
1638 sb->s_time_gran = 1;
1639 sb->s_op = old_sb->s_op;
1640 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001641}
1642
1643/*
1644 * Set up an NFS4 superblock
1645 */
David Howells54ceac42006-08-22 20:06:13 -04001646static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001647{
David Howellsf7b422b2006-06-09 09:34:33 -04001648 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001649 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001650 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001651}
1652
David Howells54ceac42006-08-22 20:06:13 -04001653/*
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001654 * If the user didn't specify a port, set the port number to
1655 * the NFS version 4 default port.
1656 */
1657static void nfs4_default_port(struct sockaddr *sap)
1658{
1659 switch (sap->sa_family) {
1660 case AF_INET: {
1661 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1662 if (ap->sin_port == 0)
1663 ap->sin_port = htons(NFS_PORT);
1664 break;
1665 }
1666 case AF_INET6: {
1667 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1668 if (ap->sin6_port == 0)
1669 ap->sin6_port = htons(NFS_PORT);
1670 break;
1671 }
1672 }
1673}
1674
1675/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001676 * Validate NFSv4 mount options
1677 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001678static int nfs4_validate_mount_data(void *options,
1679 struct nfs_parsed_mount_data *args,
1680 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001681{
Chuck Lever4c568012007-12-10 14:59:28 -05001682 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001683 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001684 char *c;
1685
Russell Kingf16c9602007-11-16 22:13:24 +00001686 memset(args, 0, sizeof(*args));
1687
Chuck Leverf0768eb2007-07-01 12:13:01 -04001688 if (data == NULL)
1689 goto out_no_data;
1690
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001691 args->rsize = NFS_MAX_FILE_IO_SIZE;
1692 args->wsize = NFS_MAX_FILE_IO_SIZE;
1693 args->timeo = 600;
1694 args->retrans = 2;
1695 args->acregmin = 3;
1696 args->acregmax = 60;
1697 args->acdirmin = 30;
1698 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001699 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001700
Chuck Leverf0768eb2007-07-01 12:13:01 -04001701 switch (data->version) {
1702 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05001703 ap = (struct sockaddr_in *)&args->nfs_server.address;
1704 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001705 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05001706 if (data->host_addrlen == 0)
1707 goto out_no_address;
1708 args->nfs_server.addrlen = data->host_addrlen;
1709 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001710 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001711 if (!nfs_verify_server_address((struct sockaddr *)
1712 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001713 goto out_no_address;
1714
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001715 nfs4_default_port((struct sockaddr *)
1716 &args->nfs_server.address);
1717
Chuck Leverf0768eb2007-07-01 12:13:01 -04001718 switch (data->auth_flavourlen) {
1719 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001720 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001721 break;
1722 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001723 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001724 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001725 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001726 return -EFAULT;
1727 break;
1728 default:
1729 goto out_inval_auth;
1730 }
1731
1732 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1733 if (IS_ERR(c))
1734 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001735 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001736
1737 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1738 if (IS_ERR(c))
1739 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001740 args->nfs_server.export_path = c;
1741 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001742
1743 c = strndup_user(data->client_addr.data, 16);
1744 if (IS_ERR(c))
1745 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001746 args->client_address = c;
1747
1748 /*
1749 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1750 * can deal with.
1751 */
1752
1753 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1754 args->rsize = data->rsize;
1755 args->wsize = data->wsize;
1756 args->timeo = data->timeo;
1757 args->retrans = data->retrans;
1758 args->acregmin = data->acregmin;
1759 args->acregmax = data->acregmax;
1760 args->acdirmin = data->acdirmin;
1761 args->acdirmax = data->acdirmax;
1762 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001763
1764 break;
Chuck Lever80071222007-07-01 12:13:59 -04001765 default: {
1766 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001767
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001768 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001769 return -EINVAL;
1770
1771 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001772 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001773 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001774
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001775 nfs4_default_port((struct sockaddr *)
1776 &args->nfs_server.address);
1777
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001778 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001779 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001780 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001781 break;
1782 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001783 break;
1784 default:
1785 goto out_inval_auth;
1786 }
1787
1788 /*
Chuck Lever80071222007-07-01 12:13:59 -04001789 * Split "dev_name" into "hostname:mntpath".
1790 */
1791 c = strchr(dev_name, ':');
1792 if (c == NULL)
1793 return -EINVAL;
1794 /* while calculating len, pretend ':' is '\0' */
1795 len = c - dev_name;
1796 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001797 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001798 /* N.B. caller will free nfs_server.hostname in all cases */
1799 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001800
1801 c++; /* step over the ':' */
1802 len = strlen(c);
1803 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001804 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001805 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001806
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001807 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001808
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001809 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001810 goto out_no_client_address;
1811
Chuck Lever80071222007-07-01 12:13:59 -04001812 break;
1813 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001814 }
1815
1816 return 0;
1817
1818out_no_data:
1819 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1820 return -EINVAL;
1821
1822out_inval_auth:
1823 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1824 data->auth_flavourlen);
1825 return -EINVAL;
1826
1827out_no_address:
1828 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1829 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001830
1831out_no_client_address:
1832 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1833 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001834}
1835
1836/*
David Howells54ceac42006-08-22 20:06:13 -04001837 * Get the superblock for an NFS4 mountpoint
1838 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001839static int nfs4_get_sb(struct file_system_type *fs_type,
1840 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001841{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001842 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001843 struct super_block *s;
1844 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001845 struct nfs_fh mntfh;
1846 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001847 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001848 struct nfs_sb_mountdata sb_mntdata = {
1849 .mntflags = flags,
1850 };
David Howells54ceac42006-08-22 20:06:13 -04001851 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001852
Chuck Leverf0768eb2007-07-01 12:13:01 -04001853 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001854 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001855 if (error < 0)
1856 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001857
David Howells54ceac42006-08-22 20:06:13 -04001858 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001859 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001860 if (IS_ERR(server)) {
1861 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001862 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001863 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001864 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001865
Trond Myklebust75180df2007-05-16 16:53:28 -04001866 if (server->flags & NFS4_MOUNT_UNSHARED)
1867 compare_super = NULL;
1868
David Howells54ceac42006-08-22 20:06:13 -04001869 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001870 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001871 if (IS_ERR(s)) {
1872 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001873 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001874 }
1875
Trond Myklebust5dd31772006-08-24 01:03:05 -04001876 if (s->s_fs_info != server) {
1877 nfs_free_server(server);
1878 server = NULL;
1879 }
1880
David Howells54ceac42006-08-22 20:06:13 -04001881 if (!s->s_root) {
1882 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001883 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001884 }
David Howellsf7b422b2006-06-09 09:34:33 -04001885
David Howells54ceac42006-08-22 20:06:13 -04001886 mntroot = nfs4_get_root(s, &mntfh);
1887 if (IS_ERR(mntroot)) {
1888 error = PTR_ERR(mntroot);
1889 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001890 }
David Howells54ceac42006-08-22 20:06:13 -04001891
David Howellsf7b422b2006-06-09 09:34:33 -04001892 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001893 mnt->mnt_sb = s;
1894 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001895 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001896
Chuck Lever29eb9812007-07-01 12:12:30 -04001897out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001898 kfree(data.client_address);
1899 kfree(data.nfs_server.export_path);
1900 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001901 return error;
David Howells54ceac42006-08-22 20:06:13 -04001902
Chuck Lever29eb9812007-07-01 12:12:30 -04001903out_free:
1904 nfs_free_server(server);
1905 goto out;
1906
David Howells54ceac42006-08-22 20:06:13 -04001907error_splat_super:
1908 up_write(&s->s_umount);
1909 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001910 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001911}
1912
1913static void nfs4_kill_super(struct super_block *sb)
1914{
1915 struct nfs_server *server = NFS_SB(sb);
1916
1917 nfs_return_all_delegations(sb);
1918 kill_anon_super(sb);
1919
1920 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001921 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001922}
1923
1924/*
David Howells54ceac42006-08-22 20:06:13 -04001925 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001926 */
David Howells54ceac42006-08-22 20:06:13 -04001927static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1928 const char *dev_name, void *raw_data,
1929 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001930{
1931 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001932 struct super_block *s;
1933 struct nfs_server *server;
1934 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001935 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001936 struct nfs_sb_mountdata sb_mntdata = {
1937 .mntflags = flags,
1938 };
David Howells54ceac42006-08-22 20:06:13 -04001939 int error;
1940
1941 dprintk("--> nfs4_xdev_get_sb()\n");
1942
1943 /* create a new volume representation */
1944 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1945 if (IS_ERR(server)) {
1946 error = PTR_ERR(server);
1947 goto out_err_noserver;
1948 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001949 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001950
Trond Myklebust75180df2007-05-16 16:53:28 -04001951 if (server->flags & NFS4_MOUNT_UNSHARED)
1952 compare_super = NULL;
1953
David Howells54ceac42006-08-22 20:06:13 -04001954 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001955 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001956 if (IS_ERR(s)) {
1957 error = PTR_ERR(s);
1958 goto out_err_nosb;
1959 }
1960
1961 if (s->s_fs_info != server) {
1962 nfs_free_server(server);
1963 server = NULL;
1964 }
1965
1966 if (!s->s_root) {
1967 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001968 nfs4_clone_super(s, data->sb);
1969 }
1970
1971 mntroot = nfs4_get_root(s, data->fh);
1972 if (IS_ERR(mntroot)) {
1973 error = PTR_ERR(mntroot);
1974 goto error_splat_super;
1975 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001976 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1977 dput(mntroot);
1978 error = -ESTALE;
1979 goto error_splat_super;
1980 }
David Howells54ceac42006-08-22 20:06:13 -04001981
1982 s->s_flags |= MS_ACTIVE;
1983 mnt->mnt_sb = s;
1984 mnt->mnt_root = mntroot;
1985
1986 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1987 return 0;
1988
1989out_err_nosb:
1990 nfs_free_server(server);
1991out_err_noserver:
1992 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1993 return error;
1994
1995error_splat_super:
1996 up_write(&s->s_umount);
1997 deactivate_super(s);
1998 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1999 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002000}
2001
David Howells54ceac42006-08-22 20:06:13 -04002002/*
2003 * Create an NFS4 server record on referral traversal
2004 */
2005static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2006 const char *dev_name, void *raw_data,
2007 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002008{
2009 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002010 struct super_block *s;
2011 struct nfs_server *server;
2012 struct dentry *mntroot;
2013 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002014 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002015 struct nfs_sb_mountdata sb_mntdata = {
2016 .mntflags = flags,
2017 };
David Howells54ceac42006-08-22 20:06:13 -04002018 int error;
2019
2020 dprintk("--> nfs4_referral_get_sb()\n");
2021
2022 /* create a new volume representation */
2023 server = nfs4_create_referral_server(data, &mntfh);
2024 if (IS_ERR(server)) {
2025 error = PTR_ERR(server);
2026 goto out_err_noserver;
2027 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002028 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002029
Trond Myklebust75180df2007-05-16 16:53:28 -04002030 if (server->flags & NFS4_MOUNT_UNSHARED)
2031 compare_super = NULL;
2032
David Howells54ceac42006-08-22 20:06:13 -04002033 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002034 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002035 if (IS_ERR(s)) {
2036 error = PTR_ERR(s);
2037 goto out_err_nosb;
2038 }
2039
2040 if (s->s_fs_info != server) {
2041 nfs_free_server(server);
2042 server = NULL;
2043 }
2044
2045 if (!s->s_root) {
2046 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002047 nfs4_fill_super(s);
2048 }
2049
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002050 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002051 if (IS_ERR(mntroot)) {
2052 error = PTR_ERR(mntroot);
2053 goto error_splat_super;
2054 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002055 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2056 dput(mntroot);
2057 error = -ESTALE;
2058 goto error_splat_super;
2059 }
David Howells54ceac42006-08-22 20:06:13 -04002060
2061 s->s_flags |= MS_ACTIVE;
2062 mnt->mnt_sb = s;
2063 mnt->mnt_root = mntroot;
2064
2065 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2066 return 0;
2067
2068out_err_nosb:
2069 nfs_free_server(server);
2070out_err_noserver:
2071 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2072 return error;
2073
2074error_splat_super:
2075 up_write(&s->s_umount);
2076 deactivate_super(s);
2077 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2078 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002079}
2080
David Howells54ceac42006-08-22 20:06:13 -04002081#endif /* CONFIG_NFS_V4 */