blob: 3804aadc18c409e165a836d0562c8adfdd2480c8 [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>
36#include <linux/nfs_fs.h>
37#include <linux/nfs_mount.h>
38#include <linux/nfs4_mount.h>
39#include <linux/lockd/bind.h>
40#include <linux/smp_lock.h>
41#include <linux/seq_file.h>
42#include <linux/mount.h>
43#include <linux/nfs_idmap.h>
44#include <linux/vfs.h>
45#include <linux/inet.h>
46#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080047#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040048#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040049
50#include <asm/system.h>
51#include <asm/uaccess.h>
52
53#include "nfs4_fs.h"
54#include "callback.h"
55#include "delegation.h"
56#include "iostat.h"
57#include "internal.h"
58
59#define NFSDBG_FACILITY NFSDBG_VFS
60
Chuck Leverbf0fd762007-07-01 12:13:44 -040061enum {
62 /* Mount options that take no arguments */
63 Opt_soft, Opt_hard,
64 Opt_intr, Opt_nointr,
65 Opt_posix, Opt_noposix,
66 Opt_cto, Opt_nocto,
67 Opt_ac, Opt_noac,
68 Opt_lock, Opt_nolock,
69 Opt_v2, Opt_v3,
70 Opt_udp, Opt_tcp,
71 Opt_acl, Opt_noacl,
72 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040073 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040074
75 /* Mount options that take integer arguments */
76 Opt_port,
77 Opt_rsize, Opt_wsize, Opt_bsize,
78 Opt_timeo, Opt_retrans,
79 Opt_acregmin, Opt_acregmax,
80 Opt_acdirmin, Opt_acdirmax,
81 Opt_actimeo,
82 Opt_namelen,
83 Opt_mountport,
84 Opt_mountprog, Opt_mountvers,
85 Opt_nfsprog, Opt_nfsvers,
86
87 /* Mount options that take string arguments */
88 Opt_sec, Opt_proto, Opt_mountproto,
Chuck Lever0ac83772007-09-11 18:01:04 -040089 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that are ignored */
92 Opt_userspace, Opt_deprecated,
93
94 Opt_err
95};
96
97static match_table_t nfs_mount_option_tokens = {
98 { Opt_userspace, "bg" },
99 { Opt_userspace, "fg" },
100 { Opt_soft, "soft" },
101 { Opt_hard, "hard" },
102 { Opt_intr, "intr" },
103 { Opt_nointr, "nointr" },
104 { Opt_posix, "posix" },
105 { Opt_noposix, "noposix" },
106 { Opt_cto, "cto" },
107 { Opt_nocto, "nocto" },
108 { Opt_ac, "ac" },
109 { Opt_noac, "noac" },
110 { Opt_lock, "lock" },
111 { Opt_nolock, "nolock" },
112 { Opt_v2, "v2" },
113 { Opt_v3, "v3" },
114 { Opt_udp, "udp" },
115 { Opt_tcp, "tcp" },
116 { Opt_acl, "acl" },
117 { Opt_noacl, "noacl" },
118 { Opt_rdirplus, "rdirplus" },
119 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400120 { Opt_sharecache, "sharecache" },
121 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400122
123 { Opt_port, "port=%u" },
124 { Opt_rsize, "rsize=%u" },
125 { Opt_wsize, "wsize=%u" },
126 { Opt_bsize, "bsize=%u" },
127 { Opt_timeo, "timeo=%u" },
128 { Opt_retrans, "retrans=%u" },
129 { Opt_acregmin, "acregmin=%u" },
130 { Opt_acregmax, "acregmax=%u" },
131 { Opt_acdirmin, "acdirmin=%u" },
132 { Opt_acdirmax, "acdirmax=%u" },
133 { Opt_actimeo, "actimeo=%u" },
134 { Opt_userspace, "retry=%u" },
135 { Opt_namelen, "namlen=%u" },
136 { Opt_mountport, "mountport=%u" },
137 { Opt_mountprog, "mountprog=%u" },
138 { Opt_mountvers, "mountvers=%u" },
139 { Opt_nfsprog, "nfsprog=%u" },
140 { Opt_nfsvers, "nfsvers=%u" },
141 { Opt_nfsvers, "vers=%u" },
142
143 { Opt_sec, "sec=%s" },
144 { Opt_proto, "proto=%s" },
145 { Opt_mountproto, "mountproto=%s" },
146 { Opt_addr, "addr=%s" },
147 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400148 { Opt_userspace, "mounthost=%s" },
149 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400150
151 { Opt_err, NULL }
152};
153
154enum {
155 Opt_xprt_udp, Opt_xprt_tcp,
156
157 Opt_xprt_err
158};
159
160static match_table_t nfs_xprt_protocol_tokens = {
161 { Opt_xprt_udp, "udp" },
162 { Opt_xprt_tcp, "tcp" },
163
164 { Opt_xprt_err, NULL }
165};
166
167enum {
168 Opt_sec_none, Opt_sec_sys,
169 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
170 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
171 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
172
173 Opt_sec_err
174};
175
176static match_table_t nfs_secflavor_tokens = {
177 { Opt_sec_none, "none" },
178 { Opt_sec_none, "null" },
179 { Opt_sec_sys, "sys" },
180
181 { Opt_sec_krb5, "krb5" },
182 { Opt_sec_krb5i, "krb5i" },
183 { Opt_sec_krb5p, "krb5p" },
184
185 { Opt_sec_lkey, "lkey" },
186 { Opt_sec_lkeyi, "lkeyi" },
187 { Opt_sec_lkeyp, "lkeyp" },
188
189 { Opt_sec_err, NULL }
190};
191
192
David Howellsf7b422b2006-06-09 09:34:33 -0400193static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400194static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400195static int nfs_show_options(struct seq_file *, struct vfsmount *);
196static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400197static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400198static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400199 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400200static void nfs_kill_super(struct super_block *);
201
202static struct file_system_type nfs_fs_type = {
203 .owner = THIS_MODULE,
204 .name = "nfs",
205 .get_sb = nfs_get_sb,
206 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700207 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400208};
209
David Howells54ceac42006-08-22 20:06:13 -0400210struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400211 .owner = THIS_MODULE,
212 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400213 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400214 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700215 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400216};
217
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800218static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400219 .alloc_inode = nfs_alloc_inode,
220 .destroy_inode = nfs_destroy_inode,
221 .write_inode = nfs_write_inode,
222 .statfs = nfs_statfs,
223 .clear_inode = nfs_clear_inode,
224 .umount_begin = nfs_umount_begin,
225 .show_options = nfs_show_options,
226 .show_stats = nfs_show_stats,
227};
228
229#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400230static int nfs4_get_sb(struct file_system_type *fs_type,
231 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400232static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
233 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
234static int nfs4_referral_get_sb(struct file_system_type *fs_type,
235 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400236static void nfs4_kill_super(struct super_block *sb);
237
238static struct file_system_type nfs4_fs_type = {
239 .owner = THIS_MODULE,
240 .name = "nfs4",
241 .get_sb = nfs4_get_sb,
242 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700243 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400244};
245
David Howells54ceac42006-08-22 20:06:13 -0400246struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400247 .owner = THIS_MODULE,
248 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400249 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400250 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700251 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400252};
253
David Howells54ceac42006-08-22 20:06:13 -0400254struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400255 .owner = THIS_MODULE,
256 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400257 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400258 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700259 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400260};
261
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800262static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .alloc_inode = nfs_alloc_inode,
264 .destroy_inode = nfs_destroy_inode,
265 .write_inode = nfs_write_inode,
266 .statfs = nfs_statfs,
267 .clear_inode = nfs4_clear_inode,
268 .umount_begin = nfs_umount_begin,
269 .show_options = nfs_show_options,
270 .show_stats = nfs_show_stats,
271};
272#endif
273
Rusty Russell8e1f9362007-07-17 04:03:17 -0700274static struct shrinker acl_shrinker = {
275 .shrink = nfs_access_cache_shrinker,
276 .seeks = DEFAULT_SEEKS,
277};
Trond Myklebust979df722006-07-25 11:28:19 -0400278
David Howellsf7b422b2006-06-09 09:34:33 -0400279/*
280 * Register the NFS filesystems
281 */
282int __init register_nfs_fs(void)
283{
284 int ret;
285
286 ret = register_filesystem(&nfs_fs_type);
287 if (ret < 0)
288 goto error_0;
289
David Howellsf7b422b2006-06-09 09:34:33 -0400290 ret = nfs_register_sysctl();
291 if (ret < 0)
292 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800293#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400294 ret = register_filesystem(&nfs4_fs_type);
295 if (ret < 0)
296 goto error_2;
297#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700298 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400299 return 0;
300
301#ifdef CONFIG_NFS_V4
302error_2:
303 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800304#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400305error_1:
306 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400307error_0:
308 return ret;
309}
310
311/*
312 * Unregister the NFS filesystems
313 */
314void __exit unregister_nfs_fs(void)
315{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700316 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400317#ifdef CONFIG_NFS_V4
318 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400319#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700320 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400321 unregister_filesystem(&nfs_fs_type);
322}
323
324/*
325 * Deliver file system statistics to userspace
326 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400327static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400328{
David Howells0c7d90c2006-08-22 20:06:10 -0400329 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400330 unsigned char blockbits;
331 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400332 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400333 struct nfs_fattr fattr;
334 struct nfs_fsstat res = {
335 .fattr = &fattr,
336 };
337 int error;
338
339 lock_kernel();
340
David Howells8fa5c002006-08-22 20:06:12 -0400341 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400342 if (error < 0)
343 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700344 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400345
346 /*
347 * Current versions of glibc do not correctly handle the
348 * case where f_frsize != f_bsize. Eventually we want to
349 * report the value of wtmult in this field.
350 */
David Howells0c7d90c2006-08-22 20:06:10 -0400351 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400352
353 /*
354 * On most *nix systems, f_blocks, f_bfree, and f_bavail
355 * are reported in units of f_frsize. Linux hasn't had
356 * an f_frsize field in its statfs struct until recently,
357 * thus historically Linux's sys_statfs reports these
358 * fields in units of f_bsize.
359 */
David Howells0c7d90c2006-08-22 20:06:10 -0400360 buf->f_bsize = dentry->d_sb->s_blocksize;
361 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400362 blockres = (1 << blockbits) - 1;
363 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
364 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
365 buf->f_bavail = (res.abytes + blockres) >> blockbits;
366
367 buf->f_files = res.tfiles;
368 buf->f_ffree = res.afiles;
369
370 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700371
David Howellsf7b422b2006-06-09 09:34:33 -0400372 unlock_kernel();
373 return 0;
374
375 out_err:
376 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700377 unlock_kernel();
378 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400379}
380
David Howells7d4e2742006-08-22 20:06:07 -0400381/*
382 * Map the security flavour number to a name
383 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400384static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
385{
David Howells7d4e2742006-08-22 20:06:07 -0400386 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400387 rpc_authflavor_t flavour;
388 const char *str;
389 } sec_flavours[] = {
390 { RPC_AUTH_NULL, "null" },
391 { RPC_AUTH_UNIX, "sys" },
392 { RPC_AUTH_GSS_KRB5, "krb5" },
393 { RPC_AUTH_GSS_KRB5I, "krb5i" },
394 { RPC_AUTH_GSS_KRB5P, "krb5p" },
395 { RPC_AUTH_GSS_LKEY, "lkey" },
396 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
397 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
398 { RPC_AUTH_GSS_SPKM, "spkm" },
399 { RPC_AUTH_GSS_SPKMI, "spkmi" },
400 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400401 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400402 };
403 int i;
404
Chuck Lever4d81cd12007-07-01 12:12:40 -0400405 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400406 if (sec_flavours[i].flavour == flavour)
407 break;
408 }
409 return sec_flavours[i].str;
410}
411
David Howellsf7b422b2006-06-09 09:34:33 -0400412/*
413 * Describe the mount options in force on this server representation
414 */
415static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
416{
David Howells509de812006-08-22 20:06:11 -0400417 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400418 int flag;
David Howells509de812006-08-22 20:06:11 -0400419 const char *str;
420 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400421 } nfs_info[] = {
422 { NFS_MOUNT_SOFT, ",soft", ",hard" },
423 { NFS_MOUNT_INTR, ",intr", "" },
424 { NFS_MOUNT_NOCTO, ",nocto", "" },
425 { NFS_MOUNT_NOAC, ",noac", "" },
426 { NFS_MOUNT_NONLM, ",nolock", "" },
427 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400428 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400429 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400430 { 0, NULL, NULL }
431 };
David Howells509de812006-08-22 20:06:11 -0400432 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400433 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400434 char buf[12];
David Howells509de812006-08-22 20:06:11 -0400435 const char *proto;
David Howellsf7b422b2006-06-09 09:34:33 -0400436
David Howells8fa5c002006-08-22 20:06:12 -0400437 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400438 seq_printf(m, ",rsize=%d", nfss->rsize);
439 seq_printf(m, ",wsize=%d", nfss->wsize);
440 if (nfss->acregmin != 3*HZ || showdefaults)
441 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
442 if (nfss->acregmax != 60*HZ || showdefaults)
443 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
444 if (nfss->acdirmin != 30*HZ || showdefaults)
445 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
446 if (nfss->acdirmax != 60*HZ || showdefaults)
447 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
448 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
449 if (nfss->flags & nfs_infop->flag)
450 seq_puts(m, nfs_infop->str);
451 else
452 seq_puts(m, nfs_infop->nostr);
453 }
454 switch (nfss->client->cl_xprt->prot) {
455 case IPPROTO_TCP:
456 proto = "tcp";
457 break;
458 case IPPROTO_UDP:
459 proto = "udp";
460 break;
461 default:
462 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
463 proto = buf;
464 }
465 seq_printf(m, ",proto=%s", proto);
David Howells5006a762006-08-22 20:06:12 -0400466 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
467 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400468 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400469}
470
471/*
472 * Describe the mount options on this VFS mountpoint
473 */
474static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
475{
476 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
477
478 nfs_show_mount_options(m, nfss, 0);
479
Jeff Laytonddc01c02007-07-30 08:47:38 -0400480 seq_printf(m, ",addr="NIPQUAD_FMT,
481 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
David Howellsf7b422b2006-06-09 09:34:33 -0400482
483 return 0;
484}
485
486/*
487 * Present statistical information for this VFS mountpoint
488 */
489static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
490{
491 int i, cpu;
492 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
493 struct rpc_auth *auth = nfss->client->cl_auth;
494 struct nfs_iostats totals = { };
495
496 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
497
498 /*
499 * Display all mount option settings
500 */
501 seq_printf(m, "\n\topts:\t");
502 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
503 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
504 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
505 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
506 nfs_show_mount_options(m, nfss, 1);
507
508 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
509
510 seq_printf(m, "\n\tcaps:\t");
511 seq_printf(m, "caps=0x%x", nfss->caps);
512 seq_printf(m, ",wtmult=%d", nfss->wtmult);
513 seq_printf(m, ",dtsize=%d", nfss->dtsize);
514 seq_printf(m, ",bsize=%d", nfss->bsize);
515 seq_printf(m, ",namelen=%d", nfss->namelen);
516
517#ifdef CONFIG_NFS_V4
David Howells8fa5c002006-08-22 20:06:12 -0400518 if (nfss->nfs_client->cl_nfsversion == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400519 seq_printf(m, "\n\tnfsv4:\t");
520 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
521 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
522 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
523 }
524#endif
525
526 /*
527 * Display security flavor in effect for this mount
528 */
529 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
530 if (auth->au_flavor)
531 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
532
533 /*
534 * Display superblock I/O counters
535 */
536 for_each_possible_cpu(cpu) {
537 struct nfs_iostats *stats;
538
539 preempt_disable();
540 stats = per_cpu_ptr(nfss->io_stats, cpu);
541
542 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
543 totals.events[i] += stats->events[i];
544 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
545 totals.bytes[i] += stats->bytes[i];
546
547 preempt_enable();
548 }
549
550 seq_printf(m, "\n\tevents:\t");
551 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
552 seq_printf(m, "%lu ", totals.events[i]);
553 seq_printf(m, "\n\tbytes:\t");
554 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
555 seq_printf(m, "%Lu ", totals.bytes[i]);
556 seq_printf(m, "\n");
557
558 rpc_print_iostats(m, nfss->client);
559
560 return 0;
561}
562
563/*
564 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400565 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400566 */
567static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
568{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400569 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
570 struct rpc_clnt *rpc;
571
David Howellsf7b422b2006-06-09 09:34:33 -0400572 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400573
574 if (!(flags & MNT_FORCE))
575 return;
576 /* -EIO all pending I/O */
577 rpc = server->client_acl;
578 if (!IS_ERR(rpc))
579 rpc_killall_tasks(rpc);
580 rpc = server->client;
581 if (!IS_ERR(rpc))
582 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400583}
584
585/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400586 * Sanity-check a server address provided by the mount command
587 */
588static int nfs_verify_server_address(struct sockaddr *addr)
589{
590 switch (addr->sa_family) {
591 case AF_INET: {
592 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
593 if (sa->sin_addr.s_addr != INADDR_ANY)
594 return 1;
595 break;
596 }
597 }
598
599 return 0;
600}
601
602/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400603 * Error-check and convert a string of mount options from user space into
604 * a data structure
605 */
606static int nfs_parse_mount_options(char *raw,
607 struct nfs_parsed_mount_data *mnt)
608{
609 char *p, *string;
610
611 if (!raw) {
612 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
613 return 1;
614 }
615 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
616
617 while ((p = strsep(&raw, ",")) != NULL) {
618 substring_t args[MAX_OPT_ARGS];
619 int option, token;
620
621 if (!*p)
622 continue;
623
624 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
625
626 token = match_token(p, nfs_mount_option_tokens, args);
627 switch (token) {
628 case Opt_soft:
629 mnt->flags |= NFS_MOUNT_SOFT;
630 break;
631 case Opt_hard:
632 mnt->flags &= ~NFS_MOUNT_SOFT;
633 break;
634 case Opt_intr:
635 mnt->flags |= NFS_MOUNT_INTR;
636 break;
637 case Opt_nointr:
638 mnt->flags &= ~NFS_MOUNT_INTR;
639 break;
640 case Opt_posix:
641 mnt->flags |= NFS_MOUNT_POSIX;
642 break;
643 case Opt_noposix:
644 mnt->flags &= ~NFS_MOUNT_POSIX;
645 break;
646 case Opt_cto:
647 mnt->flags &= ~NFS_MOUNT_NOCTO;
648 break;
649 case Opt_nocto:
650 mnt->flags |= NFS_MOUNT_NOCTO;
651 break;
652 case Opt_ac:
653 mnt->flags &= ~NFS_MOUNT_NOAC;
654 break;
655 case Opt_noac:
656 mnt->flags |= NFS_MOUNT_NOAC;
657 break;
658 case Opt_lock:
659 mnt->flags &= ~NFS_MOUNT_NONLM;
660 break;
661 case Opt_nolock:
662 mnt->flags |= NFS_MOUNT_NONLM;
663 break;
664 case Opt_v2:
665 mnt->flags &= ~NFS_MOUNT_VER3;
666 break;
667 case Opt_v3:
668 mnt->flags |= NFS_MOUNT_VER3;
669 break;
670 case Opt_udp:
671 mnt->flags &= ~NFS_MOUNT_TCP;
672 mnt->nfs_server.protocol = IPPROTO_UDP;
673 mnt->timeo = 7;
674 mnt->retrans = 5;
675 break;
676 case Opt_tcp:
677 mnt->flags |= NFS_MOUNT_TCP;
678 mnt->nfs_server.protocol = IPPROTO_TCP;
679 mnt->timeo = 600;
680 mnt->retrans = 2;
681 break;
682 case Opt_acl:
683 mnt->flags &= ~NFS_MOUNT_NOACL;
684 break;
685 case Opt_noacl:
686 mnt->flags |= NFS_MOUNT_NOACL;
687 break;
688 case Opt_rdirplus:
689 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
690 break;
691 case Opt_nordirplus:
692 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
693 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400694 case Opt_sharecache:
695 mnt->flags &= ~NFS_MOUNT_UNSHARED;
696 break;
697 case Opt_nosharecache:
698 mnt->flags |= NFS_MOUNT_UNSHARED;
699 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400700
701 case Opt_port:
702 if (match_int(args, &option))
703 return 0;
704 if (option < 0 || option > 65535)
705 return 0;
Al Viro410896442007-07-22 10:59:06 +0100706 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400707 break;
708 case Opt_rsize:
709 if (match_int(args, &mnt->rsize))
710 return 0;
711 break;
712 case Opt_wsize:
713 if (match_int(args, &mnt->wsize))
714 return 0;
715 break;
716 case Opt_bsize:
717 if (match_int(args, &option))
718 return 0;
719 if (option < 0)
720 return 0;
721 mnt->bsize = option;
722 break;
723 case Opt_timeo:
724 if (match_int(args, &mnt->timeo))
725 return 0;
726 break;
727 case Opt_retrans:
728 if (match_int(args, &mnt->retrans))
729 return 0;
730 break;
731 case Opt_acregmin:
732 if (match_int(args, &mnt->acregmin))
733 return 0;
734 break;
735 case Opt_acregmax:
736 if (match_int(args, &mnt->acregmax))
737 return 0;
738 break;
739 case Opt_acdirmin:
740 if (match_int(args, &mnt->acdirmin))
741 return 0;
742 break;
743 case Opt_acdirmax:
744 if (match_int(args, &mnt->acdirmax))
745 return 0;
746 break;
747 case Opt_actimeo:
748 if (match_int(args, &option))
749 return 0;
750 if (option < 0)
751 return 0;
752 mnt->acregmin =
753 mnt->acregmax =
754 mnt->acdirmin =
755 mnt->acdirmax = option;
756 break;
757 case Opt_namelen:
758 if (match_int(args, &mnt->namlen))
759 return 0;
760 break;
761 case Opt_mountport:
762 if (match_int(args, &option))
763 return 0;
764 if (option < 0 || option > 65535)
765 return 0;
766 mnt->mount_server.port = option;
767 break;
768 case Opt_mountprog:
769 if (match_int(args, &option))
770 return 0;
771 if (option < 0)
772 return 0;
773 mnt->mount_server.program = option;
774 break;
775 case Opt_mountvers:
776 if (match_int(args, &option))
777 return 0;
778 if (option < 0)
779 return 0;
780 mnt->mount_server.version = option;
781 break;
782 case Opt_nfsprog:
783 if (match_int(args, &option))
784 return 0;
785 if (option < 0)
786 return 0;
787 mnt->nfs_server.program = option;
788 break;
789 case Opt_nfsvers:
790 if (match_int(args, &option))
791 return 0;
792 switch (option) {
793 case 2:
794 mnt->flags &= ~NFS_MOUNT_VER3;
795 break;
796 case 3:
797 mnt->flags |= NFS_MOUNT_VER3;
798 break;
799 default:
800 goto out_unrec_vers;
801 }
802 break;
803
804 case Opt_sec:
805 string = match_strdup(args);
806 if (string == NULL)
807 goto out_nomem;
808 token = match_token(string, nfs_secflavor_tokens, args);
809 kfree(string);
810
811 /*
812 * The flags setting is for v2/v3. The flavor_len
813 * setting is for v4. v2/v3 also need to know the
814 * difference between NULL and UNIX.
815 */
816 switch (token) {
817 case Opt_sec_none:
818 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
819 mnt->auth_flavor_len = 0;
820 mnt->auth_flavors[0] = RPC_AUTH_NULL;
821 break;
822 case Opt_sec_sys:
823 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
824 mnt->auth_flavor_len = 0;
825 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
826 break;
827 case Opt_sec_krb5:
828 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
829 mnt->auth_flavor_len = 1;
830 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
831 break;
832 case Opt_sec_krb5i:
833 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
834 mnt->auth_flavor_len = 1;
835 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
836 break;
837 case Opt_sec_krb5p:
838 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
839 mnt->auth_flavor_len = 1;
840 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
841 break;
842 case Opt_sec_lkey:
843 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
844 mnt->auth_flavor_len = 1;
845 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
846 break;
847 case Opt_sec_lkeyi:
848 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
849 mnt->auth_flavor_len = 1;
850 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
851 break;
852 case Opt_sec_lkeyp:
853 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
854 mnt->auth_flavor_len = 1;
855 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
856 break;
857 case Opt_sec_spkm:
858 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
859 mnt->auth_flavor_len = 1;
860 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
861 break;
862 case Opt_sec_spkmi:
863 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
864 mnt->auth_flavor_len = 1;
865 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
866 break;
867 case Opt_sec_spkmp:
868 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
869 mnt->auth_flavor_len = 1;
870 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
871 break;
872 default:
873 goto out_unrec_sec;
874 }
875 break;
876 case Opt_proto:
877 string = match_strdup(args);
878 if (string == NULL)
879 goto out_nomem;
880 token = match_token(string,
881 nfs_xprt_protocol_tokens, args);
882 kfree(string);
883
884 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400885 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400886 mnt->flags &= ~NFS_MOUNT_TCP;
887 mnt->nfs_server.protocol = IPPROTO_UDP;
888 mnt->timeo = 7;
889 mnt->retrans = 5;
890 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400891 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400892 mnt->flags |= NFS_MOUNT_TCP;
893 mnt->nfs_server.protocol = IPPROTO_TCP;
894 mnt->timeo = 600;
895 mnt->retrans = 2;
896 break;
897 default:
898 goto out_unrec_xprt;
899 }
900 break;
901 case Opt_mountproto:
902 string = match_strdup(args);
903 if (string == NULL)
904 goto out_nomem;
905 token = match_token(string,
906 nfs_xprt_protocol_tokens, args);
907 kfree(string);
908
909 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400910 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400911 mnt->mount_server.protocol = IPPROTO_UDP;
912 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400913 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400914 mnt->mount_server.protocol = IPPROTO_TCP;
915 break;
916 default:
917 goto out_unrec_xprt;
918 }
919 break;
920 case Opt_addr:
921 string = match_strdup(args);
922 if (string == NULL)
923 goto out_nomem;
924 mnt->nfs_server.address.sin_family = AF_INET;
925 mnt->nfs_server.address.sin_addr.s_addr =
926 in_aton(string);
927 kfree(string);
928 break;
929 case Opt_clientaddr:
930 string = match_strdup(args);
931 if (string == NULL)
932 goto out_nomem;
933 mnt->client_address = string;
934 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400935 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400936 string = match_strdup(args);
937 if (string == NULL)
938 goto out_nomem;
939 mnt->mount_server.address.sin_family = AF_INET;
940 mnt->mount_server.address.sin_addr.s_addr =
941 in_aton(string);
942 kfree(string);
943 break;
944
945 case Opt_userspace:
946 case Opt_deprecated:
947 break;
948
949 default:
950 goto out_unknown;
951 }
952 }
953
954 return 1;
955
956out_nomem:
957 printk(KERN_INFO "NFS: not enough memory to parse option\n");
958 return 0;
959
960out_unrec_vers:
961 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
962 return 0;
963
964out_unrec_xprt:
965 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
966 return 0;
967
968out_unrec_sec:
969 printk(KERN_INFO "NFS: unrecognized security flavor\n");
970 return 0;
971
972out_unknown:
973 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
974 return 0;
975}
976
977/*
Chuck Lever0076d7b2007-07-01 12:13:49 -0400978 * Use the remote server's MOUNT service to request the NFS file handle
979 * corresponding to the provided path.
980 */
981static int nfs_try_mount(struct nfs_parsed_mount_data *args,
982 struct nfs_fh *root_fh)
983{
984 struct sockaddr_in sin;
985 int status;
986
987 if (args->mount_server.version == 0) {
988 if (args->flags & NFS_MOUNT_VER3)
989 args->mount_server.version = NFS_MNT3_VERSION;
990 else
991 args->mount_server.version = NFS_MNT_VERSION;
992 }
993
994 /*
995 * Construct the mount server's address.
996 */
997 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
998 sin = args->mount_server.address;
999 else
1000 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001001 /*
1002 * autobind will be used if mount_server.port == 0
1003 */
1004 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001005
1006 /*
1007 * Now ask the mount server to map our export path
1008 * to a file handle.
1009 */
1010 status = nfs_mount((struct sockaddr *) &sin,
1011 sizeof(sin),
1012 args->nfs_server.hostname,
1013 args->nfs_server.export_path,
1014 args->mount_server.version,
1015 args->mount_server.protocol,
1016 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001017 if (status == 0)
1018 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001019
Chuck Leverefd83402007-09-11 18:00:58 -04001020 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1021 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001022 return status;
1023}
1024
1025/*
David Howells54ceac42006-08-22 20:06:13 -04001026 * Validate the NFS2/NFS3 mount data
1027 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001028 *
1029 * For option strings, user space handles the following behaviors:
1030 *
1031 * + DNS: mapping server host name to IP address ("addr=" option)
1032 *
1033 * + failure mode: how to behave if a mount request can't be handled
1034 * immediately ("fg/bg" option)
1035 *
1036 * + retry: how often to retry a mount request ("retry=" option)
1037 *
1038 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1039 * mountproto=tcp after mountproto=udp, and so on
1040 *
1041 * XXX: as far as I can tell, changing the NFS program number is not
1042 * supported in the NFS client.
David Howellsf7b422b2006-06-09 09:34:33 -04001043 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001044static int nfs_validate_mount_data(void *options,
1045 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001046 struct nfs_fh *mntfh,
1047 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001048{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001049 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001050
Chuck Lever5df36e72007-07-01 12:12:56 -04001051 if (data == NULL)
1052 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001053
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001054 memset(args, 0, sizeof(*args));
1055 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1056 args->rsize = NFS_MAX_FILE_IO_SIZE;
1057 args->wsize = NFS_MAX_FILE_IO_SIZE;
1058 args->timeo = 600;
1059 args->retrans = 2;
1060 args->acregmin = 3;
1061 args->acregmax = 60;
1062 args->acdirmin = 30;
1063 args->acdirmax = 60;
1064 args->mount_server.protocol = IPPROTO_UDP;
1065 args->mount_server.program = NFS_MNT_PROGRAM;
1066 args->nfs_server.protocol = IPPROTO_TCP;
1067 args->nfs_server.program = NFS_PROGRAM;
1068
David Howellsf7b422b2006-06-09 09:34:33 -04001069 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001070 case 1:
1071 data->namlen = 0;
1072 case 2:
1073 data->bsize = 0;
1074 case 3:
1075 if (data->flags & NFS_MOUNT_VER3)
1076 goto out_no_v3;
1077 data->root.size = NFS2_FHSIZE;
1078 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1079 case 4:
1080 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1081 goto out_no_sec;
1082 case 5:
1083 memset(data->context, 0, sizeof(data->context));
1084 case 6:
1085 if (data->flags & NFS_MOUNT_VER3)
1086 mntfh->size = data->root.size;
1087 else
1088 mntfh->size = NFS2_FHSIZE;
1089
1090 if (mntfh->size > sizeof(mntfh->data))
1091 goto out_invalid_fh;
1092
1093 memcpy(mntfh->data, data->root.data, mntfh->size);
1094 if (mntfh->size < sizeof(mntfh->data))
1095 memset(mntfh->data + mntfh->size, 0,
1096 sizeof(mntfh->data) - mntfh->size);
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001097 /*
1098 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1099 * can deal with.
1100 */
1101 args->flags = data->flags;
1102 args->rsize = data->rsize;
1103 args->wsize = data->wsize;
1104 args->flags = data->flags;
1105 args->timeo = data->timeo;
1106 args->retrans = data->retrans;
1107 args->acregmin = data->acregmin;
1108 args->acregmax = data->acregmax;
1109 args->acdirmin = data->acdirmin;
1110 args->acdirmax = data->acdirmax;
1111 args->nfs_server.address = data->addr;
1112 if (!(data->flags & NFS_MOUNT_TCP))
1113 args->nfs_server.protocol = IPPROTO_UDP;
1114 /* N.B. caller will free nfs_server.hostname in all cases */
1115 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1116 args->namlen = data->namlen;
1117 args->bsize = data->bsize;
1118 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001119 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001120 default: {
1121 unsigned int len;
1122 char *c;
1123 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001124
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001125 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001126 return -EINVAL;
1127
Chuck Lever136d5582007-07-01 12:13:54 -04001128 c = strchr(dev_name, ':');
1129 if (c == NULL)
1130 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001131 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001132 /* N.B. caller will free nfs_server.hostname in all cases */
1133 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001134
1135 c++;
1136 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001137 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001138 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001139
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001140 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001141 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001142 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001143
Chuck Lever136d5582007-07-01 12:13:54 -04001144 break;
1145 }
David Howellsf7b422b2006-06-09 09:34:33 -04001146 }
David Howells54ceac42006-08-22 20:06:13 -04001147
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001148 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1149 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001150
David Howellsf7b422b2006-06-09 09:34:33 -04001151#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001152 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001153 goto out_v3_not_compiled;
1154#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001155
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001156 if (!nfs_verify_server_address((struct sockaddr *)
1157 &args->nfs_server.address))
Chuck Lever5df36e72007-07-01 12:12:56 -04001158 goto out_no_address;
David Howells54ceac42006-08-22 20:06:13 -04001159
1160 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001161
1162out_no_data:
1163 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1164 return -EINVAL;
1165
1166out_no_v3:
1167 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1168 data->version);
1169 return -EINVAL;
1170
1171out_no_sec:
1172 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1173 return -EINVAL;
1174
Chuck Lever5df36e72007-07-01 12:12:56 -04001175#ifndef CONFIG_NFS_V3
1176out_v3_not_compiled:
1177 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1178 return -EPROTONOSUPPORT;
1179#endif /* !CONFIG_NFS_V3 */
1180
1181out_no_address:
1182 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1183 return -EINVAL;
1184
1185out_invalid_fh:
1186 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1187 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001188}
1189
1190/*
1191 * Initialise the common bits of the superblock
1192 */
1193static inline void nfs_initialise_sb(struct super_block *sb)
1194{
1195 struct nfs_server *server = NFS_SB(sb);
1196
1197 sb->s_magic = NFS_SUPER_MAGIC;
1198
1199 /* We probably want something more informative here */
1200 snprintf(sb->s_id, sizeof(sb->s_id),
1201 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1202
1203 if (sb->s_blocksize == 0)
1204 sb->s_blocksize = nfs_block_bits(server->wsize,
1205 &sb->s_blocksize_bits);
1206
1207 if (server->flags & NFS_MOUNT_NOAC)
1208 sb->s_flags |= MS_SYNCHRONOUS;
1209
1210 nfs_super_set_maxbytes(sb, server->maxfilesize);
1211}
1212
1213/*
1214 * Finish setting up an NFS2/3 superblock
1215 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001216static void nfs_fill_super(struct super_block *sb,
1217 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001218{
1219 struct nfs_server *server = NFS_SB(sb);
1220
1221 sb->s_blocksize_bits = 0;
1222 sb->s_blocksize = 0;
1223 if (data->bsize)
1224 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1225
1226 if (server->flags & NFS_MOUNT_VER3) {
1227 /* The VFS shouldn't apply the umask to mode bits. We will do
1228 * so ourselves when necessary.
1229 */
1230 sb->s_flags |= MS_POSIXACL;
1231 sb->s_time_gran = 1;
1232 }
1233
1234 sb->s_op = &nfs_sops;
1235 nfs_initialise_sb(sb);
1236}
1237
1238/*
1239 * Finish setting up a cloned NFS2/3 superblock
1240 */
1241static void nfs_clone_super(struct super_block *sb,
1242 const struct super_block *old_sb)
1243{
1244 struct nfs_server *server = NFS_SB(sb);
1245
1246 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1247 sb->s_blocksize = old_sb->s_blocksize;
1248 sb->s_maxbytes = old_sb->s_maxbytes;
1249
1250 if (server->flags & NFS_MOUNT_VER3) {
1251 /* The VFS shouldn't apply the umask to mode bits. We will do
1252 * so ourselves when necessary.
1253 */
1254 sb->s_flags |= MS_POSIXACL;
1255 sb->s_time_gran = 1;
1256 }
1257
1258 sb->s_op = old_sb->s_op;
1259 nfs_initialise_sb(sb);
1260}
1261
Trond Myklebust275a5d22007-05-16 16:53:28 -04001262#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1263
1264static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1265{
1266 const struct nfs_server *a = s->s_fs_info;
1267 const struct rpc_clnt *clnt_a = a->client;
1268 const struct rpc_clnt *clnt_b = b->client;
1269
1270 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1271 goto Ebusy;
1272 if (a->nfs_client != b->nfs_client)
1273 goto Ebusy;
1274 if (a->flags != b->flags)
1275 goto Ebusy;
1276 if (a->wsize != b->wsize)
1277 goto Ebusy;
1278 if (a->rsize != b->rsize)
1279 goto Ebusy;
1280 if (a->acregmin != b->acregmin)
1281 goto Ebusy;
1282 if (a->acregmax != b->acregmax)
1283 goto Ebusy;
1284 if (a->acdirmin != b->acdirmin)
1285 goto Ebusy;
1286 if (a->acdirmax != b->acdirmax)
1287 goto Ebusy;
1288 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1289 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001290 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001291Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001292 return 0;
1293}
1294
1295struct nfs_sb_mountdata {
1296 struct nfs_server *server;
1297 int mntflags;
1298};
1299
1300static int nfs_set_super(struct super_block *s, void *data)
1301{
1302 struct nfs_sb_mountdata *sb_mntdata = data;
1303 struct nfs_server *server = sb_mntdata->server;
1304 int ret;
1305
1306 s->s_flags = sb_mntdata->mntflags;
1307 s->s_fs_info = server;
1308 ret = set_anon_super(s, server);
1309 if (ret == 0)
1310 server->s_dev = s->s_dev;
1311 return ret;
1312}
1313
1314static int nfs_compare_super(struct super_block *sb, void *data)
1315{
1316 struct nfs_sb_mountdata *sb_mntdata = data;
1317 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1318 int mntflags = sb_mntdata->mntflags;
1319
1320 if (memcmp(&old->nfs_client->cl_addr,
1321 &server->nfs_client->cl_addr,
1322 sizeof(old->nfs_client->cl_addr)) != 0)
1323 return 0;
1324 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1325 if (old->flags & NFS_MOUNT_UNSHARED)
1326 return 0;
1327 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1328 return 0;
1329 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001330}
1331
David Howells54ceac42006-08-22 20:06:13 -04001332static int nfs_get_sb(struct file_system_type *fs_type,
1333 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1334{
1335 struct nfs_server *server = NULL;
1336 struct super_block *s;
1337 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001338 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001339 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001340 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001341 struct nfs_sb_mountdata sb_mntdata = {
1342 .mntflags = flags,
1343 };
David Howells54ceac42006-08-22 20:06:13 -04001344 int error;
1345
1346 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001347 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001348 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001349 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001350
1351 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001352 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001353 if (IS_ERR(server)) {
1354 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001355 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001356 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001357 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001358
Trond Myklebust75180df2007-05-16 16:53:28 -04001359 if (server->flags & NFS_MOUNT_UNSHARED)
1360 compare_super = NULL;
1361
David Howells54ceac42006-08-22 20:06:13 -04001362 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001363 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001364 if (IS_ERR(s)) {
1365 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001366 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001367 }
1368
David Howells54ceac42006-08-22 20:06:13 -04001369 if (s->s_fs_info != server) {
1370 nfs_free_server(server);
1371 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001372 }
David Howells54ceac42006-08-22 20:06:13 -04001373
1374 if (!s->s_root) {
1375 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001376 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001377 }
1378
1379 mntroot = nfs_get_root(s, &mntfh);
1380 if (IS_ERR(mntroot)) {
1381 error = PTR_ERR(mntroot);
1382 goto error_splat_super;
1383 }
1384
David Howellsf7b422b2006-06-09 09:34:33 -04001385 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001386 mnt->mnt_sb = s;
1387 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001388 error = 0;
1389
1390out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001391 kfree(data.nfs_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001392 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001393
David Howells54ceac42006-08-22 20:06:13 -04001394out_err_nosb:
1395 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001396 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001397
1398error_splat_super:
1399 up_write(&s->s_umount);
1400 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001401 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001402}
1403
David Howells54ceac42006-08-22 20:06:13 -04001404/*
1405 * Destroy an NFS2/3 superblock
1406 */
David Howellsf7b422b2006-06-09 09:34:33 -04001407static void nfs_kill_super(struct super_block *s)
1408{
1409 struct nfs_server *server = NFS_SB(s);
1410
1411 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001412 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001413}
1414
David Howells54ceac42006-08-22 20:06:13 -04001415/*
1416 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1417 */
1418static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1419 const char *dev_name, void *raw_data,
1420 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001421{
1422 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001423 struct super_block *s;
1424 struct nfs_server *server;
1425 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001426 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001427 struct nfs_sb_mountdata sb_mntdata = {
1428 .mntflags = flags,
1429 };
David Howells54ceac42006-08-22 20:06:13 -04001430 int error;
1431
1432 dprintk("--> nfs_xdev_get_sb()\n");
1433
1434 /* create a new volume representation */
1435 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1436 if (IS_ERR(server)) {
1437 error = PTR_ERR(server);
1438 goto out_err_noserver;
1439 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001440 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001441
Trond Myklebust75180df2007-05-16 16:53:28 -04001442 if (server->flags & NFS_MOUNT_UNSHARED)
1443 compare_super = NULL;
1444
David Howells54ceac42006-08-22 20:06:13 -04001445 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001446 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001447 if (IS_ERR(s)) {
1448 error = PTR_ERR(s);
1449 goto out_err_nosb;
1450 }
1451
1452 if (s->s_fs_info != server) {
1453 nfs_free_server(server);
1454 server = NULL;
1455 }
1456
1457 if (!s->s_root) {
1458 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001459 nfs_clone_super(s, data->sb);
1460 }
1461
1462 mntroot = nfs_get_root(s, data->fh);
1463 if (IS_ERR(mntroot)) {
1464 error = PTR_ERR(mntroot);
1465 goto error_splat_super;
1466 }
1467
1468 s->s_flags |= MS_ACTIVE;
1469 mnt->mnt_sb = s;
1470 mnt->mnt_root = mntroot;
1471
1472 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1473 return 0;
1474
1475out_err_nosb:
1476 nfs_free_server(server);
1477out_err_noserver:
1478 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1479 return error;
1480
1481error_splat_super:
1482 up_write(&s->s_umount);
1483 deactivate_super(s);
1484 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1485 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001486}
1487
1488#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001489
1490/*
1491 * Finish setting up a cloned NFS4 superblock
1492 */
1493static void nfs4_clone_super(struct super_block *sb,
1494 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001495{
David Howells54ceac42006-08-22 20:06:13 -04001496 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1497 sb->s_blocksize = old_sb->s_blocksize;
1498 sb->s_maxbytes = old_sb->s_maxbytes;
1499 sb->s_time_gran = 1;
1500 sb->s_op = old_sb->s_op;
1501 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001502}
1503
1504/*
1505 * Set up an NFS4 superblock
1506 */
David Howells54ceac42006-08-22 20:06:13 -04001507static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001508{
David Howellsf7b422b2006-06-09 09:34:33 -04001509 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001510 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001511 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001512}
1513
David Howells54ceac42006-08-22 20:06:13 -04001514/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001515 * Validate NFSv4 mount options
1516 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001517static int nfs4_validate_mount_data(void *options,
1518 struct nfs_parsed_mount_data *args,
1519 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001520{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001521 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001522 char *c;
1523
1524 if (data == NULL)
1525 goto out_no_data;
1526
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001527 memset(args, 0, sizeof(*args));
1528 args->rsize = NFS_MAX_FILE_IO_SIZE;
1529 args->wsize = NFS_MAX_FILE_IO_SIZE;
1530 args->timeo = 600;
1531 args->retrans = 2;
1532 args->acregmin = 3;
1533 args->acregmax = 60;
1534 args->acdirmin = 30;
1535 args->acdirmax = 60;
1536 args->nfs_server.protocol = IPPROTO_TCP;
1537
Chuck Leverf0768eb2007-07-01 12:13:01 -04001538 switch (data->version) {
1539 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001540 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001541 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001542 if (copy_from_user(&args->nfs_server.address,
1543 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001544 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001545 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001546 if (args->nfs_server.address.sin_port == 0)
1547 args->nfs_server.address.sin_port = htons(NFS_PORT);
1548 if (!nfs_verify_server_address((struct sockaddr *)
1549 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001550 goto out_no_address;
1551
1552 switch (data->auth_flavourlen) {
1553 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001554 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001555 break;
1556 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001557 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001558 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001559 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001560 return -EFAULT;
1561 break;
1562 default:
1563 goto out_inval_auth;
1564 }
1565
1566 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1567 if (IS_ERR(c))
1568 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001569 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001570
1571 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1572 if (IS_ERR(c))
1573 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001574 args->nfs_server.export_path = c;
1575 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001576
1577 c = strndup_user(data->client_addr.data, 16);
1578 if (IS_ERR(c))
1579 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001580 args->client_address = c;
1581
1582 /*
1583 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1584 * can deal with.
1585 */
1586
1587 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1588 args->rsize = data->rsize;
1589 args->wsize = data->wsize;
1590 args->timeo = data->timeo;
1591 args->retrans = data->retrans;
1592 args->acregmin = data->acregmin;
1593 args->acregmax = data->acregmax;
1594 args->acdirmin = data->acdirmin;
1595 args->acdirmax = data->acdirmax;
1596 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001597
1598 break;
Chuck Lever80071222007-07-01 12:13:59 -04001599 default: {
1600 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001601
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001602 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001603 return -EINVAL;
1604
1605 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001606 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001607 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001608
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001609 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001610 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001611 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001612 break;
1613 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001614 break;
1615 default:
1616 goto out_inval_auth;
1617 }
1618
1619 /*
Chuck Lever80071222007-07-01 12:13:59 -04001620 * Split "dev_name" into "hostname:mntpath".
1621 */
1622 c = strchr(dev_name, ':');
1623 if (c == NULL)
1624 return -EINVAL;
1625 /* while calculating len, pretend ':' is '\0' */
1626 len = c - dev_name;
1627 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001628 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001629 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1630 if (args->nfs_server.hostname == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001631 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001632 strncpy(args->nfs_server.hostname, dev_name, len - 1);
Chuck Lever80071222007-07-01 12:13:59 -04001633
1634 c++; /* step over the ':' */
1635 len = strlen(c);
1636 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001637 return -ENAMETOOLONG;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001638 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1639 if (args->nfs_server.export_path == NULL)
Chuck Lever80071222007-07-01 12:13:59 -04001640 return -ENOMEM;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001641 strncpy(args->nfs_server.export_path, c, len);
Chuck Lever80071222007-07-01 12:13:59 -04001642
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001643 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001644
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001645 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001646 goto out_no_client_address;
1647
Chuck Lever80071222007-07-01 12:13:59 -04001648 break;
1649 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001650 }
1651
1652 return 0;
1653
1654out_no_data:
1655 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1656 return -EINVAL;
1657
1658out_inval_auth:
1659 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1660 data->auth_flavourlen);
1661 return -EINVAL;
1662
1663out_no_address:
1664 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1665 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001666
1667out_no_client_address:
1668 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1669 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001670}
1671
1672/*
David Howells54ceac42006-08-22 20:06:13 -04001673 * Get the superblock for an NFS4 mountpoint
1674 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001675static int nfs4_get_sb(struct file_system_type *fs_type,
1676 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001677{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001678 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001679 struct super_block *s;
1680 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001681 struct nfs_fh mntfh;
1682 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001683 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001684 struct nfs_sb_mountdata sb_mntdata = {
1685 .mntflags = flags,
1686 };
David Howells54ceac42006-08-22 20:06:13 -04001687 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001688
Chuck Leverf0768eb2007-07-01 12:13:01 -04001689 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001690 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001691 if (error < 0)
1692 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001693
David Howells54ceac42006-08-22 20:06:13 -04001694 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001695 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001696 if (IS_ERR(server)) {
1697 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001698 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001699 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001700 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001701
Trond Myklebust75180df2007-05-16 16:53:28 -04001702 if (server->flags & NFS4_MOUNT_UNSHARED)
1703 compare_super = NULL;
1704
David Howells54ceac42006-08-22 20:06:13 -04001705 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001706 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001707 if (IS_ERR(s)) {
1708 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001709 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001710 }
1711
Trond Myklebust5dd31772006-08-24 01:03:05 -04001712 if (s->s_fs_info != server) {
1713 nfs_free_server(server);
1714 server = NULL;
1715 }
1716
David Howells54ceac42006-08-22 20:06:13 -04001717 if (!s->s_root) {
1718 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001719 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001720 }
David Howellsf7b422b2006-06-09 09:34:33 -04001721
David Howells54ceac42006-08-22 20:06:13 -04001722 mntroot = nfs4_get_root(s, &mntfh);
1723 if (IS_ERR(mntroot)) {
1724 error = PTR_ERR(mntroot);
1725 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001726 }
David Howells54ceac42006-08-22 20:06:13 -04001727
David Howellsf7b422b2006-06-09 09:34:33 -04001728 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001729 mnt->mnt_sb = s;
1730 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001731 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001732
Chuck Lever29eb9812007-07-01 12:12:30 -04001733out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001734 kfree(data.client_address);
1735 kfree(data.nfs_server.export_path);
1736 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001737 return error;
David Howells54ceac42006-08-22 20:06:13 -04001738
Chuck Lever29eb9812007-07-01 12:12:30 -04001739out_free:
1740 nfs_free_server(server);
1741 goto out;
1742
David Howells54ceac42006-08-22 20:06:13 -04001743error_splat_super:
1744 up_write(&s->s_umount);
1745 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001746 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001747}
1748
1749static void nfs4_kill_super(struct super_block *sb)
1750{
1751 struct nfs_server *server = NFS_SB(sb);
1752
1753 nfs_return_all_delegations(sb);
1754 kill_anon_super(sb);
1755
1756 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001757 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001758}
1759
1760/*
David Howells54ceac42006-08-22 20:06:13 -04001761 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001762 */
David Howells54ceac42006-08-22 20:06:13 -04001763static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1764 const char *dev_name, void *raw_data,
1765 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001766{
1767 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001768 struct super_block *s;
1769 struct nfs_server *server;
1770 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001771 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001772 struct nfs_sb_mountdata sb_mntdata = {
1773 .mntflags = flags,
1774 };
David Howells54ceac42006-08-22 20:06:13 -04001775 int error;
1776
1777 dprintk("--> nfs4_xdev_get_sb()\n");
1778
1779 /* create a new volume representation */
1780 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1781 if (IS_ERR(server)) {
1782 error = PTR_ERR(server);
1783 goto out_err_noserver;
1784 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001785 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001786
Trond Myklebust75180df2007-05-16 16:53:28 -04001787 if (server->flags & NFS4_MOUNT_UNSHARED)
1788 compare_super = NULL;
1789
David Howells54ceac42006-08-22 20:06:13 -04001790 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001791 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001792 if (IS_ERR(s)) {
1793 error = PTR_ERR(s);
1794 goto out_err_nosb;
1795 }
1796
1797 if (s->s_fs_info != server) {
1798 nfs_free_server(server);
1799 server = NULL;
1800 }
1801
1802 if (!s->s_root) {
1803 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001804 nfs4_clone_super(s, data->sb);
1805 }
1806
1807 mntroot = nfs4_get_root(s, data->fh);
1808 if (IS_ERR(mntroot)) {
1809 error = PTR_ERR(mntroot);
1810 goto error_splat_super;
1811 }
1812
1813 s->s_flags |= MS_ACTIVE;
1814 mnt->mnt_sb = s;
1815 mnt->mnt_root = mntroot;
1816
1817 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1818 return 0;
1819
1820out_err_nosb:
1821 nfs_free_server(server);
1822out_err_noserver:
1823 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1824 return error;
1825
1826error_splat_super:
1827 up_write(&s->s_umount);
1828 deactivate_super(s);
1829 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1830 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001831}
1832
David Howells54ceac42006-08-22 20:06:13 -04001833/*
1834 * Create an NFS4 server record on referral traversal
1835 */
1836static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1837 const char *dev_name, void *raw_data,
1838 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001839{
1840 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001841 struct super_block *s;
1842 struct nfs_server *server;
1843 struct dentry *mntroot;
1844 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001845 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001846 struct nfs_sb_mountdata sb_mntdata = {
1847 .mntflags = flags,
1848 };
David Howells54ceac42006-08-22 20:06:13 -04001849 int error;
1850
1851 dprintk("--> nfs4_referral_get_sb()\n");
1852
1853 /* create a new volume representation */
1854 server = nfs4_create_referral_server(data, &mntfh);
1855 if (IS_ERR(server)) {
1856 error = PTR_ERR(server);
1857 goto out_err_noserver;
1858 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001859 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001860
Trond Myklebust75180df2007-05-16 16:53:28 -04001861 if (server->flags & NFS4_MOUNT_UNSHARED)
1862 compare_super = NULL;
1863
David Howells54ceac42006-08-22 20:06:13 -04001864 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001865 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001866 if (IS_ERR(s)) {
1867 error = PTR_ERR(s);
1868 goto out_err_nosb;
1869 }
1870
1871 if (s->s_fs_info != server) {
1872 nfs_free_server(server);
1873 server = NULL;
1874 }
1875
1876 if (!s->s_root) {
1877 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001878 nfs4_fill_super(s);
1879 }
1880
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001881 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001882 if (IS_ERR(mntroot)) {
1883 error = PTR_ERR(mntroot);
1884 goto error_splat_super;
1885 }
1886
1887 s->s_flags |= MS_ACTIVE;
1888 mnt->mnt_sb = s;
1889 mnt->mnt_root = mntroot;
1890
1891 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1892 return 0;
1893
1894out_err_nosb:
1895 nfs_free_server(server);
1896out_err_noserver:
1897 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1898 return error;
1899
1900error_splat_super:
1901 up_write(&s->s_umount);
1902 deactivate_super(s);
1903 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1904 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001905}
1906
David Howells54ceac42006-08-22 20:06:13 -04001907#endif /* CONFIG_NFS_V4 */