blob: 347c36341e53ebb2179e379104d50f2f9d666949 [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>
David Howellsf7b422b2006-06-09 09:34:33 -040037#include <linux/nfs_fs.h>
38#include <linux/nfs_mount.h>
39#include <linux/nfs4_mount.h>
40#include <linux/lockd/bind.h>
41#include <linux/smp_lock.h>
42#include <linux/seq_file.h>
43#include <linux/mount.h>
44#include <linux/nfs_idmap.h>
45#include <linux/vfs.h>
46#include <linux/inet.h>
47#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080048#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040049#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040050
51#include <asm/system.h>
52#include <asm/uaccess.h>
53
54#include "nfs4_fs.h"
55#include "callback.h"
56#include "delegation.h"
57#include "iostat.h"
58#include "internal.h"
59
60#define NFSDBG_FACILITY NFSDBG_VFS
61
Chuck Leverbf0fd762007-07-01 12:13:44 -040062enum {
63 /* Mount options that take no arguments */
64 Opt_soft, Opt_hard,
65 Opt_intr, Opt_nointr,
66 Opt_posix, Opt_noposix,
67 Opt_cto, Opt_nocto,
68 Opt_ac, Opt_noac,
69 Opt_lock, Opt_nolock,
70 Opt_v2, Opt_v3,
71 Opt_udp, Opt_tcp,
72 Opt_acl, Opt_noacl,
73 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040074 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075
76 /* Mount options that take integer arguments */
77 Opt_port,
78 Opt_rsize, Opt_wsize, Opt_bsize,
79 Opt_timeo, Opt_retrans,
80 Opt_acregmin, Opt_acregmax,
81 Opt_acdirmin, Opt_acdirmax,
82 Opt_actimeo,
83 Opt_namelen,
84 Opt_mountport,
85 Opt_mountprog, Opt_mountvers,
86 Opt_nfsprog, Opt_nfsvers,
87
88 /* Mount options that take string arguments */
89 Opt_sec, Opt_proto, Opt_mountproto,
Chuck Lever0ac83772007-09-11 18:01:04 -040090 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040091
92 /* Mount options that are ignored */
93 Opt_userspace, Opt_deprecated,
94
95 Opt_err
96};
97
98static match_table_t nfs_mount_option_tokens = {
99 { Opt_userspace, "bg" },
100 { Opt_userspace, "fg" },
101 { Opt_soft, "soft" },
102 { Opt_hard, "hard" },
103 { Opt_intr, "intr" },
104 { Opt_nointr, "nointr" },
105 { Opt_posix, "posix" },
106 { Opt_noposix, "noposix" },
107 { Opt_cto, "cto" },
108 { Opt_nocto, "nocto" },
109 { Opt_ac, "ac" },
110 { Opt_noac, "noac" },
111 { Opt_lock, "lock" },
112 { Opt_nolock, "nolock" },
113 { Opt_v2, "v2" },
114 { Opt_v3, "v3" },
115 { Opt_udp, "udp" },
116 { Opt_tcp, "tcp" },
117 { Opt_acl, "acl" },
118 { Opt_noacl, "noacl" },
119 { Opt_rdirplus, "rdirplus" },
120 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400121 { Opt_sharecache, "sharecache" },
122 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123
124 { Opt_port, "port=%u" },
125 { Opt_rsize, "rsize=%u" },
126 { Opt_wsize, "wsize=%u" },
127 { Opt_bsize, "bsize=%u" },
128 { Opt_timeo, "timeo=%u" },
129 { Opt_retrans, "retrans=%u" },
130 { Opt_acregmin, "acregmin=%u" },
131 { Opt_acregmax, "acregmax=%u" },
132 { Opt_acdirmin, "acdirmin=%u" },
133 { Opt_acdirmax, "acdirmax=%u" },
134 { Opt_actimeo, "actimeo=%u" },
135 { Opt_userspace, "retry=%u" },
136 { Opt_namelen, "namlen=%u" },
137 { Opt_mountport, "mountport=%u" },
138 { Opt_mountprog, "mountprog=%u" },
139 { Opt_mountvers, "mountvers=%u" },
140 { Opt_nfsprog, "nfsprog=%u" },
141 { Opt_nfsvers, "nfsvers=%u" },
142 { Opt_nfsvers, "vers=%u" },
143
144 { Opt_sec, "sec=%s" },
145 { Opt_proto, "proto=%s" },
146 { Opt_mountproto, "mountproto=%s" },
147 { Opt_addr, "addr=%s" },
148 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400149 { Opt_userspace, "mounthost=%s" },
150 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400151
152 { Opt_err, NULL }
153};
154
155enum {
156 Opt_xprt_udp, Opt_xprt_tcp,
157
158 Opt_xprt_err
159};
160
161static match_table_t nfs_xprt_protocol_tokens = {
162 { Opt_xprt_udp, "udp" },
163 { Opt_xprt_tcp, "tcp" },
164
165 { Opt_xprt_err, NULL }
166};
167
168enum {
169 Opt_sec_none, Opt_sec_sys,
170 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
171 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
172 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
173
174 Opt_sec_err
175};
176
177static match_table_t nfs_secflavor_tokens = {
178 { Opt_sec_none, "none" },
179 { Opt_sec_none, "null" },
180 { Opt_sec_sys, "sys" },
181
182 { Opt_sec_krb5, "krb5" },
183 { Opt_sec_krb5i, "krb5i" },
184 { Opt_sec_krb5p, "krb5p" },
185
186 { Opt_sec_lkey, "lkey" },
187 { Opt_sec_lkeyi, "lkeyi" },
188 { Opt_sec_lkeyp, "lkeyp" },
189
190 { Opt_sec_err, NULL }
191};
192
193
David Howellsf7b422b2006-06-09 09:34:33 -0400194static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400195static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400196static int nfs_show_options(struct seq_file *, struct vfsmount *);
197static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400198static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400199static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400200 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400201static void nfs_kill_super(struct super_block *);
202
203static struct file_system_type nfs_fs_type = {
204 .owner = THIS_MODULE,
205 .name = "nfs",
206 .get_sb = nfs_get_sb,
207 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700208 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400209};
210
David Howells54ceac42006-08-22 20:06:13 -0400211struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400212 .owner = THIS_MODULE,
213 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400214 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400215 .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
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800219static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400220 .alloc_inode = nfs_alloc_inode,
221 .destroy_inode = nfs_destroy_inode,
222 .write_inode = nfs_write_inode,
223 .statfs = nfs_statfs,
224 .clear_inode = nfs_clear_inode,
225 .umount_begin = nfs_umount_begin,
226 .show_options = nfs_show_options,
227 .show_stats = nfs_show_stats,
228};
229
230#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400231static int nfs4_get_sb(struct file_system_type *fs_type,
232 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400233static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
234 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
235static int nfs4_referral_get_sb(struct file_system_type *fs_type,
236 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400237static void nfs4_kill_super(struct super_block *sb);
238
239static struct file_system_type nfs4_fs_type = {
240 .owner = THIS_MODULE,
241 .name = "nfs4",
242 .get_sb = nfs4_get_sb,
243 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700244 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400245};
246
David Howells54ceac42006-08-22 20:06:13 -0400247struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400248 .owner = THIS_MODULE,
249 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400250 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400251 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700252 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400253};
254
David Howells54ceac42006-08-22 20:06:13 -0400255struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400256 .owner = THIS_MODULE,
257 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400258 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700260 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400261};
262
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800263static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400264 .alloc_inode = nfs_alloc_inode,
265 .destroy_inode = nfs_destroy_inode,
266 .write_inode = nfs_write_inode,
267 .statfs = nfs_statfs,
268 .clear_inode = nfs4_clear_inode,
269 .umount_begin = nfs_umount_begin,
270 .show_options = nfs_show_options,
271 .show_stats = nfs_show_stats,
272};
273#endif
274
Rusty Russell8e1f9362007-07-17 04:03:17 -0700275static struct shrinker acl_shrinker = {
276 .shrink = nfs_access_cache_shrinker,
277 .seeks = DEFAULT_SEEKS,
278};
Trond Myklebust979df722006-07-25 11:28:19 -0400279
David Howellsf7b422b2006-06-09 09:34:33 -0400280/*
281 * Register the NFS filesystems
282 */
283int __init register_nfs_fs(void)
284{
285 int ret;
286
287 ret = register_filesystem(&nfs_fs_type);
288 if (ret < 0)
289 goto error_0;
290
David Howellsf7b422b2006-06-09 09:34:33 -0400291 ret = nfs_register_sysctl();
292 if (ret < 0)
293 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800294#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400295 ret = register_filesystem(&nfs4_fs_type);
296 if (ret < 0)
297 goto error_2;
298#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700299 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400300 return 0;
301
302#ifdef CONFIG_NFS_V4
303error_2:
304 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800305#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400306error_1:
307 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400308error_0:
309 return ret;
310}
311
312/*
313 * Unregister the NFS filesystems
314 */
315void __exit unregister_nfs_fs(void)
316{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700317 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400318#ifdef CONFIG_NFS_V4
319 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400320#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700321 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400322 unregister_filesystem(&nfs_fs_type);
323}
324
325/*
326 * Deliver file system statistics to userspace
327 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400328static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400329{
David Howells0c7d90c2006-08-22 20:06:10 -0400330 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400331 unsigned char blockbits;
332 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400333 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400334 struct nfs_fattr fattr;
335 struct nfs_fsstat res = {
336 .fattr = &fattr,
337 };
338 int error;
339
340 lock_kernel();
341
David Howells8fa5c002006-08-22 20:06:12 -0400342 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400343 if (error < 0)
344 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700345 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400346
347 /*
348 * Current versions of glibc do not correctly handle the
349 * case where f_frsize != f_bsize. Eventually we want to
350 * report the value of wtmult in this field.
351 */
David Howells0c7d90c2006-08-22 20:06:10 -0400352 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400353
354 /*
355 * On most *nix systems, f_blocks, f_bfree, and f_bavail
356 * are reported in units of f_frsize. Linux hasn't had
357 * an f_frsize field in its statfs struct until recently,
358 * thus historically Linux's sys_statfs reports these
359 * fields in units of f_bsize.
360 */
David Howells0c7d90c2006-08-22 20:06:10 -0400361 buf->f_bsize = dentry->d_sb->s_blocksize;
362 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400363 blockres = (1 << blockbits) - 1;
364 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
365 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
366 buf->f_bavail = (res.abytes + blockres) >> blockbits;
367
368 buf->f_files = res.tfiles;
369 buf->f_ffree = res.afiles;
370
371 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700372
David Howellsf7b422b2006-06-09 09:34:33 -0400373 unlock_kernel();
374 return 0;
375
376 out_err:
377 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700378 unlock_kernel();
379 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400380}
381
David Howells7d4e2742006-08-22 20:06:07 -0400382/*
383 * Map the security flavour number to a name
384 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400385static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
386{
David Howells7d4e2742006-08-22 20:06:07 -0400387 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400388 rpc_authflavor_t flavour;
389 const char *str;
390 } sec_flavours[] = {
391 { RPC_AUTH_NULL, "null" },
392 { RPC_AUTH_UNIX, "sys" },
393 { RPC_AUTH_GSS_KRB5, "krb5" },
394 { RPC_AUTH_GSS_KRB5I, "krb5i" },
395 { RPC_AUTH_GSS_KRB5P, "krb5p" },
396 { RPC_AUTH_GSS_LKEY, "lkey" },
397 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
398 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
399 { RPC_AUTH_GSS_SPKM, "spkm" },
400 { RPC_AUTH_GSS_SPKMI, "spkmi" },
401 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400402 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400403 };
404 int i;
405
Chuck Lever4d81cd12007-07-01 12:12:40 -0400406 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400407 if (sec_flavours[i].flavour == flavour)
408 break;
409 }
410 return sec_flavours[i].str;
411}
412
David Howellsf7b422b2006-06-09 09:34:33 -0400413/*
414 * Describe the mount options in force on this server representation
415 */
416static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
417{
David Howells509de812006-08-22 20:06:11 -0400418 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400419 int flag;
David Howells509de812006-08-22 20:06:11 -0400420 const char *str;
421 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400422 } nfs_info[] = {
423 { NFS_MOUNT_SOFT, ",soft", ",hard" },
424 { NFS_MOUNT_INTR, ",intr", "" },
425 { NFS_MOUNT_NOCTO, ",nocto", "" },
426 { NFS_MOUNT_NOAC, ",noac", "" },
427 { NFS_MOUNT_NONLM, ",nolock", "" },
428 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400429 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400430 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400431 { 0, NULL, NULL }
432 };
David Howells509de812006-08-22 20:06:11 -0400433 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400434 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400435
David Howells8fa5c002006-08-22 20:06:12 -0400436 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400437 seq_printf(m, ",rsize=%d", nfss->rsize);
438 seq_printf(m, ",wsize=%d", nfss->wsize);
439 if (nfss->acregmin != 3*HZ || showdefaults)
440 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
441 if (nfss->acregmax != 60*HZ || showdefaults)
442 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
443 if (nfss->acdirmin != 30*HZ || showdefaults)
444 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
445 if (nfss->acdirmax != 60*HZ || showdefaults)
446 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
447 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
448 if (nfss->flags & nfs_infop->flag)
449 seq_puts(m, nfs_infop->str);
450 else
451 seq_puts(m, nfs_infop->nostr);
452 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400453 seq_printf(m, ",proto=%s",
454 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
David Howells5006a762006-08-22 20:06:12 -0400455 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
456 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400457 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400458}
459
460/*
461 * Describe the mount options on this VFS mountpoint
462 */
463static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
464{
465 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
466
467 nfs_show_mount_options(m, nfss, 0);
468
Jeff Laytonddc01c02007-07-30 08:47:38 -0400469 seq_printf(m, ",addr="NIPQUAD_FMT,
470 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
David Howellsf7b422b2006-06-09 09:34:33 -0400471
472 return 0;
473}
474
475/*
476 * Present statistical information for this VFS mountpoint
477 */
478static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
479{
480 int i, cpu;
481 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
482 struct rpc_auth *auth = nfss->client->cl_auth;
483 struct nfs_iostats totals = { };
484
485 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
486
487 /*
488 * Display all mount option settings
489 */
490 seq_printf(m, "\n\topts:\t");
491 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
492 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
493 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
494 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
495 nfs_show_mount_options(m, nfss, 1);
496
497 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
498
499 seq_printf(m, "\n\tcaps:\t");
500 seq_printf(m, "caps=0x%x", nfss->caps);
501 seq_printf(m, ",wtmult=%d", nfss->wtmult);
502 seq_printf(m, ",dtsize=%d", nfss->dtsize);
503 seq_printf(m, ",bsize=%d", nfss->bsize);
504 seq_printf(m, ",namelen=%d", nfss->namelen);
505
506#ifdef CONFIG_NFS_V4
David Howells8fa5c002006-08-22 20:06:12 -0400507 if (nfss->nfs_client->cl_nfsversion == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400508 seq_printf(m, "\n\tnfsv4:\t");
509 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
510 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
511 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
512 }
513#endif
514
515 /*
516 * Display security flavor in effect for this mount
517 */
518 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
519 if (auth->au_flavor)
520 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
521
522 /*
523 * Display superblock I/O counters
524 */
525 for_each_possible_cpu(cpu) {
526 struct nfs_iostats *stats;
527
528 preempt_disable();
529 stats = per_cpu_ptr(nfss->io_stats, cpu);
530
531 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
532 totals.events[i] += stats->events[i];
533 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
534 totals.bytes[i] += stats->bytes[i];
535
536 preempt_enable();
537 }
538
539 seq_printf(m, "\n\tevents:\t");
540 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
541 seq_printf(m, "%lu ", totals.events[i]);
542 seq_printf(m, "\n\tbytes:\t");
543 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
544 seq_printf(m, "%Lu ", totals.bytes[i]);
545 seq_printf(m, "\n");
546
547 rpc_print_iostats(m, nfss->client);
548
549 return 0;
550}
551
552/*
553 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400554 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400555 */
556static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
557{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400558 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
559 struct rpc_clnt *rpc;
560
David Howellsf7b422b2006-06-09 09:34:33 -0400561 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400562
563 if (!(flags & MNT_FORCE))
564 return;
565 /* -EIO all pending I/O */
566 rpc = server->client_acl;
567 if (!IS_ERR(rpc))
568 rpc_killall_tasks(rpc);
569 rpc = server->client;
570 if (!IS_ERR(rpc))
571 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400572}
573
574/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400575 * Sanity-check a server address provided by the mount command
576 */
577static int nfs_verify_server_address(struct sockaddr *addr)
578{
579 switch (addr->sa_family) {
580 case AF_INET: {
581 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
582 if (sa->sin_addr.s_addr != INADDR_ANY)
583 return 1;
584 break;
585 }
586 }
587
588 return 0;
589}
590
591/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400592 * Error-check and convert a string of mount options from user space into
593 * a data structure
594 */
595static int nfs_parse_mount_options(char *raw,
596 struct nfs_parsed_mount_data *mnt)
597{
598 char *p, *string;
599
600 if (!raw) {
601 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
602 return 1;
603 }
604 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
605
606 while ((p = strsep(&raw, ",")) != NULL) {
607 substring_t args[MAX_OPT_ARGS];
608 int option, token;
609
610 if (!*p)
611 continue;
612
613 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
614
615 token = match_token(p, nfs_mount_option_tokens, args);
616 switch (token) {
617 case Opt_soft:
618 mnt->flags |= NFS_MOUNT_SOFT;
619 break;
620 case Opt_hard:
621 mnt->flags &= ~NFS_MOUNT_SOFT;
622 break;
623 case Opt_intr:
624 mnt->flags |= NFS_MOUNT_INTR;
625 break;
626 case Opt_nointr:
627 mnt->flags &= ~NFS_MOUNT_INTR;
628 break;
629 case Opt_posix:
630 mnt->flags |= NFS_MOUNT_POSIX;
631 break;
632 case Opt_noposix:
633 mnt->flags &= ~NFS_MOUNT_POSIX;
634 break;
635 case Opt_cto:
636 mnt->flags &= ~NFS_MOUNT_NOCTO;
637 break;
638 case Opt_nocto:
639 mnt->flags |= NFS_MOUNT_NOCTO;
640 break;
641 case Opt_ac:
642 mnt->flags &= ~NFS_MOUNT_NOAC;
643 break;
644 case Opt_noac:
645 mnt->flags |= NFS_MOUNT_NOAC;
646 break;
647 case Opt_lock:
648 mnt->flags &= ~NFS_MOUNT_NONLM;
649 break;
650 case Opt_nolock:
651 mnt->flags |= NFS_MOUNT_NONLM;
652 break;
653 case Opt_v2:
654 mnt->flags &= ~NFS_MOUNT_VER3;
655 break;
656 case Opt_v3:
657 mnt->flags |= NFS_MOUNT_VER3;
658 break;
659 case Opt_udp:
660 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400661 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400662 mnt->timeo = 7;
663 mnt->retrans = 5;
664 break;
665 case Opt_tcp:
666 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400667 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400668 mnt->timeo = 600;
669 mnt->retrans = 2;
670 break;
671 case Opt_acl:
672 mnt->flags &= ~NFS_MOUNT_NOACL;
673 break;
674 case Opt_noacl:
675 mnt->flags |= NFS_MOUNT_NOACL;
676 break;
677 case Opt_rdirplus:
678 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
679 break;
680 case Opt_nordirplus:
681 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
682 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400683 case Opt_sharecache:
684 mnt->flags &= ~NFS_MOUNT_UNSHARED;
685 break;
686 case Opt_nosharecache:
687 mnt->flags |= NFS_MOUNT_UNSHARED;
688 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400689
690 case Opt_port:
691 if (match_int(args, &option))
692 return 0;
693 if (option < 0 || option > 65535)
694 return 0;
Al Viro410896442007-07-22 10:59:06 +0100695 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400696 break;
697 case Opt_rsize:
698 if (match_int(args, &mnt->rsize))
699 return 0;
700 break;
701 case Opt_wsize:
702 if (match_int(args, &mnt->wsize))
703 return 0;
704 break;
705 case Opt_bsize:
706 if (match_int(args, &option))
707 return 0;
708 if (option < 0)
709 return 0;
710 mnt->bsize = option;
711 break;
712 case Opt_timeo:
713 if (match_int(args, &mnt->timeo))
714 return 0;
715 break;
716 case Opt_retrans:
717 if (match_int(args, &mnt->retrans))
718 return 0;
719 break;
720 case Opt_acregmin:
721 if (match_int(args, &mnt->acregmin))
722 return 0;
723 break;
724 case Opt_acregmax:
725 if (match_int(args, &mnt->acregmax))
726 return 0;
727 break;
728 case Opt_acdirmin:
729 if (match_int(args, &mnt->acdirmin))
730 return 0;
731 break;
732 case Opt_acdirmax:
733 if (match_int(args, &mnt->acdirmax))
734 return 0;
735 break;
736 case Opt_actimeo:
737 if (match_int(args, &option))
738 return 0;
739 if (option < 0)
740 return 0;
741 mnt->acregmin =
742 mnt->acregmax =
743 mnt->acdirmin =
744 mnt->acdirmax = option;
745 break;
746 case Opt_namelen:
747 if (match_int(args, &mnt->namlen))
748 return 0;
749 break;
750 case Opt_mountport:
751 if (match_int(args, &option))
752 return 0;
753 if (option < 0 || option > 65535)
754 return 0;
755 mnt->mount_server.port = option;
756 break;
757 case Opt_mountprog:
758 if (match_int(args, &option))
759 return 0;
760 if (option < 0)
761 return 0;
762 mnt->mount_server.program = option;
763 break;
764 case Opt_mountvers:
765 if (match_int(args, &option))
766 return 0;
767 if (option < 0)
768 return 0;
769 mnt->mount_server.version = option;
770 break;
771 case Opt_nfsprog:
772 if (match_int(args, &option))
773 return 0;
774 if (option < 0)
775 return 0;
776 mnt->nfs_server.program = option;
777 break;
778 case Opt_nfsvers:
779 if (match_int(args, &option))
780 return 0;
781 switch (option) {
782 case 2:
783 mnt->flags &= ~NFS_MOUNT_VER3;
784 break;
785 case 3:
786 mnt->flags |= NFS_MOUNT_VER3;
787 break;
788 default:
789 goto out_unrec_vers;
790 }
791 break;
792
793 case Opt_sec:
794 string = match_strdup(args);
795 if (string == NULL)
796 goto out_nomem;
797 token = match_token(string, nfs_secflavor_tokens, args);
798 kfree(string);
799
800 /*
801 * The flags setting is for v2/v3. The flavor_len
802 * setting is for v4. v2/v3 also need to know the
803 * difference between NULL and UNIX.
804 */
805 switch (token) {
806 case Opt_sec_none:
807 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
808 mnt->auth_flavor_len = 0;
809 mnt->auth_flavors[0] = RPC_AUTH_NULL;
810 break;
811 case Opt_sec_sys:
812 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
813 mnt->auth_flavor_len = 0;
814 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
815 break;
816 case Opt_sec_krb5:
817 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
818 mnt->auth_flavor_len = 1;
819 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
820 break;
821 case Opt_sec_krb5i:
822 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
823 mnt->auth_flavor_len = 1;
824 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
825 break;
826 case Opt_sec_krb5p:
827 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
828 mnt->auth_flavor_len = 1;
829 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
830 break;
831 case Opt_sec_lkey:
832 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
833 mnt->auth_flavor_len = 1;
834 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
835 break;
836 case Opt_sec_lkeyi:
837 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
838 mnt->auth_flavor_len = 1;
839 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
840 break;
841 case Opt_sec_lkeyp:
842 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
843 mnt->auth_flavor_len = 1;
844 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
845 break;
846 case Opt_sec_spkm:
847 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 1;
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
850 break;
851 case Opt_sec_spkmi:
852 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 1;
854 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
855 break;
856 case Opt_sec_spkmp:
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
860 break;
861 default:
862 goto out_unrec_sec;
863 }
864 break;
865 case Opt_proto:
866 string = match_strdup(args);
867 if (string == NULL)
868 goto out_nomem;
869 token = match_token(string,
870 nfs_xprt_protocol_tokens, args);
871 kfree(string);
872
873 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400874 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400875 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400876 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400877 mnt->timeo = 7;
878 mnt->retrans = 5;
879 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400880 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400881 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400882 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400883 mnt->timeo = 600;
884 mnt->retrans = 2;
885 break;
886 default:
887 goto out_unrec_xprt;
888 }
889 break;
890 case Opt_mountproto:
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:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400900 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400901 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400902 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400903 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400904 break;
905 default:
906 goto out_unrec_xprt;
907 }
908 break;
909 case Opt_addr:
910 string = match_strdup(args);
911 if (string == NULL)
912 goto out_nomem;
913 mnt->nfs_server.address.sin_family = AF_INET;
914 mnt->nfs_server.address.sin_addr.s_addr =
915 in_aton(string);
916 kfree(string);
917 break;
918 case Opt_clientaddr:
919 string = match_strdup(args);
920 if (string == NULL)
921 goto out_nomem;
922 mnt->client_address = string;
923 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400924 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400925 string = match_strdup(args);
926 if (string == NULL)
927 goto out_nomem;
928 mnt->mount_server.address.sin_family = AF_INET;
929 mnt->mount_server.address.sin_addr.s_addr =
930 in_aton(string);
931 kfree(string);
932 break;
933
934 case Opt_userspace:
935 case Opt_deprecated:
936 break;
937
938 default:
939 goto out_unknown;
940 }
941 }
942
943 return 1;
944
945out_nomem:
946 printk(KERN_INFO "NFS: not enough memory to parse option\n");
947 return 0;
948
949out_unrec_vers:
950 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
951 return 0;
952
953out_unrec_xprt:
954 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
955 return 0;
956
957out_unrec_sec:
958 printk(KERN_INFO "NFS: unrecognized security flavor\n");
959 return 0;
960
961out_unknown:
962 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
963 return 0;
964}
965
966/*
Chuck Lever0076d7b2007-07-01 12:13:49 -0400967 * Use the remote server's MOUNT service to request the NFS file handle
968 * corresponding to the provided path.
969 */
970static int nfs_try_mount(struct nfs_parsed_mount_data *args,
971 struct nfs_fh *root_fh)
972{
973 struct sockaddr_in sin;
974 int status;
975
976 if (args->mount_server.version == 0) {
977 if (args->flags & NFS_MOUNT_VER3)
978 args->mount_server.version = NFS_MNT3_VERSION;
979 else
980 args->mount_server.version = NFS_MNT_VERSION;
981 }
982
983 /*
984 * Construct the mount server's address.
985 */
986 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
987 sin = args->mount_server.address;
988 else
989 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -0400990 /*
991 * autobind will be used if mount_server.port == 0
992 */
993 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -0400994
995 /*
996 * Now ask the mount server to map our export path
997 * to a file handle.
998 */
999 status = nfs_mount((struct sockaddr *) &sin,
1000 sizeof(sin),
1001 args->nfs_server.hostname,
1002 args->nfs_server.export_path,
1003 args->mount_server.version,
1004 args->mount_server.protocol,
1005 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001006 if (status == 0)
1007 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001008
Chuck Leverefd83402007-09-11 18:00:58 -04001009 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1010 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001011 return status;
1012}
1013
1014/*
David Howells54ceac42006-08-22 20:06:13 -04001015 * Validate the NFS2/NFS3 mount data
1016 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001017 *
1018 * For option strings, user space handles the following behaviors:
1019 *
1020 * + DNS: mapping server host name to IP address ("addr=" option)
1021 *
1022 * + failure mode: how to behave if a mount request can't be handled
1023 * immediately ("fg/bg" option)
1024 *
1025 * + retry: how often to retry a mount request ("retry=" option)
1026 *
1027 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1028 * mountproto=tcp after mountproto=udp, and so on
1029 *
1030 * XXX: as far as I can tell, changing the NFS program number is not
1031 * supported in the NFS client.
David Howellsf7b422b2006-06-09 09:34:33 -04001032 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001033static int nfs_validate_mount_data(void *options,
1034 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001035 struct nfs_fh *mntfh,
1036 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001037{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001038 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001039
Chuck Lever5df36e72007-07-01 12:12:56 -04001040 if (data == NULL)
1041 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001042
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001043 memset(args, 0, sizeof(*args));
1044 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1045 args->rsize = NFS_MAX_FILE_IO_SIZE;
1046 args->wsize = NFS_MAX_FILE_IO_SIZE;
1047 args->timeo = 600;
1048 args->retrans = 2;
1049 args->acregmin = 3;
1050 args->acregmax = 60;
1051 args->acdirmin = 30;
1052 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001053 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001054 args->mount_server.program = NFS_MNT_PROGRAM;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001055 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001056 args->nfs_server.program = NFS_PROGRAM;
1057
David Howellsf7b422b2006-06-09 09:34:33 -04001058 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001059 case 1:
1060 data->namlen = 0;
1061 case 2:
1062 data->bsize = 0;
1063 case 3:
1064 if (data->flags & NFS_MOUNT_VER3)
1065 goto out_no_v3;
1066 data->root.size = NFS2_FHSIZE;
1067 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1068 case 4:
1069 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1070 goto out_no_sec;
1071 case 5:
1072 memset(data->context, 0, sizeof(data->context));
1073 case 6:
1074 if (data->flags & NFS_MOUNT_VER3)
1075 mntfh->size = data->root.size;
1076 else
1077 mntfh->size = NFS2_FHSIZE;
1078
1079 if (mntfh->size > sizeof(mntfh->data))
1080 goto out_invalid_fh;
1081
1082 memcpy(mntfh->data, data->root.data, mntfh->size);
1083 if (mntfh->size < sizeof(mntfh->data))
1084 memset(mntfh->data + mntfh->size, 0,
1085 sizeof(mntfh->data) - mntfh->size);
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001086 /*
1087 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1088 * can deal with.
1089 */
1090 args->flags = data->flags;
1091 args->rsize = data->rsize;
1092 args->wsize = data->wsize;
1093 args->flags = data->flags;
1094 args->timeo = data->timeo;
1095 args->retrans = data->retrans;
1096 args->acregmin = data->acregmin;
1097 args->acregmax = data->acregmax;
1098 args->acdirmin = data->acdirmin;
1099 args->acdirmax = data->acdirmax;
1100 args->nfs_server.address = data->addr;
1101 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001102 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001103 /* N.B. caller will free nfs_server.hostname in all cases */
1104 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1105 args->namlen = data->namlen;
1106 args->bsize = data->bsize;
1107 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001108 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001109 default: {
1110 unsigned int len;
1111 char *c;
1112 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001113
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001114 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001115 return -EINVAL;
1116
Chuck Lever136d5582007-07-01 12:13:54 -04001117 c = strchr(dev_name, ':');
1118 if (c == NULL)
1119 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001120 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001121 /* N.B. caller will free nfs_server.hostname in all cases */
1122 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001123
1124 c++;
1125 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001126 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001127 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001128
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001129 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001130 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001131 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001132
Chuck Lever136d5582007-07-01 12:13:54 -04001133 break;
1134 }
David Howellsf7b422b2006-06-09 09:34:33 -04001135 }
David Howells54ceac42006-08-22 20:06:13 -04001136
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001137 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1138 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001139
David Howellsf7b422b2006-06-09 09:34:33 -04001140#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001141 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001142 goto out_v3_not_compiled;
1143#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001144
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001145 if (!nfs_verify_server_address((struct sockaddr *)
1146 &args->nfs_server.address))
Chuck Lever5df36e72007-07-01 12:12:56 -04001147 goto out_no_address;
David Howells54ceac42006-08-22 20:06:13 -04001148
1149 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001150
1151out_no_data:
1152 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1153 return -EINVAL;
1154
1155out_no_v3:
1156 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1157 data->version);
1158 return -EINVAL;
1159
1160out_no_sec:
1161 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1162 return -EINVAL;
1163
Chuck Lever5df36e72007-07-01 12:12:56 -04001164#ifndef CONFIG_NFS_V3
1165out_v3_not_compiled:
1166 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1167 return -EPROTONOSUPPORT;
1168#endif /* !CONFIG_NFS_V3 */
1169
1170out_no_address:
1171 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1172 return -EINVAL;
1173
1174out_invalid_fh:
1175 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1176 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001177}
1178
1179/*
1180 * Initialise the common bits of the superblock
1181 */
1182static inline void nfs_initialise_sb(struct super_block *sb)
1183{
1184 struct nfs_server *server = NFS_SB(sb);
1185
1186 sb->s_magic = NFS_SUPER_MAGIC;
1187
1188 /* We probably want something more informative here */
1189 snprintf(sb->s_id, sizeof(sb->s_id),
1190 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1191
1192 if (sb->s_blocksize == 0)
1193 sb->s_blocksize = nfs_block_bits(server->wsize,
1194 &sb->s_blocksize_bits);
1195
1196 if (server->flags & NFS_MOUNT_NOAC)
1197 sb->s_flags |= MS_SYNCHRONOUS;
1198
1199 nfs_super_set_maxbytes(sb, server->maxfilesize);
1200}
1201
1202/*
1203 * Finish setting up an NFS2/3 superblock
1204 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001205static void nfs_fill_super(struct super_block *sb,
1206 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001207{
1208 struct nfs_server *server = NFS_SB(sb);
1209
1210 sb->s_blocksize_bits = 0;
1211 sb->s_blocksize = 0;
1212 if (data->bsize)
1213 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1214
1215 if (server->flags & NFS_MOUNT_VER3) {
1216 /* The VFS shouldn't apply the umask to mode bits. We will do
1217 * so ourselves when necessary.
1218 */
1219 sb->s_flags |= MS_POSIXACL;
1220 sb->s_time_gran = 1;
1221 }
1222
1223 sb->s_op = &nfs_sops;
1224 nfs_initialise_sb(sb);
1225}
1226
1227/*
1228 * Finish setting up a cloned NFS2/3 superblock
1229 */
1230static void nfs_clone_super(struct super_block *sb,
1231 const struct super_block *old_sb)
1232{
1233 struct nfs_server *server = NFS_SB(sb);
1234
1235 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1236 sb->s_blocksize = old_sb->s_blocksize;
1237 sb->s_maxbytes = old_sb->s_maxbytes;
1238
1239 if (server->flags & NFS_MOUNT_VER3) {
1240 /* The VFS shouldn't apply the umask to mode bits. We will do
1241 * so ourselves when necessary.
1242 */
1243 sb->s_flags |= MS_POSIXACL;
1244 sb->s_time_gran = 1;
1245 }
1246
1247 sb->s_op = old_sb->s_op;
1248 nfs_initialise_sb(sb);
1249}
1250
Trond Myklebust275a5d22007-05-16 16:53:28 -04001251#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1252
1253static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1254{
1255 const struct nfs_server *a = s->s_fs_info;
1256 const struct rpc_clnt *clnt_a = a->client;
1257 const struct rpc_clnt *clnt_b = b->client;
1258
1259 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1260 goto Ebusy;
1261 if (a->nfs_client != b->nfs_client)
1262 goto Ebusy;
1263 if (a->flags != b->flags)
1264 goto Ebusy;
1265 if (a->wsize != b->wsize)
1266 goto Ebusy;
1267 if (a->rsize != b->rsize)
1268 goto Ebusy;
1269 if (a->acregmin != b->acregmin)
1270 goto Ebusy;
1271 if (a->acregmax != b->acregmax)
1272 goto Ebusy;
1273 if (a->acdirmin != b->acdirmin)
1274 goto Ebusy;
1275 if (a->acdirmax != b->acdirmax)
1276 goto Ebusy;
1277 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1278 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001279 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001280Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001281 return 0;
1282}
1283
1284struct nfs_sb_mountdata {
1285 struct nfs_server *server;
1286 int mntflags;
1287};
1288
1289static int nfs_set_super(struct super_block *s, void *data)
1290{
1291 struct nfs_sb_mountdata *sb_mntdata = data;
1292 struct nfs_server *server = sb_mntdata->server;
1293 int ret;
1294
1295 s->s_flags = sb_mntdata->mntflags;
1296 s->s_fs_info = server;
1297 ret = set_anon_super(s, server);
1298 if (ret == 0)
1299 server->s_dev = s->s_dev;
1300 return ret;
1301}
1302
1303static int nfs_compare_super(struct super_block *sb, void *data)
1304{
1305 struct nfs_sb_mountdata *sb_mntdata = data;
1306 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1307 int mntflags = sb_mntdata->mntflags;
1308
1309 if (memcmp(&old->nfs_client->cl_addr,
1310 &server->nfs_client->cl_addr,
1311 sizeof(old->nfs_client->cl_addr)) != 0)
1312 return 0;
1313 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1314 if (old->flags & NFS_MOUNT_UNSHARED)
1315 return 0;
1316 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1317 return 0;
1318 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001319}
1320
David Howells54ceac42006-08-22 20:06:13 -04001321static int nfs_get_sb(struct file_system_type *fs_type,
1322 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1323{
1324 struct nfs_server *server = NULL;
1325 struct super_block *s;
1326 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001327 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001328 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001329 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001330 struct nfs_sb_mountdata sb_mntdata = {
1331 .mntflags = flags,
1332 };
David Howells54ceac42006-08-22 20:06:13 -04001333 int error;
1334
1335 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001336 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001337 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001338 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001339
1340 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001341 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001342 if (IS_ERR(server)) {
1343 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001344 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001345 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001346 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001347
Trond Myklebust75180df2007-05-16 16:53:28 -04001348 if (server->flags & NFS_MOUNT_UNSHARED)
1349 compare_super = NULL;
1350
David Howells54ceac42006-08-22 20:06:13 -04001351 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001352 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001353 if (IS_ERR(s)) {
1354 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001355 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001356 }
1357
David Howells54ceac42006-08-22 20:06:13 -04001358 if (s->s_fs_info != server) {
1359 nfs_free_server(server);
1360 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001361 }
David Howells54ceac42006-08-22 20:06:13 -04001362
1363 if (!s->s_root) {
1364 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001365 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001366 }
1367
1368 mntroot = nfs_get_root(s, &mntfh);
1369 if (IS_ERR(mntroot)) {
1370 error = PTR_ERR(mntroot);
1371 goto error_splat_super;
1372 }
1373
David Howellsf7b422b2006-06-09 09:34:33 -04001374 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001375 mnt->mnt_sb = s;
1376 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001377 error = 0;
1378
1379out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001380 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001381 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001382
David Howells54ceac42006-08-22 20:06:13 -04001383out_err_nosb:
1384 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001385 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001386
1387error_splat_super:
1388 up_write(&s->s_umount);
1389 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001390 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001391}
1392
David Howells54ceac42006-08-22 20:06:13 -04001393/*
1394 * Destroy an NFS2/3 superblock
1395 */
David Howellsf7b422b2006-06-09 09:34:33 -04001396static void nfs_kill_super(struct super_block *s)
1397{
1398 struct nfs_server *server = NFS_SB(s);
1399
1400 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001401 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001402}
1403
David Howells54ceac42006-08-22 20:06:13 -04001404/*
1405 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1406 */
1407static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1408 const char *dev_name, void *raw_data,
1409 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001410{
1411 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001412 struct super_block *s;
1413 struct nfs_server *server;
1414 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001415 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001416 struct nfs_sb_mountdata sb_mntdata = {
1417 .mntflags = flags,
1418 };
David Howells54ceac42006-08-22 20:06:13 -04001419 int error;
1420
1421 dprintk("--> nfs_xdev_get_sb()\n");
1422
1423 /* create a new volume representation */
1424 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1425 if (IS_ERR(server)) {
1426 error = PTR_ERR(server);
1427 goto out_err_noserver;
1428 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001429 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001430
Trond Myklebust75180df2007-05-16 16:53:28 -04001431 if (server->flags & NFS_MOUNT_UNSHARED)
1432 compare_super = NULL;
1433
David Howells54ceac42006-08-22 20:06:13 -04001434 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001435 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001436 if (IS_ERR(s)) {
1437 error = PTR_ERR(s);
1438 goto out_err_nosb;
1439 }
1440
1441 if (s->s_fs_info != server) {
1442 nfs_free_server(server);
1443 server = NULL;
1444 }
1445
1446 if (!s->s_root) {
1447 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001448 nfs_clone_super(s, data->sb);
1449 }
1450
1451 mntroot = nfs_get_root(s, data->fh);
1452 if (IS_ERR(mntroot)) {
1453 error = PTR_ERR(mntroot);
1454 goto error_splat_super;
1455 }
1456
1457 s->s_flags |= MS_ACTIVE;
1458 mnt->mnt_sb = s;
1459 mnt->mnt_root = mntroot;
1460
1461 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1462 return 0;
1463
1464out_err_nosb:
1465 nfs_free_server(server);
1466out_err_noserver:
1467 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1468 return error;
1469
1470error_splat_super:
1471 up_write(&s->s_umount);
1472 deactivate_super(s);
1473 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1474 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001475}
1476
1477#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001478
1479/*
1480 * Finish setting up a cloned NFS4 superblock
1481 */
1482static void nfs4_clone_super(struct super_block *sb,
1483 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001484{
David Howells54ceac42006-08-22 20:06:13 -04001485 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1486 sb->s_blocksize = old_sb->s_blocksize;
1487 sb->s_maxbytes = old_sb->s_maxbytes;
1488 sb->s_time_gran = 1;
1489 sb->s_op = old_sb->s_op;
1490 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001491}
1492
1493/*
1494 * Set up an NFS4 superblock
1495 */
David Howells54ceac42006-08-22 20:06:13 -04001496static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001497{
David Howellsf7b422b2006-06-09 09:34:33 -04001498 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001499 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001500 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001501}
1502
David Howells54ceac42006-08-22 20:06:13 -04001503/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001504 * Validate NFSv4 mount options
1505 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001506static int nfs4_validate_mount_data(void *options,
1507 struct nfs_parsed_mount_data *args,
1508 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001509{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001510 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001511 char *c;
1512
1513 if (data == NULL)
1514 goto out_no_data;
1515
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001516 memset(args, 0, sizeof(*args));
1517 args->rsize = NFS_MAX_FILE_IO_SIZE;
1518 args->wsize = NFS_MAX_FILE_IO_SIZE;
1519 args->timeo = 600;
1520 args->retrans = 2;
1521 args->acregmin = 3;
1522 args->acregmax = 60;
1523 args->acdirmin = 30;
1524 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001525 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001526
Chuck Leverf0768eb2007-07-01 12:13:01 -04001527 switch (data->version) {
1528 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001529 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001530 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001531 if (copy_from_user(&args->nfs_server.address,
1532 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001533 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001534 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001535 if (args->nfs_server.address.sin_port == 0)
1536 args->nfs_server.address.sin_port = htons(NFS_PORT);
1537 if (!nfs_verify_server_address((struct sockaddr *)
1538 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001539 goto out_no_address;
1540
1541 switch (data->auth_flavourlen) {
1542 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001543 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001544 break;
1545 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001546 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001547 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001548 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001549 return -EFAULT;
1550 break;
1551 default:
1552 goto out_inval_auth;
1553 }
1554
1555 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1556 if (IS_ERR(c))
1557 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001558 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001559
1560 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1561 if (IS_ERR(c))
1562 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001563 args->nfs_server.export_path = c;
1564 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001565
1566 c = strndup_user(data->client_addr.data, 16);
1567 if (IS_ERR(c))
1568 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001569 args->client_address = c;
1570
1571 /*
1572 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1573 * can deal with.
1574 */
1575
1576 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1577 args->rsize = data->rsize;
1578 args->wsize = data->wsize;
1579 args->timeo = data->timeo;
1580 args->retrans = data->retrans;
1581 args->acregmin = data->acregmin;
1582 args->acregmax = data->acregmax;
1583 args->acdirmin = data->acdirmin;
1584 args->acdirmax = data->acdirmax;
1585 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001586
1587 break;
Chuck Lever80071222007-07-01 12:13:59 -04001588 default: {
1589 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001590
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001591 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001592 return -EINVAL;
1593
1594 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001595 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001596 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001597
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001598 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001599 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001600 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001601 break;
1602 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001603 break;
1604 default:
1605 goto out_inval_auth;
1606 }
1607
1608 /*
Chuck Lever80071222007-07-01 12:13:59 -04001609 * Split "dev_name" into "hostname:mntpath".
1610 */
1611 c = strchr(dev_name, ':');
1612 if (c == NULL)
1613 return -EINVAL;
1614 /* while calculating len, pretend ':' is '\0' */
1615 len = c - dev_name;
1616 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001617 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001618 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1619 if (args->nfs_server.hostname == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001620 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001621 strncpy(args->nfs_server.hostname, dev_name, len - 1);
Chuck Lever80071222007-07-01 12:13:59 -04001622
1623 c++; /* step over the ':' */
1624 len = strlen(c);
1625 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001626 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001627 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1628 if (args->nfs_server.export_path == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001629 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001630 strncpy(args->nfs_server.export_path, c, len);
Chuck Lever80071222007-07-01 12:13:59 -04001631
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001632 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001633
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001634 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001635 goto out_no_client_address;
1636
Chuck Lever80071222007-07-01 12:13:59 -04001637 break;
1638 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001639 }
1640
1641 return 0;
1642
1643out_no_data:
1644 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1645 return -EINVAL;
1646
1647out_inval_auth:
1648 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1649 data->auth_flavourlen);
1650 return -EINVAL;
1651
1652out_no_address:
1653 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1654 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001655
1656out_no_client_address:
1657 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1658 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001659}
1660
1661/*
David Howells54ceac42006-08-22 20:06:13 -04001662 * Get the superblock for an NFS4 mountpoint
1663 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001664static int nfs4_get_sb(struct file_system_type *fs_type,
1665 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001666{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001667 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001668 struct super_block *s;
1669 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001670 struct nfs_fh mntfh;
1671 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001672 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001673 struct nfs_sb_mountdata sb_mntdata = {
1674 .mntflags = flags,
1675 };
David Howells54ceac42006-08-22 20:06:13 -04001676 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001677
Chuck Leverf0768eb2007-07-01 12:13:01 -04001678 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001679 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001680 if (error < 0)
1681 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001682
David Howells54ceac42006-08-22 20:06:13 -04001683 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001684 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001685 if (IS_ERR(server)) {
1686 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001687 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001688 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001689 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001690
Trond Myklebust75180df2007-05-16 16:53:28 -04001691 if (server->flags & NFS4_MOUNT_UNSHARED)
1692 compare_super = NULL;
1693
David Howells54ceac42006-08-22 20:06:13 -04001694 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001695 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001696 if (IS_ERR(s)) {
1697 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001698 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001699 }
1700
Trond Myklebust5dd31772006-08-24 01:03:05 -04001701 if (s->s_fs_info != server) {
1702 nfs_free_server(server);
1703 server = NULL;
1704 }
1705
David Howells54ceac42006-08-22 20:06:13 -04001706 if (!s->s_root) {
1707 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001708 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001709 }
David Howellsf7b422b2006-06-09 09:34:33 -04001710
David Howells54ceac42006-08-22 20:06:13 -04001711 mntroot = nfs4_get_root(s, &mntfh);
1712 if (IS_ERR(mntroot)) {
1713 error = PTR_ERR(mntroot);
1714 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001715 }
David Howells54ceac42006-08-22 20:06:13 -04001716
David Howellsf7b422b2006-06-09 09:34:33 -04001717 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001718 mnt->mnt_sb = s;
1719 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001720 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001721
Chuck Lever29eb9812007-07-01 12:12:30 -04001722out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001723 kfree(data.client_address);
1724 kfree(data.nfs_server.export_path);
1725 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001726 return error;
David Howells54ceac42006-08-22 20:06:13 -04001727
Chuck Lever29eb9812007-07-01 12:12:30 -04001728out_free:
1729 nfs_free_server(server);
1730 goto out;
1731
David Howells54ceac42006-08-22 20:06:13 -04001732error_splat_super:
1733 up_write(&s->s_umount);
1734 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001735 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001736}
1737
1738static void nfs4_kill_super(struct super_block *sb)
1739{
1740 struct nfs_server *server = NFS_SB(sb);
1741
1742 nfs_return_all_delegations(sb);
1743 kill_anon_super(sb);
1744
1745 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001746 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001747}
1748
1749/*
David Howells54ceac42006-08-22 20:06:13 -04001750 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001751 */
David Howells54ceac42006-08-22 20:06:13 -04001752static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1753 const char *dev_name, void *raw_data,
1754 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001755{
1756 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001757 struct super_block *s;
1758 struct nfs_server *server;
1759 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001760 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001761 struct nfs_sb_mountdata sb_mntdata = {
1762 .mntflags = flags,
1763 };
David Howells54ceac42006-08-22 20:06:13 -04001764 int error;
1765
1766 dprintk("--> nfs4_xdev_get_sb()\n");
1767
1768 /* create a new volume representation */
1769 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1770 if (IS_ERR(server)) {
1771 error = PTR_ERR(server);
1772 goto out_err_noserver;
1773 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001774 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001775
Trond Myklebust75180df2007-05-16 16:53:28 -04001776 if (server->flags & NFS4_MOUNT_UNSHARED)
1777 compare_super = NULL;
1778
David Howells54ceac42006-08-22 20:06:13 -04001779 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001780 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001781 if (IS_ERR(s)) {
1782 error = PTR_ERR(s);
1783 goto out_err_nosb;
1784 }
1785
1786 if (s->s_fs_info != server) {
1787 nfs_free_server(server);
1788 server = NULL;
1789 }
1790
1791 if (!s->s_root) {
1792 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001793 nfs4_clone_super(s, data->sb);
1794 }
1795
1796 mntroot = nfs4_get_root(s, data->fh);
1797 if (IS_ERR(mntroot)) {
1798 error = PTR_ERR(mntroot);
1799 goto error_splat_super;
1800 }
1801
1802 s->s_flags |= MS_ACTIVE;
1803 mnt->mnt_sb = s;
1804 mnt->mnt_root = mntroot;
1805
1806 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1807 return 0;
1808
1809out_err_nosb:
1810 nfs_free_server(server);
1811out_err_noserver:
1812 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1813 return error;
1814
1815error_splat_super:
1816 up_write(&s->s_umount);
1817 deactivate_super(s);
1818 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1819 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001820}
1821
David Howells54ceac42006-08-22 20:06:13 -04001822/*
1823 * Create an NFS4 server record on referral traversal
1824 */
1825static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1826 const char *dev_name, void *raw_data,
1827 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001828{
1829 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001830 struct super_block *s;
1831 struct nfs_server *server;
1832 struct dentry *mntroot;
1833 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001834 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001835 struct nfs_sb_mountdata sb_mntdata = {
1836 .mntflags = flags,
1837 };
David Howells54ceac42006-08-22 20:06:13 -04001838 int error;
1839
1840 dprintk("--> nfs4_referral_get_sb()\n");
1841
1842 /* create a new volume representation */
1843 server = nfs4_create_referral_server(data, &mntfh);
1844 if (IS_ERR(server)) {
1845 error = PTR_ERR(server);
1846 goto out_err_noserver;
1847 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001848 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001849
Trond Myklebust75180df2007-05-16 16:53:28 -04001850 if (server->flags & NFS4_MOUNT_UNSHARED)
1851 compare_super = NULL;
1852
David Howells54ceac42006-08-22 20:06:13 -04001853 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001854 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001855 if (IS_ERR(s)) {
1856 error = PTR_ERR(s);
1857 goto out_err_nosb;
1858 }
1859
1860 if (s->s_fs_info != server) {
1861 nfs_free_server(server);
1862 server = NULL;
1863 }
1864
1865 if (!s->s_root) {
1866 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001867 nfs4_fill_super(s);
1868 }
1869
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001870 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001871 if (IS_ERR(mntroot)) {
1872 error = PTR_ERR(mntroot);
1873 goto error_splat_super;
1874 }
1875
1876 s->s_flags |= MS_ACTIVE;
1877 mnt->mnt_sb = s;
1878 mnt->mnt_root = mntroot;
1879
1880 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1881 return 0;
1882
1883out_err_nosb:
1884 nfs_free_server(server);
1885out_err_noserver:
1886 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1887 return error;
1888
1889error_splat_super:
1890 up_write(&s->s_umount);
1891 deactivate_super(s);
1892 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1893 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001894}
1895
David Howells54ceac42006-08-22 20:06:13 -04001896#endif /* CONFIG_NFS_V4 */