blob: 2fd28c4df1d4d2740223650bddde49a23e4e8e96 [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 */
Chuck Lever136d5582007-07-01 12:13:54 -04001044static int nfs_validate_mount_data(struct nfs_mount_data **options,
1045 struct nfs_fh *mntfh,
1046 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001047{
Chuck Lever136d5582007-07-01 12:13:54 -04001048 struct nfs_mount_data *data = *options;
1049
Chuck Lever5df36e72007-07-01 12:12:56 -04001050 if (data == NULL)
1051 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001052
David Howellsf7b422b2006-06-09 09:34:33 -04001053 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001054 case 1:
1055 data->namlen = 0;
1056 case 2:
1057 data->bsize = 0;
1058 case 3:
1059 if (data->flags & NFS_MOUNT_VER3)
1060 goto out_no_v3;
1061 data->root.size = NFS2_FHSIZE;
1062 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1063 case 4:
1064 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1065 goto out_no_sec;
1066 case 5:
1067 memset(data->context, 0, sizeof(data->context));
1068 case 6:
1069 if (data->flags & NFS_MOUNT_VER3)
1070 mntfh->size = data->root.size;
1071 else
1072 mntfh->size = NFS2_FHSIZE;
1073
1074 if (mntfh->size > sizeof(mntfh->data))
1075 goto out_invalid_fh;
1076
1077 memcpy(mntfh->data, data->root.data, mntfh->size);
1078 if (mntfh->size < sizeof(mntfh->data))
1079 memset(mntfh->data + mntfh->size, 0,
1080 sizeof(mntfh->data) - mntfh->size);
1081 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001082 default: {
1083 unsigned int len;
1084 char *c;
1085 int status;
1086 struct nfs_parsed_mount_data args = {
1087 .flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP),
1088 .rsize = NFS_MAX_FILE_IO_SIZE,
1089 .wsize = NFS_MAX_FILE_IO_SIZE,
1090 .timeo = 600,
1091 .retrans = 2,
1092 .acregmin = 3,
1093 .acregmax = 60,
1094 .acdirmin = 30,
1095 .acdirmax = 60,
1096 .mount_server.protocol = IPPROTO_UDP,
1097 .mount_server.program = NFS_MNT_PROGRAM,
1098 .nfs_server.protocol = IPPROTO_TCP,
1099 .nfs_server.program = NFS_PROGRAM,
1100 };
1101
1102 if (nfs_parse_mount_options((char *) *options, &args) == 0)
1103 return -EINVAL;
1104
1105 data = kzalloc(sizeof(*data), GFP_KERNEL);
1106 if (data == NULL)
1107 return -ENOMEM;
1108
1109 /*
1110 * NB: after this point, caller will free "data"
1111 * if we return an error
1112 */
1113 *options = data;
1114
1115 c = strchr(dev_name, ':');
1116 if (c == NULL)
1117 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001118 len = c - dev_name;
Chuck Lever136d5582007-07-01 12:13:54 -04001119 if (len > sizeof(data->hostname))
Chuck Lever7d1cca722007-08-29 17:59:03 -04001120 return -ENAMETOOLONG;
Chuck Lever136d5582007-07-01 12:13:54 -04001121 strncpy(data->hostname, dev_name, len);
1122 args.nfs_server.hostname = data->hostname;
1123
1124 c++;
1125 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001126 return -ENAMETOOLONG;
Chuck Lever136d5582007-07-01 12:13:54 -04001127 args.nfs_server.export_path = c;
1128
1129 status = nfs_try_mount(&args, mntfh);
1130 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001131 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001132
1133 /*
1134 * Translate to nfs_mount_data, which nfs_fill_super
1135 * can deal with.
1136 */
1137 data->version = 6;
1138 data->flags = args.flags;
1139 data->rsize = args.rsize;
1140 data->wsize = args.wsize;
1141 data->timeo = args.timeo;
1142 data->retrans = args.retrans;
1143 data->acregmin = args.acregmin;
1144 data->acregmax = args.acregmax;
1145 data->acdirmin = args.acdirmin;
1146 data->acdirmax = args.acdirmax;
1147 data->addr = args.nfs_server.address;
1148 data->namlen = args.namlen;
1149 data->bsize = args.bsize;
1150 data->pseudoflavor = args.auth_flavors[0];
1151
1152 break;
1153 }
David Howellsf7b422b2006-06-09 09:34:33 -04001154 }
David Howells54ceac42006-08-22 20:06:13 -04001155
Trond Myklebust36b15c52006-08-22 20:06:14 -04001156 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
1157 data->pseudoflavor = RPC_AUTH_UNIX;
1158
David Howellsf7b422b2006-06-09 09:34:33 -04001159#ifndef CONFIG_NFS_V3
David Howells54ceac42006-08-22 20:06:13 -04001160 if (data->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001161 goto out_v3_not_compiled;
1162#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001163
Chuck Lever5df36e72007-07-01 12:12:56 -04001164 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1165 goto out_no_address;
David Howells54ceac42006-08-22 20:06:13 -04001166
1167 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001168
1169out_no_data:
1170 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1171 return -EINVAL;
1172
1173out_no_v3:
1174 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1175 data->version);
1176 return -EINVAL;
1177
1178out_no_sec:
1179 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1180 return -EINVAL;
1181
Chuck Lever5df36e72007-07-01 12:12:56 -04001182#ifndef CONFIG_NFS_V3
1183out_v3_not_compiled:
1184 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1185 return -EPROTONOSUPPORT;
1186#endif /* !CONFIG_NFS_V3 */
1187
1188out_no_address:
1189 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1190 return -EINVAL;
1191
1192out_invalid_fh:
1193 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1194 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001195}
1196
1197/*
1198 * Initialise the common bits of the superblock
1199 */
1200static inline void nfs_initialise_sb(struct super_block *sb)
1201{
1202 struct nfs_server *server = NFS_SB(sb);
1203
1204 sb->s_magic = NFS_SUPER_MAGIC;
1205
1206 /* We probably want something more informative here */
1207 snprintf(sb->s_id, sizeof(sb->s_id),
1208 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1209
1210 if (sb->s_blocksize == 0)
1211 sb->s_blocksize = nfs_block_bits(server->wsize,
1212 &sb->s_blocksize_bits);
1213
1214 if (server->flags & NFS_MOUNT_NOAC)
1215 sb->s_flags |= MS_SYNCHRONOUS;
1216
1217 nfs_super_set_maxbytes(sb, server->maxfilesize);
1218}
1219
1220/*
1221 * Finish setting up an NFS2/3 superblock
1222 */
1223static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
1224{
1225 struct nfs_server *server = NFS_SB(sb);
1226
1227 sb->s_blocksize_bits = 0;
1228 sb->s_blocksize = 0;
1229 if (data->bsize)
1230 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1231
1232 if (server->flags & NFS_MOUNT_VER3) {
1233 /* The VFS shouldn't apply the umask to mode bits. We will do
1234 * so ourselves when necessary.
1235 */
1236 sb->s_flags |= MS_POSIXACL;
1237 sb->s_time_gran = 1;
1238 }
1239
1240 sb->s_op = &nfs_sops;
1241 nfs_initialise_sb(sb);
1242}
1243
1244/*
1245 * Finish setting up a cloned NFS2/3 superblock
1246 */
1247static void nfs_clone_super(struct super_block *sb,
1248 const struct super_block *old_sb)
1249{
1250 struct nfs_server *server = NFS_SB(sb);
1251
1252 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1253 sb->s_blocksize = old_sb->s_blocksize;
1254 sb->s_maxbytes = old_sb->s_maxbytes;
1255
1256 if (server->flags & NFS_MOUNT_VER3) {
1257 /* The VFS shouldn't apply the umask to mode bits. We will do
1258 * so ourselves when necessary.
1259 */
1260 sb->s_flags |= MS_POSIXACL;
1261 sb->s_time_gran = 1;
1262 }
1263
1264 sb->s_op = old_sb->s_op;
1265 nfs_initialise_sb(sb);
1266}
1267
Trond Myklebust275a5d22007-05-16 16:53:28 -04001268#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1269
1270static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1271{
1272 const struct nfs_server *a = s->s_fs_info;
1273 const struct rpc_clnt *clnt_a = a->client;
1274 const struct rpc_clnt *clnt_b = b->client;
1275
1276 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1277 goto Ebusy;
1278 if (a->nfs_client != b->nfs_client)
1279 goto Ebusy;
1280 if (a->flags != b->flags)
1281 goto Ebusy;
1282 if (a->wsize != b->wsize)
1283 goto Ebusy;
1284 if (a->rsize != b->rsize)
1285 goto Ebusy;
1286 if (a->acregmin != b->acregmin)
1287 goto Ebusy;
1288 if (a->acregmax != b->acregmax)
1289 goto Ebusy;
1290 if (a->acdirmin != b->acdirmin)
1291 goto Ebusy;
1292 if (a->acdirmax != b->acdirmax)
1293 goto Ebusy;
1294 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1295 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001296 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001297Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001298 return 0;
1299}
1300
1301struct nfs_sb_mountdata {
1302 struct nfs_server *server;
1303 int mntflags;
1304};
1305
1306static int nfs_set_super(struct super_block *s, void *data)
1307{
1308 struct nfs_sb_mountdata *sb_mntdata = data;
1309 struct nfs_server *server = sb_mntdata->server;
1310 int ret;
1311
1312 s->s_flags = sb_mntdata->mntflags;
1313 s->s_fs_info = server;
1314 ret = set_anon_super(s, server);
1315 if (ret == 0)
1316 server->s_dev = s->s_dev;
1317 return ret;
1318}
1319
1320static int nfs_compare_super(struct super_block *sb, void *data)
1321{
1322 struct nfs_sb_mountdata *sb_mntdata = data;
1323 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1324 int mntflags = sb_mntdata->mntflags;
1325
1326 if (memcmp(&old->nfs_client->cl_addr,
1327 &server->nfs_client->cl_addr,
1328 sizeof(old->nfs_client->cl_addr)) != 0)
1329 return 0;
1330 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1331 if (old->flags & NFS_MOUNT_UNSHARED)
1332 return 0;
1333 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1334 return 0;
1335 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001336}
1337
David Howells54ceac42006-08-22 20:06:13 -04001338static int nfs_get_sb(struct file_system_type *fs_type,
1339 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1340{
1341 struct nfs_server *server = NULL;
1342 struct super_block *s;
1343 struct nfs_fh mntfh;
1344 struct nfs_mount_data *data = raw_data;
1345 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001346 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001347 struct nfs_sb_mountdata sb_mntdata = {
1348 .mntflags = flags,
1349 };
David Howells54ceac42006-08-22 20:06:13 -04001350 int error;
1351
1352 /* Validate the mount data */
Chuck Lever136d5582007-07-01 12:13:54 -04001353 error = nfs_validate_mount_data(&data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001354 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001355 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001356
1357 /* Get a volume representation */
1358 server = nfs_create_server(data, &mntfh);
1359 if (IS_ERR(server)) {
1360 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001361 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001362 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001363 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001364
Trond Myklebust75180df2007-05-16 16:53:28 -04001365 if (server->flags & NFS_MOUNT_UNSHARED)
1366 compare_super = NULL;
1367
David Howells54ceac42006-08-22 20:06:13 -04001368 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001369 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001370 if (IS_ERR(s)) {
1371 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001372 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001373 }
1374
David Howells54ceac42006-08-22 20:06:13 -04001375 if (s->s_fs_info != server) {
1376 nfs_free_server(server);
1377 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001378 }
David Howells54ceac42006-08-22 20:06:13 -04001379
1380 if (!s->s_root) {
1381 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001382 nfs_fill_super(s, data);
1383 }
1384
1385 mntroot = nfs_get_root(s, &mntfh);
1386 if (IS_ERR(mntroot)) {
1387 error = PTR_ERR(mntroot);
1388 goto error_splat_super;
1389 }
1390
David Howellsf7b422b2006-06-09 09:34:33 -04001391 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001392 mnt->mnt_sb = s;
1393 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001394 error = 0;
1395
1396out:
Chuck Lever136d5582007-07-01 12:13:54 -04001397 if (data != raw_data)
1398 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04001399 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001400
David Howells54ceac42006-08-22 20:06:13 -04001401out_err_nosb:
1402 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001403 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001404
1405error_splat_super:
1406 up_write(&s->s_umount);
1407 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001408 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001409}
1410
David Howells54ceac42006-08-22 20:06:13 -04001411/*
1412 * Destroy an NFS2/3 superblock
1413 */
David Howellsf7b422b2006-06-09 09:34:33 -04001414static void nfs_kill_super(struct super_block *s)
1415{
1416 struct nfs_server *server = NFS_SB(s);
1417
1418 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001419 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001420}
1421
David Howells54ceac42006-08-22 20:06:13 -04001422/*
1423 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1424 */
1425static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1426 const char *dev_name, void *raw_data,
1427 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001428{
1429 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001430 struct super_block *s;
1431 struct nfs_server *server;
1432 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001433 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001434 struct nfs_sb_mountdata sb_mntdata = {
1435 .mntflags = flags,
1436 };
David Howells54ceac42006-08-22 20:06:13 -04001437 int error;
1438
1439 dprintk("--> nfs_xdev_get_sb()\n");
1440
1441 /* create a new volume representation */
1442 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1443 if (IS_ERR(server)) {
1444 error = PTR_ERR(server);
1445 goto out_err_noserver;
1446 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001447 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001448
Trond Myklebust75180df2007-05-16 16:53:28 -04001449 if (server->flags & NFS_MOUNT_UNSHARED)
1450 compare_super = NULL;
1451
David Howells54ceac42006-08-22 20:06:13 -04001452 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001453 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001454 if (IS_ERR(s)) {
1455 error = PTR_ERR(s);
1456 goto out_err_nosb;
1457 }
1458
1459 if (s->s_fs_info != server) {
1460 nfs_free_server(server);
1461 server = NULL;
1462 }
1463
1464 if (!s->s_root) {
1465 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001466 nfs_clone_super(s, data->sb);
1467 }
1468
1469 mntroot = nfs_get_root(s, data->fh);
1470 if (IS_ERR(mntroot)) {
1471 error = PTR_ERR(mntroot);
1472 goto error_splat_super;
1473 }
1474
1475 s->s_flags |= MS_ACTIVE;
1476 mnt->mnt_sb = s;
1477 mnt->mnt_root = mntroot;
1478
1479 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1480 return 0;
1481
1482out_err_nosb:
1483 nfs_free_server(server);
1484out_err_noserver:
1485 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1486 return error;
1487
1488error_splat_super:
1489 up_write(&s->s_umount);
1490 deactivate_super(s);
1491 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1492 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001493}
1494
1495#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001496
1497/*
1498 * Finish setting up a cloned NFS4 superblock
1499 */
1500static void nfs4_clone_super(struct super_block *sb,
1501 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001502{
David Howells54ceac42006-08-22 20:06:13 -04001503 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1504 sb->s_blocksize = old_sb->s_blocksize;
1505 sb->s_maxbytes = old_sb->s_maxbytes;
1506 sb->s_time_gran = 1;
1507 sb->s_op = old_sb->s_op;
1508 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001509}
1510
1511/*
1512 * Set up an NFS4 superblock
1513 */
David Howells54ceac42006-08-22 20:06:13 -04001514static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001515{
David Howellsf7b422b2006-06-09 09:34:33 -04001516 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001517 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001518 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001519}
1520
David Howells54ceac42006-08-22 20:06:13 -04001521/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001522 * Validate NFSv4 mount options
1523 */
1524static int nfs4_validate_mount_data(struct nfs4_mount_data **options,
1525 const char *dev_name,
1526 struct sockaddr_in *addr,
1527 rpc_authflavor_t *authflavour,
1528 char **hostname,
1529 char **mntpath,
1530 char **ip_addr)
1531{
1532 struct nfs4_mount_data *data = *options;
1533 char *c;
1534
1535 if (data == NULL)
1536 goto out_no_data;
1537
1538 switch (data->version) {
1539 case 1:
1540 if (data->host_addrlen != sizeof(*addr))
1541 goto out_no_address;
1542 if (copy_from_user(addr, data->host_addr, sizeof(*addr)))
1543 return -EFAULT;
1544 if (addr->sin_port == 0)
1545 addr->sin_port = htons(NFS_PORT);
1546 if (!nfs_verify_server_address((struct sockaddr *) addr))
1547 goto out_no_address;
1548
1549 switch (data->auth_flavourlen) {
1550 case 0:
1551 *authflavour = RPC_AUTH_UNIX;
1552 break;
1553 case 1:
1554 if (copy_from_user(authflavour, data->auth_flavours,
1555 sizeof(*authflavour)))
1556 return -EFAULT;
1557 break;
1558 default:
1559 goto out_inval_auth;
1560 }
1561
1562 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1563 if (IS_ERR(c))
1564 return PTR_ERR(c);
1565 *hostname = c;
1566
1567 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1568 if (IS_ERR(c))
1569 return PTR_ERR(c);
1570 *mntpath = c;
1571 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *mntpath);
1572
1573 c = strndup_user(data->client_addr.data, 16);
1574 if (IS_ERR(c))
1575 return PTR_ERR(c);
1576 *ip_addr = c;
1577
1578 break;
Chuck Lever80071222007-07-01 12:13:59 -04001579 default: {
1580 unsigned int len;
1581 struct nfs_parsed_mount_data args = {
1582 .rsize = NFS_MAX_FILE_IO_SIZE,
1583 .wsize = NFS_MAX_FILE_IO_SIZE,
1584 .timeo = 600,
1585 .retrans = 2,
1586 .acregmin = 3,
1587 .acregmax = 60,
1588 .acdirmin = 30,
1589 .acdirmax = 60,
1590 .nfs_server.protocol = IPPROTO_TCP,
1591 };
1592
1593 if (nfs_parse_mount_options((char *) *options, &args) == 0)
1594 return -EINVAL;
1595
1596 if (!nfs_verify_server_address((struct sockaddr *)
1597 &args.nfs_server.address))
1598 return -EINVAL;
1599 *addr = args.nfs_server.address;
1600
1601 switch (args.auth_flavor_len) {
1602 case 0:
1603 *authflavour = RPC_AUTH_UNIX;
1604 break;
1605 case 1:
1606 *authflavour = (rpc_authflavor_t) args.auth_flavors[0];
1607 break;
1608 default:
1609 goto out_inval_auth;
1610 }
1611
1612 /*
1613 * Translate to nfs4_mount_data, which nfs4_fill_super
1614 * can deal with.
1615 */
1616 data = kzalloc(sizeof(*data), GFP_KERNEL);
1617 if (data == NULL)
1618 return -ENOMEM;
1619 *options = data;
1620
1621 data->version = 1;
1622 data->flags = args.flags & NFS4_MOUNT_FLAGMASK;
1623 data->rsize = args.rsize;
1624 data->wsize = args.wsize;
1625 data->timeo = args.timeo;
1626 data->retrans = args.retrans;
1627 data->acregmin = args.acregmin;
1628 data->acregmax = args.acregmax;
1629 data->acdirmin = args.acdirmin;
1630 data->acdirmax = args.acdirmax;
1631 data->proto = args.nfs_server.protocol;
1632
1633 /*
1634 * Split "dev_name" into "hostname:mntpath".
1635 */
1636 c = strchr(dev_name, ':');
1637 if (c == NULL)
1638 return -EINVAL;
1639 /* while calculating len, pretend ':' is '\0' */
1640 len = c - dev_name;
1641 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001642 return -ENAMETOOLONG;
Chuck Lever80071222007-07-01 12:13:59 -04001643 *hostname = kzalloc(len, GFP_KERNEL);
1644 if (*hostname == NULL)
1645 return -ENOMEM;
1646 strncpy(*hostname, dev_name, len - 1);
1647
1648 c++; /* step over the ':' */
1649 len = strlen(c);
1650 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001651 return -ENAMETOOLONG;
Chuck Lever80071222007-07-01 12:13:59 -04001652 *mntpath = kzalloc(len + 1, GFP_KERNEL);
1653 if (*mntpath == NULL)
1654 return -ENOMEM;
1655 strncpy(*mntpath, c, len);
1656
1657 dprintk("MNTPATH: %s\n", *mntpath);
1658
Jeff Layton0a87cf12007-07-18 11:28:43 -04001659 if (args.client_address == NULL)
1660 goto out_no_client_address;
1661
Chuck Lever80071222007-07-01 12:13:59 -04001662 *ip_addr = args.client_address;
1663
1664 break;
1665 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001666 }
1667
1668 return 0;
1669
1670out_no_data:
1671 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1672 return -EINVAL;
1673
1674out_inval_auth:
1675 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1676 data->auth_flavourlen);
1677 return -EINVAL;
1678
1679out_no_address:
1680 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1681 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001682
1683out_no_client_address:
1684 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1685 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001686}
1687
1688/*
David Howells54ceac42006-08-22 20:06:13 -04001689 * Get the superblock for an NFS4 mountpoint
1690 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001691static int nfs4_get_sb(struct file_system_type *fs_type,
1692 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001693{
David Howellsf7b422b2006-06-09 09:34:33 -04001694 struct nfs4_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001695 struct super_block *s;
1696 struct nfs_server *server;
1697 struct sockaddr_in addr;
1698 rpc_authflavor_t authflavour;
1699 struct nfs_fh mntfh;
1700 struct dentry *mntroot;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001701 char *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
Trond Myklebust75180df2007-05-16 16:53:28 -04001702 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001703 struct nfs_sb_mountdata sb_mntdata = {
1704 .mntflags = flags,
1705 };
David Howells54ceac42006-08-22 20:06:13 -04001706 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001707
Chuck Leverf0768eb2007-07-01 12:13:01 -04001708 /* Validate the mount data */
1709 error = nfs4_validate_mount_data(&data, dev_name, &addr, &authflavour,
1710 &hostname, &mntpath, &ip_addr);
1711 if (error < 0)
1712 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001713
David Howells54ceac42006-08-22 20:06:13 -04001714 /* Get a volume representation */
1715 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
1716 authflavour, &mntfh);
1717 if (IS_ERR(server)) {
1718 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001719 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001720 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001721 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001722
Trond Myklebust75180df2007-05-16 16:53:28 -04001723 if (server->flags & NFS4_MOUNT_UNSHARED)
1724 compare_super = NULL;
1725
David Howells54ceac42006-08-22 20:06:13 -04001726 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001727 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001728 if (IS_ERR(s)) {
1729 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001730 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001731 }
1732
Trond Myklebust5dd31772006-08-24 01:03:05 -04001733 if (s->s_fs_info != server) {
1734 nfs_free_server(server);
1735 server = NULL;
1736 }
1737
David Howells54ceac42006-08-22 20:06:13 -04001738 if (!s->s_root) {
1739 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001740 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001741 }
David Howellsf7b422b2006-06-09 09:34:33 -04001742
David Howells54ceac42006-08-22 20:06:13 -04001743 mntroot = nfs4_get_root(s, &mntfh);
1744 if (IS_ERR(mntroot)) {
1745 error = PTR_ERR(mntroot);
1746 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001747 }
David Howells54ceac42006-08-22 20:06:13 -04001748
David Howellsf7b422b2006-06-09 09:34:33 -04001749 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001750 mnt->mnt_sb = s;
1751 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001752 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001753
Chuck Lever29eb9812007-07-01 12:12:30 -04001754out:
1755 kfree(ip_addr);
David Howells54ceac42006-08-22 20:06:13 -04001756 kfree(mntpath);
1757 kfree(hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001758 return error;
David Howells54ceac42006-08-22 20:06:13 -04001759
Chuck Lever29eb9812007-07-01 12:12:30 -04001760out_free:
1761 nfs_free_server(server);
1762 goto out;
1763
David Howells54ceac42006-08-22 20:06:13 -04001764error_splat_super:
1765 up_write(&s->s_umount);
1766 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001767 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001768}
1769
1770static void nfs4_kill_super(struct super_block *sb)
1771{
1772 struct nfs_server *server = NFS_SB(sb);
1773
1774 nfs_return_all_delegations(sb);
1775 kill_anon_super(sb);
1776
1777 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001778 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001779}
1780
1781/*
David Howells54ceac42006-08-22 20:06:13 -04001782 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001783 */
David Howells54ceac42006-08-22 20:06:13 -04001784static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1785 const char *dev_name, void *raw_data,
1786 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001787{
1788 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001789 struct super_block *s;
1790 struct nfs_server *server;
1791 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001792 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001793 struct nfs_sb_mountdata sb_mntdata = {
1794 .mntflags = flags,
1795 };
David Howells54ceac42006-08-22 20:06:13 -04001796 int error;
1797
1798 dprintk("--> nfs4_xdev_get_sb()\n");
1799
1800 /* create a new volume representation */
1801 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1802 if (IS_ERR(server)) {
1803 error = PTR_ERR(server);
1804 goto out_err_noserver;
1805 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001806 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001807
Trond Myklebust75180df2007-05-16 16:53:28 -04001808 if (server->flags & NFS4_MOUNT_UNSHARED)
1809 compare_super = NULL;
1810
David Howells54ceac42006-08-22 20:06:13 -04001811 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001812 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001813 if (IS_ERR(s)) {
1814 error = PTR_ERR(s);
1815 goto out_err_nosb;
1816 }
1817
1818 if (s->s_fs_info != server) {
1819 nfs_free_server(server);
1820 server = NULL;
1821 }
1822
1823 if (!s->s_root) {
1824 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001825 nfs4_clone_super(s, data->sb);
1826 }
1827
1828 mntroot = nfs4_get_root(s, data->fh);
1829 if (IS_ERR(mntroot)) {
1830 error = PTR_ERR(mntroot);
1831 goto error_splat_super;
1832 }
1833
1834 s->s_flags |= MS_ACTIVE;
1835 mnt->mnt_sb = s;
1836 mnt->mnt_root = mntroot;
1837
1838 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1839 return 0;
1840
1841out_err_nosb:
1842 nfs_free_server(server);
1843out_err_noserver:
1844 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1845 return error;
1846
1847error_splat_super:
1848 up_write(&s->s_umount);
1849 deactivate_super(s);
1850 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1851 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001852}
1853
David Howells54ceac42006-08-22 20:06:13 -04001854/*
1855 * Create an NFS4 server record on referral traversal
1856 */
1857static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1858 const char *dev_name, void *raw_data,
1859 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001860{
1861 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001862 struct super_block *s;
1863 struct nfs_server *server;
1864 struct dentry *mntroot;
1865 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001866 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001867 struct nfs_sb_mountdata sb_mntdata = {
1868 .mntflags = flags,
1869 };
David Howells54ceac42006-08-22 20:06:13 -04001870 int error;
1871
1872 dprintk("--> nfs4_referral_get_sb()\n");
1873
1874 /* create a new volume representation */
1875 server = nfs4_create_referral_server(data, &mntfh);
1876 if (IS_ERR(server)) {
1877 error = PTR_ERR(server);
1878 goto out_err_noserver;
1879 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001880 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001881
Trond Myklebust75180df2007-05-16 16:53:28 -04001882 if (server->flags & NFS4_MOUNT_UNSHARED)
1883 compare_super = NULL;
1884
David Howells54ceac42006-08-22 20:06:13 -04001885 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001886 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001887 if (IS_ERR(s)) {
1888 error = PTR_ERR(s);
1889 goto out_err_nosb;
1890 }
1891
1892 if (s->s_fs_info != server) {
1893 nfs_free_server(server);
1894 server = NULL;
1895 }
1896
1897 if (!s->s_root) {
1898 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001899 nfs4_fill_super(s);
1900 }
1901
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001902 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001903 if (IS_ERR(mntroot)) {
1904 error = PTR_ERR(mntroot);
1905 goto error_splat_super;
1906 }
1907
1908 s->s_flags |= MS_ACTIVE;
1909 mnt->mnt_sb = s;
1910 mnt->mnt_root = mntroot;
1911
1912 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1913 return 0;
1914
1915out_err_nosb:
1916 nfs_free_server(server);
1917out_err_noserver:
1918 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1919 return error;
1920
1921error_splat_super:
1922 up_write(&s->s_umount);
1923 deactivate_super(s);
1924 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1925 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001926}
1927
David Howells54ceac42006-08-22 20:06:13 -04001928#endif /* CONFIG_NFS_V4 */