blob: 094d2f832c3cc3fbe0a574b511b863ed34d8068f [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 -040061
62struct nfs_parsed_mount_data {
63 int flags;
64 int rsize, wsize;
65 int timeo, retrans;
66 int acregmin, acregmax,
67 acdirmin, acdirmax;
68 int namlen;
69 unsigned int bsize;
70 unsigned int auth_flavor_len;
71 rpc_authflavor_t auth_flavors[1];
72 char *client_address;
73
74 struct {
75 struct sockaddr_in address;
76 unsigned int program;
77 unsigned int version;
78 unsigned short port;
79 int protocol;
80 } mount_server;
81
82 struct {
83 struct sockaddr_in address;
84 char *hostname;
85 char *export_path;
86 unsigned int program;
87 int protocol;
88 } nfs_server;
89};
90
91enum {
92 /* Mount options that take no arguments */
93 Opt_soft, Opt_hard,
94 Opt_intr, Opt_nointr,
95 Opt_posix, Opt_noposix,
96 Opt_cto, Opt_nocto,
97 Opt_ac, Opt_noac,
98 Opt_lock, Opt_nolock,
99 Opt_v2, Opt_v3,
100 Opt_udp, Opt_tcp,
101 Opt_acl, Opt_noacl,
102 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -0400103 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400104
105 /* Mount options that take integer arguments */
106 Opt_port,
107 Opt_rsize, Opt_wsize, Opt_bsize,
108 Opt_timeo, Opt_retrans,
109 Opt_acregmin, Opt_acregmax,
110 Opt_acdirmin, Opt_acdirmax,
111 Opt_actimeo,
112 Opt_namelen,
113 Opt_mountport,
114 Opt_mountprog, Opt_mountvers,
115 Opt_nfsprog, Opt_nfsvers,
116
117 /* Mount options that take string arguments */
118 Opt_sec, Opt_proto, Opt_mountproto,
119 Opt_addr, Opt_mounthost, Opt_clientaddr,
120
121 /* Mount options that are ignored */
122 Opt_userspace, Opt_deprecated,
123
124 Opt_err
125};
126
127static match_table_t nfs_mount_option_tokens = {
128 { Opt_userspace, "bg" },
129 { Opt_userspace, "fg" },
130 { Opt_soft, "soft" },
131 { Opt_hard, "hard" },
132 { Opt_intr, "intr" },
133 { Opt_nointr, "nointr" },
134 { Opt_posix, "posix" },
135 { Opt_noposix, "noposix" },
136 { Opt_cto, "cto" },
137 { Opt_nocto, "nocto" },
138 { Opt_ac, "ac" },
139 { Opt_noac, "noac" },
140 { Opt_lock, "lock" },
141 { Opt_nolock, "nolock" },
142 { Opt_v2, "v2" },
143 { Opt_v3, "v3" },
144 { Opt_udp, "udp" },
145 { Opt_tcp, "tcp" },
146 { Opt_acl, "acl" },
147 { Opt_noacl, "noacl" },
148 { Opt_rdirplus, "rdirplus" },
149 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400150 { Opt_sharecache, "sharecache" },
151 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400152
153 { Opt_port, "port=%u" },
154 { Opt_rsize, "rsize=%u" },
155 { Opt_wsize, "wsize=%u" },
156 { Opt_bsize, "bsize=%u" },
157 { Opt_timeo, "timeo=%u" },
158 { Opt_retrans, "retrans=%u" },
159 { Opt_acregmin, "acregmin=%u" },
160 { Opt_acregmax, "acregmax=%u" },
161 { Opt_acdirmin, "acdirmin=%u" },
162 { Opt_acdirmax, "acdirmax=%u" },
163 { Opt_actimeo, "actimeo=%u" },
164 { Opt_userspace, "retry=%u" },
165 { Opt_namelen, "namlen=%u" },
166 { Opt_mountport, "mountport=%u" },
167 { Opt_mountprog, "mountprog=%u" },
168 { Opt_mountvers, "mountvers=%u" },
169 { Opt_nfsprog, "nfsprog=%u" },
170 { Opt_nfsvers, "nfsvers=%u" },
171 { Opt_nfsvers, "vers=%u" },
172
173 { Opt_sec, "sec=%s" },
174 { Opt_proto, "proto=%s" },
175 { Opt_mountproto, "mountproto=%s" },
176 { Opt_addr, "addr=%s" },
177 { Opt_clientaddr, "clientaddr=%s" },
178 { Opt_mounthost, "mounthost=%s" },
179
180 { Opt_err, NULL }
181};
182
183enum {
184 Opt_xprt_udp, Opt_xprt_tcp,
185
186 Opt_xprt_err
187};
188
189static match_table_t nfs_xprt_protocol_tokens = {
190 { Opt_xprt_udp, "udp" },
191 { Opt_xprt_tcp, "tcp" },
192
193 { Opt_xprt_err, NULL }
194};
195
196enum {
197 Opt_sec_none, Opt_sec_sys,
198 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
199 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
200 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
201
202 Opt_sec_err
203};
204
205static match_table_t nfs_secflavor_tokens = {
206 { Opt_sec_none, "none" },
207 { Opt_sec_none, "null" },
208 { Opt_sec_sys, "sys" },
209
210 { Opt_sec_krb5, "krb5" },
211 { Opt_sec_krb5i, "krb5i" },
212 { Opt_sec_krb5p, "krb5p" },
213
214 { Opt_sec_lkey, "lkey" },
215 { Opt_sec_lkeyi, "lkeyi" },
216 { Opt_sec_lkeyp, "lkeyp" },
217
218 { Opt_sec_err, NULL }
219};
220
221
David Howellsf7b422b2006-06-09 09:34:33 -0400222static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400223static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400224static int nfs_show_options(struct seq_file *, struct vfsmount *);
225static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400226static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400227static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400228 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400229static void nfs_kill_super(struct super_block *);
230
231static struct file_system_type nfs_fs_type = {
232 .owner = THIS_MODULE,
233 .name = "nfs",
234 .get_sb = nfs_get_sb,
235 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700236 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400237};
238
David Howells54ceac42006-08-22 20:06:13 -0400239struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400240 .owner = THIS_MODULE,
241 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400242 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400243 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700244 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400245};
246
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800247static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400248 .alloc_inode = nfs_alloc_inode,
249 .destroy_inode = nfs_destroy_inode,
250 .write_inode = nfs_write_inode,
251 .statfs = nfs_statfs,
252 .clear_inode = nfs_clear_inode,
253 .umount_begin = nfs_umount_begin,
254 .show_options = nfs_show_options,
255 .show_stats = nfs_show_stats,
256};
257
258#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400259static int nfs4_get_sb(struct file_system_type *fs_type,
260 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400261static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
262 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
263static int nfs4_referral_get_sb(struct file_system_type *fs_type,
264 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400265static void nfs4_kill_super(struct super_block *sb);
266
267static struct file_system_type nfs4_fs_type = {
268 .owner = THIS_MODULE,
269 .name = "nfs4",
270 .get_sb = nfs4_get_sb,
271 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700272 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400273};
274
David Howells54ceac42006-08-22 20:06:13 -0400275struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400276 .owner = THIS_MODULE,
277 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400278 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400279 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700280 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400281};
282
David Howells54ceac42006-08-22 20:06:13 -0400283struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400284 .owner = THIS_MODULE,
285 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400286 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400287 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700288 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400289};
290
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800291static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400292 .alloc_inode = nfs_alloc_inode,
293 .destroy_inode = nfs_destroy_inode,
294 .write_inode = nfs_write_inode,
295 .statfs = nfs_statfs,
296 .clear_inode = nfs4_clear_inode,
297 .umount_begin = nfs_umount_begin,
298 .show_options = nfs_show_options,
299 .show_stats = nfs_show_stats,
300};
301#endif
302
Rusty Russell8e1f9362007-07-17 04:03:17 -0700303static struct shrinker acl_shrinker = {
304 .shrink = nfs_access_cache_shrinker,
305 .seeks = DEFAULT_SEEKS,
306};
Trond Myklebust979df722006-07-25 11:28:19 -0400307
David Howellsf7b422b2006-06-09 09:34:33 -0400308/*
309 * Register the NFS filesystems
310 */
311int __init register_nfs_fs(void)
312{
313 int ret;
314
315 ret = register_filesystem(&nfs_fs_type);
316 if (ret < 0)
317 goto error_0;
318
David Howellsf7b422b2006-06-09 09:34:33 -0400319 ret = nfs_register_sysctl();
320 if (ret < 0)
321 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800322#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400323 ret = register_filesystem(&nfs4_fs_type);
324 if (ret < 0)
325 goto error_2;
326#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700327 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400328 return 0;
329
330#ifdef CONFIG_NFS_V4
331error_2:
332 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800333#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400334error_1:
335 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400336error_0:
337 return ret;
338}
339
340/*
341 * Unregister the NFS filesystems
342 */
343void __exit unregister_nfs_fs(void)
344{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700345 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400346#ifdef CONFIG_NFS_V4
347 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400348#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700349 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400350 unregister_filesystem(&nfs_fs_type);
351}
352
353/*
354 * Deliver file system statistics to userspace
355 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400356static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400357{
David Howells0c7d90c2006-08-22 20:06:10 -0400358 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400359 unsigned char blockbits;
360 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400361 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400362 struct nfs_fattr fattr;
363 struct nfs_fsstat res = {
364 .fattr = &fattr,
365 };
366 int error;
367
368 lock_kernel();
369
David Howells8fa5c002006-08-22 20:06:12 -0400370 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400371 if (error < 0)
372 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700373 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400374
375 /*
376 * Current versions of glibc do not correctly handle the
377 * case where f_frsize != f_bsize. Eventually we want to
378 * report the value of wtmult in this field.
379 */
David Howells0c7d90c2006-08-22 20:06:10 -0400380 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400381
382 /*
383 * On most *nix systems, f_blocks, f_bfree, and f_bavail
384 * are reported in units of f_frsize. Linux hasn't had
385 * an f_frsize field in its statfs struct until recently,
386 * thus historically Linux's sys_statfs reports these
387 * fields in units of f_bsize.
388 */
David Howells0c7d90c2006-08-22 20:06:10 -0400389 buf->f_bsize = dentry->d_sb->s_blocksize;
390 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400391 blockres = (1 << blockbits) - 1;
392 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
393 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
394 buf->f_bavail = (res.abytes + blockres) >> blockbits;
395
396 buf->f_files = res.tfiles;
397 buf->f_ffree = res.afiles;
398
399 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700400
David Howellsf7b422b2006-06-09 09:34:33 -0400401 unlock_kernel();
402 return 0;
403
404 out_err:
405 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700406 unlock_kernel();
407 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400408}
409
David Howells7d4e2742006-08-22 20:06:07 -0400410/*
411 * Map the security flavour number to a name
412 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400413static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
414{
David Howells7d4e2742006-08-22 20:06:07 -0400415 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400416 rpc_authflavor_t flavour;
417 const char *str;
418 } sec_flavours[] = {
419 { RPC_AUTH_NULL, "null" },
420 { RPC_AUTH_UNIX, "sys" },
421 { RPC_AUTH_GSS_KRB5, "krb5" },
422 { RPC_AUTH_GSS_KRB5I, "krb5i" },
423 { RPC_AUTH_GSS_KRB5P, "krb5p" },
424 { RPC_AUTH_GSS_LKEY, "lkey" },
425 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
426 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
427 { RPC_AUTH_GSS_SPKM, "spkm" },
428 { RPC_AUTH_GSS_SPKMI, "spkmi" },
429 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400430 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400431 };
432 int i;
433
Chuck Lever4d81cd12007-07-01 12:12:40 -0400434 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400435 if (sec_flavours[i].flavour == flavour)
436 break;
437 }
438 return sec_flavours[i].str;
439}
440
David Howellsf7b422b2006-06-09 09:34:33 -0400441/*
442 * Describe the mount options in force on this server representation
443 */
444static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
445{
David Howells509de812006-08-22 20:06:11 -0400446 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400447 int flag;
David Howells509de812006-08-22 20:06:11 -0400448 const char *str;
449 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400450 } nfs_info[] = {
451 { NFS_MOUNT_SOFT, ",soft", ",hard" },
452 { NFS_MOUNT_INTR, ",intr", "" },
453 { NFS_MOUNT_NOCTO, ",nocto", "" },
454 { NFS_MOUNT_NOAC, ",noac", "" },
455 { NFS_MOUNT_NONLM, ",nolock", "" },
456 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400457 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400458 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400459 { 0, NULL, NULL }
460 };
David Howells509de812006-08-22 20:06:11 -0400461 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400462 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400463 char buf[12];
David Howells509de812006-08-22 20:06:11 -0400464 const char *proto;
David Howellsf7b422b2006-06-09 09:34:33 -0400465
David Howells8fa5c002006-08-22 20:06:12 -0400466 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400467 seq_printf(m, ",rsize=%d", nfss->rsize);
468 seq_printf(m, ",wsize=%d", nfss->wsize);
469 if (nfss->acregmin != 3*HZ || showdefaults)
470 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
471 if (nfss->acregmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
473 if (nfss->acdirmin != 30*HZ || showdefaults)
474 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
475 if (nfss->acdirmax != 60*HZ || showdefaults)
476 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
477 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
478 if (nfss->flags & nfs_infop->flag)
479 seq_puts(m, nfs_infop->str);
480 else
481 seq_puts(m, nfs_infop->nostr);
482 }
483 switch (nfss->client->cl_xprt->prot) {
484 case IPPROTO_TCP:
485 proto = "tcp";
486 break;
487 case IPPROTO_UDP:
488 proto = "udp";
489 break;
490 default:
491 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
492 proto = buf;
493 }
494 seq_printf(m, ",proto=%s", proto);
David Howells5006a762006-08-22 20:06:12 -0400495 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
496 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400497 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400498}
499
500/*
501 * Describe the mount options on this VFS mountpoint
502 */
503static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
504{
505 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
506
507 nfs_show_mount_options(m, nfss, 0);
508
Jeff Laytonddc01c02007-07-30 08:47:38 -0400509 seq_printf(m, ",addr="NIPQUAD_FMT,
510 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
David Howellsf7b422b2006-06-09 09:34:33 -0400511
512 return 0;
513}
514
515/*
516 * Present statistical information for this VFS mountpoint
517 */
518static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
519{
520 int i, cpu;
521 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
522 struct rpc_auth *auth = nfss->client->cl_auth;
523 struct nfs_iostats totals = { };
524
525 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
526
527 /*
528 * Display all mount option settings
529 */
530 seq_printf(m, "\n\topts:\t");
531 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
532 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
533 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
534 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
535 nfs_show_mount_options(m, nfss, 1);
536
537 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
538
539 seq_printf(m, "\n\tcaps:\t");
540 seq_printf(m, "caps=0x%x", nfss->caps);
541 seq_printf(m, ",wtmult=%d", nfss->wtmult);
542 seq_printf(m, ",dtsize=%d", nfss->dtsize);
543 seq_printf(m, ",bsize=%d", nfss->bsize);
544 seq_printf(m, ",namelen=%d", nfss->namelen);
545
546#ifdef CONFIG_NFS_V4
David Howells8fa5c002006-08-22 20:06:12 -0400547 if (nfss->nfs_client->cl_nfsversion == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400548 seq_printf(m, "\n\tnfsv4:\t");
549 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
550 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
551 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
552 }
553#endif
554
555 /*
556 * Display security flavor in effect for this mount
557 */
558 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
559 if (auth->au_flavor)
560 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
561
562 /*
563 * Display superblock I/O counters
564 */
565 for_each_possible_cpu(cpu) {
566 struct nfs_iostats *stats;
567
568 preempt_disable();
569 stats = per_cpu_ptr(nfss->io_stats, cpu);
570
571 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
572 totals.events[i] += stats->events[i];
573 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
574 totals.bytes[i] += stats->bytes[i];
575
576 preempt_enable();
577 }
578
579 seq_printf(m, "\n\tevents:\t");
580 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
581 seq_printf(m, "%lu ", totals.events[i]);
582 seq_printf(m, "\n\tbytes:\t");
583 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
584 seq_printf(m, "%Lu ", totals.bytes[i]);
585 seq_printf(m, "\n");
586
587 rpc_print_iostats(m, nfss->client);
588
589 return 0;
590}
591
592/*
593 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400594 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400595 */
596static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
597{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400598 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
599 struct rpc_clnt *rpc;
600
David Howellsf7b422b2006-06-09 09:34:33 -0400601 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400602
603 if (!(flags & MNT_FORCE))
604 return;
605 /* -EIO all pending I/O */
606 rpc = server->client_acl;
607 if (!IS_ERR(rpc))
608 rpc_killall_tasks(rpc);
609 rpc = server->client;
610 if (!IS_ERR(rpc))
611 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400612}
613
614/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400615 * Sanity-check a server address provided by the mount command
616 */
617static int nfs_verify_server_address(struct sockaddr *addr)
618{
619 switch (addr->sa_family) {
620 case AF_INET: {
621 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
622 if (sa->sin_addr.s_addr != INADDR_ANY)
623 return 1;
624 break;
625 }
626 }
627
628 return 0;
629}
630
631/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400632 * Error-check and convert a string of mount options from user space into
633 * a data structure
634 */
635static int nfs_parse_mount_options(char *raw,
636 struct nfs_parsed_mount_data *mnt)
637{
638 char *p, *string;
639
640 if (!raw) {
641 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
642 return 1;
643 }
644 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
645
646 while ((p = strsep(&raw, ",")) != NULL) {
647 substring_t args[MAX_OPT_ARGS];
648 int option, token;
649
650 if (!*p)
651 continue;
652
653 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
654
655 token = match_token(p, nfs_mount_option_tokens, args);
656 switch (token) {
657 case Opt_soft:
658 mnt->flags |= NFS_MOUNT_SOFT;
659 break;
660 case Opt_hard:
661 mnt->flags &= ~NFS_MOUNT_SOFT;
662 break;
663 case Opt_intr:
664 mnt->flags |= NFS_MOUNT_INTR;
665 break;
666 case Opt_nointr:
667 mnt->flags &= ~NFS_MOUNT_INTR;
668 break;
669 case Opt_posix:
670 mnt->flags |= NFS_MOUNT_POSIX;
671 break;
672 case Opt_noposix:
673 mnt->flags &= ~NFS_MOUNT_POSIX;
674 break;
675 case Opt_cto:
676 mnt->flags &= ~NFS_MOUNT_NOCTO;
677 break;
678 case Opt_nocto:
679 mnt->flags |= NFS_MOUNT_NOCTO;
680 break;
681 case Opt_ac:
682 mnt->flags &= ~NFS_MOUNT_NOAC;
683 break;
684 case Opt_noac:
685 mnt->flags |= NFS_MOUNT_NOAC;
686 break;
687 case Opt_lock:
688 mnt->flags &= ~NFS_MOUNT_NONLM;
689 break;
690 case Opt_nolock:
691 mnt->flags |= NFS_MOUNT_NONLM;
692 break;
693 case Opt_v2:
694 mnt->flags &= ~NFS_MOUNT_VER3;
695 break;
696 case Opt_v3:
697 mnt->flags |= NFS_MOUNT_VER3;
698 break;
699 case Opt_udp:
700 mnt->flags &= ~NFS_MOUNT_TCP;
701 mnt->nfs_server.protocol = IPPROTO_UDP;
702 mnt->timeo = 7;
703 mnt->retrans = 5;
704 break;
705 case Opt_tcp:
706 mnt->flags |= NFS_MOUNT_TCP;
707 mnt->nfs_server.protocol = IPPROTO_TCP;
708 mnt->timeo = 600;
709 mnt->retrans = 2;
710 break;
711 case Opt_acl:
712 mnt->flags &= ~NFS_MOUNT_NOACL;
713 break;
714 case Opt_noacl:
715 mnt->flags |= NFS_MOUNT_NOACL;
716 break;
717 case Opt_rdirplus:
718 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
719 break;
720 case Opt_nordirplus:
721 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
722 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400723 case Opt_sharecache:
724 mnt->flags &= ~NFS_MOUNT_UNSHARED;
725 break;
726 case Opt_nosharecache:
727 mnt->flags |= NFS_MOUNT_UNSHARED;
728 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400729
730 case Opt_port:
731 if (match_int(args, &option))
732 return 0;
733 if (option < 0 || option > 65535)
734 return 0;
Al Viro410896442007-07-22 10:59:06 +0100735 mnt->nfs_server.address.sin_port = htons(option);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400736 break;
737 case Opt_rsize:
738 if (match_int(args, &mnt->rsize))
739 return 0;
740 break;
741 case Opt_wsize:
742 if (match_int(args, &mnt->wsize))
743 return 0;
744 break;
745 case Opt_bsize:
746 if (match_int(args, &option))
747 return 0;
748 if (option < 0)
749 return 0;
750 mnt->bsize = option;
751 break;
752 case Opt_timeo:
753 if (match_int(args, &mnt->timeo))
754 return 0;
755 break;
756 case Opt_retrans:
757 if (match_int(args, &mnt->retrans))
758 return 0;
759 break;
760 case Opt_acregmin:
761 if (match_int(args, &mnt->acregmin))
762 return 0;
763 break;
764 case Opt_acregmax:
765 if (match_int(args, &mnt->acregmax))
766 return 0;
767 break;
768 case Opt_acdirmin:
769 if (match_int(args, &mnt->acdirmin))
770 return 0;
771 break;
772 case Opt_acdirmax:
773 if (match_int(args, &mnt->acdirmax))
774 return 0;
775 break;
776 case Opt_actimeo:
777 if (match_int(args, &option))
778 return 0;
779 if (option < 0)
780 return 0;
781 mnt->acregmin =
782 mnt->acregmax =
783 mnt->acdirmin =
784 mnt->acdirmax = option;
785 break;
786 case Opt_namelen:
787 if (match_int(args, &mnt->namlen))
788 return 0;
789 break;
790 case Opt_mountport:
791 if (match_int(args, &option))
792 return 0;
793 if (option < 0 || option > 65535)
794 return 0;
795 mnt->mount_server.port = option;
796 break;
797 case Opt_mountprog:
798 if (match_int(args, &option))
799 return 0;
800 if (option < 0)
801 return 0;
802 mnt->mount_server.program = option;
803 break;
804 case Opt_mountvers:
805 if (match_int(args, &option))
806 return 0;
807 if (option < 0)
808 return 0;
809 mnt->mount_server.version = option;
810 break;
811 case Opt_nfsprog:
812 if (match_int(args, &option))
813 return 0;
814 if (option < 0)
815 return 0;
816 mnt->nfs_server.program = option;
817 break;
818 case Opt_nfsvers:
819 if (match_int(args, &option))
820 return 0;
821 switch (option) {
822 case 2:
823 mnt->flags &= ~NFS_MOUNT_VER3;
824 break;
825 case 3:
826 mnt->flags |= NFS_MOUNT_VER3;
827 break;
828 default:
829 goto out_unrec_vers;
830 }
831 break;
832
833 case Opt_sec:
834 string = match_strdup(args);
835 if (string == NULL)
836 goto out_nomem;
837 token = match_token(string, nfs_secflavor_tokens, args);
838 kfree(string);
839
840 /*
841 * The flags setting is for v2/v3. The flavor_len
842 * setting is for v4. v2/v3 also need to know the
843 * difference between NULL and UNIX.
844 */
845 switch (token) {
846 case Opt_sec_none:
847 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 0;
849 mnt->auth_flavors[0] = RPC_AUTH_NULL;
850 break;
851 case Opt_sec_sys:
852 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 0;
854 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
855 break;
856 case Opt_sec_krb5:
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
860 break;
861 case Opt_sec_krb5i:
862 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
863 mnt->auth_flavor_len = 1;
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
865 break;
866 case Opt_sec_krb5p:
867 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
868 mnt->auth_flavor_len = 1;
869 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
870 break;
871 case Opt_sec_lkey:
872 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 1;
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
875 break;
876 case Opt_sec_lkeyi:
877 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
880 break;
881 case Opt_sec_lkeyp:
882 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 1;
884 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
885 break;
886 case Opt_sec_spkm:
887 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
888 mnt->auth_flavor_len = 1;
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
890 break;
891 case Opt_sec_spkmi:
892 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
893 mnt->auth_flavor_len = 1;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
895 break;
896 case Opt_sec_spkmp:
897 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
898 mnt->auth_flavor_len = 1;
899 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
900 break;
901 default:
902 goto out_unrec_sec;
903 }
904 break;
905 case Opt_proto:
906 string = match_strdup(args);
907 if (string == NULL)
908 goto out_nomem;
909 token = match_token(string,
910 nfs_xprt_protocol_tokens, args);
911 kfree(string);
912
913 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400914 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400915 mnt->flags &= ~NFS_MOUNT_TCP;
916 mnt->nfs_server.protocol = IPPROTO_UDP;
917 mnt->timeo = 7;
918 mnt->retrans = 5;
919 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400920 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400921 mnt->flags |= NFS_MOUNT_TCP;
922 mnt->nfs_server.protocol = IPPROTO_TCP;
923 mnt->timeo = 600;
924 mnt->retrans = 2;
925 break;
926 default:
927 goto out_unrec_xprt;
928 }
929 break;
930 case Opt_mountproto:
931 string = match_strdup(args);
932 if (string == NULL)
933 goto out_nomem;
934 token = match_token(string,
935 nfs_xprt_protocol_tokens, args);
936 kfree(string);
937
938 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400939 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400940 mnt->mount_server.protocol = IPPROTO_UDP;
941 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400942 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400943 mnt->mount_server.protocol = IPPROTO_TCP;
944 break;
945 default:
946 goto out_unrec_xprt;
947 }
948 break;
949 case Opt_addr:
950 string = match_strdup(args);
951 if (string == NULL)
952 goto out_nomem;
953 mnt->nfs_server.address.sin_family = AF_INET;
954 mnt->nfs_server.address.sin_addr.s_addr =
955 in_aton(string);
956 kfree(string);
957 break;
958 case Opt_clientaddr:
959 string = match_strdup(args);
960 if (string == NULL)
961 goto out_nomem;
962 mnt->client_address = string;
963 break;
964 case Opt_mounthost:
965 string = match_strdup(args);
966 if (string == NULL)
967 goto out_nomem;
968 mnt->mount_server.address.sin_family = AF_INET;
969 mnt->mount_server.address.sin_addr.s_addr =
970 in_aton(string);
971 kfree(string);
972 break;
973
974 case Opt_userspace:
975 case Opt_deprecated:
976 break;
977
978 default:
979 goto out_unknown;
980 }
981 }
982
983 return 1;
984
985out_nomem:
986 printk(KERN_INFO "NFS: not enough memory to parse option\n");
987 return 0;
988
989out_unrec_vers:
990 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
991 return 0;
992
993out_unrec_xprt:
994 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
995 return 0;
996
997out_unrec_sec:
998 printk(KERN_INFO "NFS: unrecognized security flavor\n");
999 return 0;
1000
1001out_unknown:
1002 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1003 return 0;
1004}
1005
1006/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001007 * Use the remote server's MOUNT service to request the NFS file handle
1008 * corresponding to the provided path.
1009 */
1010static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1011 struct nfs_fh *root_fh)
1012{
1013 struct sockaddr_in sin;
1014 int status;
1015
1016 if (args->mount_server.version == 0) {
1017 if (args->flags & NFS_MOUNT_VER3)
1018 args->mount_server.version = NFS_MNT3_VERSION;
1019 else
1020 args->mount_server.version = NFS_MNT_VERSION;
1021 }
1022
1023 /*
1024 * Construct the mount server's address.
1025 */
1026 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1027 sin = args->mount_server.address;
1028 else
1029 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001030 /*
1031 * autobind will be used if mount_server.port == 0
1032 */
1033 sin.sin_port = htons(args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001034
1035 /*
1036 * Now ask the mount server to map our export path
1037 * to a file handle.
1038 */
1039 status = nfs_mount((struct sockaddr *) &sin,
1040 sizeof(sin),
1041 args->nfs_server.hostname,
1042 args->nfs_server.export_path,
1043 args->mount_server.version,
1044 args->mount_server.protocol,
1045 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001046 if (status == 0)
1047 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001048
Chuck Leverefd83402007-09-11 18:00:58 -04001049 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1050 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001051 return status;
1052}
1053
1054/*
David Howells54ceac42006-08-22 20:06:13 -04001055 * Validate the NFS2/NFS3 mount data
1056 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001057 *
1058 * For option strings, user space handles the following behaviors:
1059 *
1060 * + DNS: mapping server host name to IP address ("addr=" option)
1061 *
1062 * + failure mode: how to behave if a mount request can't be handled
1063 * immediately ("fg/bg" option)
1064 *
1065 * + retry: how often to retry a mount request ("retry=" option)
1066 *
1067 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1068 * mountproto=tcp after mountproto=udp, and so on
1069 *
1070 * XXX: as far as I can tell, changing the NFS program number is not
1071 * supported in the NFS client.
David Howellsf7b422b2006-06-09 09:34:33 -04001072 */
Chuck Lever136d5582007-07-01 12:13:54 -04001073static int nfs_validate_mount_data(struct nfs_mount_data **options,
1074 struct nfs_fh *mntfh,
1075 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001076{
Chuck Lever136d5582007-07-01 12:13:54 -04001077 struct nfs_mount_data *data = *options;
1078
Chuck Lever5df36e72007-07-01 12:12:56 -04001079 if (data == NULL)
1080 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001081
David Howellsf7b422b2006-06-09 09:34:33 -04001082 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001083 case 1:
1084 data->namlen = 0;
1085 case 2:
1086 data->bsize = 0;
1087 case 3:
1088 if (data->flags & NFS_MOUNT_VER3)
1089 goto out_no_v3;
1090 data->root.size = NFS2_FHSIZE;
1091 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1092 case 4:
1093 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1094 goto out_no_sec;
1095 case 5:
1096 memset(data->context, 0, sizeof(data->context));
1097 case 6:
1098 if (data->flags & NFS_MOUNT_VER3)
1099 mntfh->size = data->root.size;
1100 else
1101 mntfh->size = NFS2_FHSIZE;
1102
1103 if (mntfh->size > sizeof(mntfh->data))
1104 goto out_invalid_fh;
1105
1106 memcpy(mntfh->data, data->root.data, mntfh->size);
1107 if (mntfh->size < sizeof(mntfh->data))
1108 memset(mntfh->data + mntfh->size, 0,
1109 sizeof(mntfh->data) - mntfh->size);
1110 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001111 default: {
1112 unsigned int len;
1113 char *c;
1114 int status;
1115 struct nfs_parsed_mount_data args = {
1116 .flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP),
1117 .rsize = NFS_MAX_FILE_IO_SIZE,
1118 .wsize = NFS_MAX_FILE_IO_SIZE,
1119 .timeo = 600,
1120 .retrans = 2,
1121 .acregmin = 3,
1122 .acregmax = 60,
1123 .acdirmin = 30,
1124 .acdirmax = 60,
1125 .mount_server.protocol = IPPROTO_UDP,
1126 .mount_server.program = NFS_MNT_PROGRAM,
1127 .nfs_server.protocol = IPPROTO_TCP,
1128 .nfs_server.program = NFS_PROGRAM,
1129 };
1130
1131 if (nfs_parse_mount_options((char *) *options, &args) == 0)
1132 return -EINVAL;
1133
1134 data = kzalloc(sizeof(*data), GFP_KERNEL);
1135 if (data == NULL)
1136 return -ENOMEM;
1137
1138 /*
1139 * NB: after this point, caller will free "data"
1140 * if we return an error
1141 */
1142 *options = data;
1143
1144 c = strchr(dev_name, ':');
1145 if (c == NULL)
1146 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001147 len = c - dev_name;
Chuck Lever136d5582007-07-01 12:13:54 -04001148 if (len > sizeof(data->hostname))
Chuck Lever7d1cca722007-08-29 17:59:03 -04001149 return -ENAMETOOLONG;
Chuck Lever136d5582007-07-01 12:13:54 -04001150 strncpy(data->hostname, dev_name, len);
1151 args.nfs_server.hostname = data->hostname;
1152
1153 c++;
1154 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001155 return -ENAMETOOLONG;
Chuck Lever136d5582007-07-01 12:13:54 -04001156 args.nfs_server.export_path = c;
1157
1158 status = nfs_try_mount(&args, mntfh);
1159 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001160 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001161
1162 /*
1163 * Translate to nfs_mount_data, which nfs_fill_super
1164 * can deal with.
1165 */
1166 data->version = 6;
1167 data->flags = args.flags;
1168 data->rsize = args.rsize;
1169 data->wsize = args.wsize;
1170 data->timeo = args.timeo;
1171 data->retrans = args.retrans;
1172 data->acregmin = args.acregmin;
1173 data->acregmax = args.acregmax;
1174 data->acdirmin = args.acdirmin;
1175 data->acdirmax = args.acdirmax;
1176 data->addr = args.nfs_server.address;
1177 data->namlen = args.namlen;
1178 data->bsize = args.bsize;
1179 data->pseudoflavor = args.auth_flavors[0];
1180
1181 break;
1182 }
David Howellsf7b422b2006-06-09 09:34:33 -04001183 }
David Howells54ceac42006-08-22 20:06:13 -04001184
Trond Myklebust36b15c52006-08-22 20:06:14 -04001185 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
1186 data->pseudoflavor = RPC_AUTH_UNIX;
1187
David Howellsf7b422b2006-06-09 09:34:33 -04001188#ifndef CONFIG_NFS_V3
David Howells54ceac42006-08-22 20:06:13 -04001189 if (data->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001190 goto out_v3_not_compiled;
1191#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001192
Chuck Lever5df36e72007-07-01 12:12:56 -04001193 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1194 goto out_no_address;
David Howells54ceac42006-08-22 20:06:13 -04001195
1196 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001197
1198out_no_data:
1199 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1200 return -EINVAL;
1201
1202out_no_v3:
1203 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1204 data->version);
1205 return -EINVAL;
1206
1207out_no_sec:
1208 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1209 return -EINVAL;
1210
Chuck Lever5df36e72007-07-01 12:12:56 -04001211#ifndef CONFIG_NFS_V3
1212out_v3_not_compiled:
1213 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1214 return -EPROTONOSUPPORT;
1215#endif /* !CONFIG_NFS_V3 */
1216
1217out_no_address:
1218 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1219 return -EINVAL;
1220
1221out_invalid_fh:
1222 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1223 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001224}
1225
1226/*
1227 * Initialise the common bits of the superblock
1228 */
1229static inline void nfs_initialise_sb(struct super_block *sb)
1230{
1231 struct nfs_server *server = NFS_SB(sb);
1232
1233 sb->s_magic = NFS_SUPER_MAGIC;
1234
1235 /* We probably want something more informative here */
1236 snprintf(sb->s_id, sizeof(sb->s_id),
1237 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1238
1239 if (sb->s_blocksize == 0)
1240 sb->s_blocksize = nfs_block_bits(server->wsize,
1241 &sb->s_blocksize_bits);
1242
1243 if (server->flags & NFS_MOUNT_NOAC)
1244 sb->s_flags |= MS_SYNCHRONOUS;
1245
1246 nfs_super_set_maxbytes(sb, server->maxfilesize);
1247}
1248
1249/*
1250 * Finish setting up an NFS2/3 superblock
1251 */
1252static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
1253{
1254 struct nfs_server *server = NFS_SB(sb);
1255
1256 sb->s_blocksize_bits = 0;
1257 sb->s_blocksize = 0;
1258 if (data->bsize)
1259 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1260
1261 if (server->flags & NFS_MOUNT_VER3) {
1262 /* The VFS shouldn't apply the umask to mode bits. We will do
1263 * so ourselves when necessary.
1264 */
1265 sb->s_flags |= MS_POSIXACL;
1266 sb->s_time_gran = 1;
1267 }
1268
1269 sb->s_op = &nfs_sops;
1270 nfs_initialise_sb(sb);
1271}
1272
1273/*
1274 * Finish setting up a cloned NFS2/3 superblock
1275 */
1276static void nfs_clone_super(struct super_block *sb,
1277 const struct super_block *old_sb)
1278{
1279 struct nfs_server *server = NFS_SB(sb);
1280
1281 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1282 sb->s_blocksize = old_sb->s_blocksize;
1283 sb->s_maxbytes = old_sb->s_maxbytes;
1284
1285 if (server->flags & NFS_MOUNT_VER3) {
1286 /* The VFS shouldn't apply the umask to mode bits. We will do
1287 * so ourselves when necessary.
1288 */
1289 sb->s_flags |= MS_POSIXACL;
1290 sb->s_time_gran = 1;
1291 }
1292
1293 sb->s_op = old_sb->s_op;
1294 nfs_initialise_sb(sb);
1295}
1296
Trond Myklebust275a5d22007-05-16 16:53:28 -04001297#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1298
1299static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1300{
1301 const struct nfs_server *a = s->s_fs_info;
1302 const struct rpc_clnt *clnt_a = a->client;
1303 const struct rpc_clnt *clnt_b = b->client;
1304
1305 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1306 goto Ebusy;
1307 if (a->nfs_client != b->nfs_client)
1308 goto Ebusy;
1309 if (a->flags != b->flags)
1310 goto Ebusy;
1311 if (a->wsize != b->wsize)
1312 goto Ebusy;
1313 if (a->rsize != b->rsize)
1314 goto Ebusy;
1315 if (a->acregmin != b->acregmin)
1316 goto Ebusy;
1317 if (a->acregmax != b->acregmax)
1318 goto Ebusy;
1319 if (a->acdirmin != b->acdirmin)
1320 goto Ebusy;
1321 if (a->acdirmax != b->acdirmax)
1322 goto Ebusy;
1323 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1324 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001325 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001326Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001327 return 0;
1328}
1329
1330struct nfs_sb_mountdata {
1331 struct nfs_server *server;
1332 int mntflags;
1333};
1334
1335static int nfs_set_super(struct super_block *s, void *data)
1336{
1337 struct nfs_sb_mountdata *sb_mntdata = data;
1338 struct nfs_server *server = sb_mntdata->server;
1339 int ret;
1340
1341 s->s_flags = sb_mntdata->mntflags;
1342 s->s_fs_info = server;
1343 ret = set_anon_super(s, server);
1344 if (ret == 0)
1345 server->s_dev = s->s_dev;
1346 return ret;
1347}
1348
1349static int nfs_compare_super(struct super_block *sb, void *data)
1350{
1351 struct nfs_sb_mountdata *sb_mntdata = data;
1352 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1353 int mntflags = sb_mntdata->mntflags;
1354
1355 if (memcmp(&old->nfs_client->cl_addr,
1356 &server->nfs_client->cl_addr,
1357 sizeof(old->nfs_client->cl_addr)) != 0)
1358 return 0;
1359 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1360 if (old->flags & NFS_MOUNT_UNSHARED)
1361 return 0;
1362 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1363 return 0;
1364 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001365}
1366
David Howells54ceac42006-08-22 20:06:13 -04001367static int nfs_get_sb(struct file_system_type *fs_type,
1368 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1369{
1370 struct nfs_server *server = NULL;
1371 struct super_block *s;
1372 struct nfs_fh mntfh;
1373 struct nfs_mount_data *data = raw_data;
1374 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001375 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001376 struct nfs_sb_mountdata sb_mntdata = {
1377 .mntflags = flags,
1378 };
David Howells54ceac42006-08-22 20:06:13 -04001379 int error;
1380
1381 /* Validate the mount data */
Chuck Lever136d5582007-07-01 12:13:54 -04001382 error = nfs_validate_mount_data(&data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001383 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001384 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001385
1386 /* Get a volume representation */
1387 server = nfs_create_server(data, &mntfh);
1388 if (IS_ERR(server)) {
1389 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001390 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001391 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001392 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001393
Trond Myklebust75180df2007-05-16 16:53:28 -04001394 if (server->flags & NFS_MOUNT_UNSHARED)
1395 compare_super = NULL;
1396
David Howells54ceac42006-08-22 20:06:13 -04001397 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001398 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001399 if (IS_ERR(s)) {
1400 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001401 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001402 }
1403
David Howells54ceac42006-08-22 20:06:13 -04001404 if (s->s_fs_info != server) {
1405 nfs_free_server(server);
1406 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001407 }
David Howells54ceac42006-08-22 20:06:13 -04001408
1409 if (!s->s_root) {
1410 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001411 nfs_fill_super(s, data);
1412 }
1413
1414 mntroot = nfs_get_root(s, &mntfh);
1415 if (IS_ERR(mntroot)) {
1416 error = PTR_ERR(mntroot);
1417 goto error_splat_super;
1418 }
1419
David Howellsf7b422b2006-06-09 09:34:33 -04001420 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001421 mnt->mnt_sb = s;
1422 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001423 error = 0;
1424
1425out:
Chuck Lever136d5582007-07-01 12:13:54 -04001426 if (data != raw_data)
1427 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04001428 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001429
David Howells54ceac42006-08-22 20:06:13 -04001430out_err_nosb:
1431 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001432 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001433
1434error_splat_super:
1435 up_write(&s->s_umount);
1436 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001437 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001438}
1439
David Howells54ceac42006-08-22 20:06:13 -04001440/*
1441 * Destroy an NFS2/3 superblock
1442 */
David Howellsf7b422b2006-06-09 09:34:33 -04001443static void nfs_kill_super(struct super_block *s)
1444{
1445 struct nfs_server *server = NFS_SB(s);
1446
1447 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001448 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001449}
1450
David Howells54ceac42006-08-22 20:06:13 -04001451/*
1452 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1453 */
1454static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1455 const char *dev_name, void *raw_data,
1456 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001457{
1458 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001459 struct super_block *s;
1460 struct nfs_server *server;
1461 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001462 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001463 struct nfs_sb_mountdata sb_mntdata = {
1464 .mntflags = flags,
1465 };
David Howells54ceac42006-08-22 20:06:13 -04001466 int error;
1467
1468 dprintk("--> nfs_xdev_get_sb()\n");
1469
1470 /* create a new volume representation */
1471 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1472 if (IS_ERR(server)) {
1473 error = PTR_ERR(server);
1474 goto out_err_noserver;
1475 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001476 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001477
Trond Myklebust75180df2007-05-16 16:53:28 -04001478 if (server->flags & NFS_MOUNT_UNSHARED)
1479 compare_super = NULL;
1480
David Howells54ceac42006-08-22 20:06:13 -04001481 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001482 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001483 if (IS_ERR(s)) {
1484 error = PTR_ERR(s);
1485 goto out_err_nosb;
1486 }
1487
1488 if (s->s_fs_info != server) {
1489 nfs_free_server(server);
1490 server = NULL;
1491 }
1492
1493 if (!s->s_root) {
1494 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001495 nfs_clone_super(s, data->sb);
1496 }
1497
1498 mntroot = nfs_get_root(s, data->fh);
1499 if (IS_ERR(mntroot)) {
1500 error = PTR_ERR(mntroot);
1501 goto error_splat_super;
1502 }
1503
1504 s->s_flags |= MS_ACTIVE;
1505 mnt->mnt_sb = s;
1506 mnt->mnt_root = mntroot;
1507
1508 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1509 return 0;
1510
1511out_err_nosb:
1512 nfs_free_server(server);
1513out_err_noserver:
1514 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1515 return error;
1516
1517error_splat_super:
1518 up_write(&s->s_umount);
1519 deactivate_super(s);
1520 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1521 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001522}
1523
1524#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001525
1526/*
1527 * Finish setting up a cloned NFS4 superblock
1528 */
1529static void nfs4_clone_super(struct super_block *sb,
1530 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001531{
David Howells54ceac42006-08-22 20:06:13 -04001532 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1533 sb->s_blocksize = old_sb->s_blocksize;
1534 sb->s_maxbytes = old_sb->s_maxbytes;
1535 sb->s_time_gran = 1;
1536 sb->s_op = old_sb->s_op;
1537 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001538}
1539
1540/*
1541 * Set up an NFS4 superblock
1542 */
David Howells54ceac42006-08-22 20:06:13 -04001543static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001544{
David Howellsf7b422b2006-06-09 09:34:33 -04001545 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001546 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001547 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001548}
1549
David Howells54ceac42006-08-22 20:06:13 -04001550/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001551 * Validate NFSv4 mount options
1552 */
1553static int nfs4_validate_mount_data(struct nfs4_mount_data **options,
1554 const char *dev_name,
1555 struct sockaddr_in *addr,
1556 rpc_authflavor_t *authflavour,
1557 char **hostname,
1558 char **mntpath,
1559 char **ip_addr)
1560{
1561 struct nfs4_mount_data *data = *options;
1562 char *c;
1563
1564 if (data == NULL)
1565 goto out_no_data;
1566
1567 switch (data->version) {
1568 case 1:
1569 if (data->host_addrlen != sizeof(*addr))
1570 goto out_no_address;
1571 if (copy_from_user(addr, data->host_addr, sizeof(*addr)))
1572 return -EFAULT;
1573 if (addr->sin_port == 0)
1574 addr->sin_port = htons(NFS_PORT);
1575 if (!nfs_verify_server_address((struct sockaddr *) addr))
1576 goto out_no_address;
1577
1578 switch (data->auth_flavourlen) {
1579 case 0:
1580 *authflavour = RPC_AUTH_UNIX;
1581 break;
1582 case 1:
1583 if (copy_from_user(authflavour, data->auth_flavours,
1584 sizeof(*authflavour)))
1585 return -EFAULT;
1586 break;
1587 default:
1588 goto out_inval_auth;
1589 }
1590
1591 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1592 if (IS_ERR(c))
1593 return PTR_ERR(c);
1594 *hostname = c;
1595
1596 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1597 if (IS_ERR(c))
1598 return PTR_ERR(c);
1599 *mntpath = c;
1600 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *mntpath);
1601
1602 c = strndup_user(data->client_addr.data, 16);
1603 if (IS_ERR(c))
1604 return PTR_ERR(c);
1605 *ip_addr = c;
1606
1607 break;
Chuck Lever80071222007-07-01 12:13:59 -04001608 default: {
1609 unsigned int len;
1610 struct nfs_parsed_mount_data args = {
1611 .rsize = NFS_MAX_FILE_IO_SIZE,
1612 .wsize = NFS_MAX_FILE_IO_SIZE,
1613 .timeo = 600,
1614 .retrans = 2,
1615 .acregmin = 3,
1616 .acregmax = 60,
1617 .acdirmin = 30,
1618 .acdirmax = 60,
1619 .nfs_server.protocol = IPPROTO_TCP,
1620 };
1621
1622 if (nfs_parse_mount_options((char *) *options, &args) == 0)
1623 return -EINVAL;
1624
1625 if (!nfs_verify_server_address((struct sockaddr *)
1626 &args.nfs_server.address))
1627 return -EINVAL;
1628 *addr = args.nfs_server.address;
1629
1630 switch (args.auth_flavor_len) {
1631 case 0:
1632 *authflavour = RPC_AUTH_UNIX;
1633 break;
1634 case 1:
1635 *authflavour = (rpc_authflavor_t) args.auth_flavors[0];
1636 break;
1637 default:
1638 goto out_inval_auth;
1639 }
1640
1641 /*
1642 * Translate to nfs4_mount_data, which nfs4_fill_super
1643 * can deal with.
1644 */
1645 data = kzalloc(sizeof(*data), GFP_KERNEL);
1646 if (data == NULL)
1647 return -ENOMEM;
1648 *options = data;
1649
1650 data->version = 1;
1651 data->flags = args.flags & NFS4_MOUNT_FLAGMASK;
1652 data->rsize = args.rsize;
1653 data->wsize = args.wsize;
1654 data->timeo = args.timeo;
1655 data->retrans = args.retrans;
1656 data->acregmin = args.acregmin;
1657 data->acregmax = args.acregmax;
1658 data->acdirmin = args.acdirmin;
1659 data->acdirmax = args.acdirmax;
1660 data->proto = args.nfs_server.protocol;
1661
1662 /*
1663 * Split "dev_name" into "hostname:mntpath".
1664 */
1665 c = strchr(dev_name, ':');
1666 if (c == NULL)
1667 return -EINVAL;
1668 /* while calculating len, pretend ':' is '\0' */
1669 len = c - dev_name;
1670 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001671 return -ENAMETOOLONG;
Chuck Lever80071222007-07-01 12:13:59 -04001672 *hostname = kzalloc(len, GFP_KERNEL);
1673 if (*hostname == NULL)
1674 return -ENOMEM;
1675 strncpy(*hostname, dev_name, len - 1);
1676
1677 c++; /* step over the ':' */
1678 len = strlen(c);
1679 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001680 return -ENAMETOOLONG;
Chuck Lever80071222007-07-01 12:13:59 -04001681 *mntpath = kzalloc(len + 1, GFP_KERNEL);
1682 if (*mntpath == NULL)
1683 return -ENOMEM;
1684 strncpy(*mntpath, c, len);
1685
1686 dprintk("MNTPATH: %s\n", *mntpath);
1687
Jeff Layton0a87cf12007-07-18 11:28:43 -04001688 if (args.client_address == NULL)
1689 goto out_no_client_address;
1690
Chuck Lever80071222007-07-01 12:13:59 -04001691 *ip_addr = args.client_address;
1692
1693 break;
1694 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001695 }
1696
1697 return 0;
1698
1699out_no_data:
1700 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1701 return -EINVAL;
1702
1703out_inval_auth:
1704 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1705 data->auth_flavourlen);
1706 return -EINVAL;
1707
1708out_no_address:
1709 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1710 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001711
1712out_no_client_address:
1713 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1714 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001715}
1716
1717/*
David Howells54ceac42006-08-22 20:06:13 -04001718 * Get the superblock for an NFS4 mountpoint
1719 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001720static int nfs4_get_sb(struct file_system_type *fs_type,
1721 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001722{
David Howellsf7b422b2006-06-09 09:34:33 -04001723 struct nfs4_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001724 struct super_block *s;
1725 struct nfs_server *server;
1726 struct sockaddr_in addr;
1727 rpc_authflavor_t authflavour;
1728 struct nfs_fh mntfh;
1729 struct dentry *mntroot;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001730 char *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
Trond Myklebust75180df2007-05-16 16:53:28 -04001731 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001732 struct nfs_sb_mountdata sb_mntdata = {
1733 .mntflags = flags,
1734 };
David Howells54ceac42006-08-22 20:06:13 -04001735 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001736
Chuck Leverf0768eb2007-07-01 12:13:01 -04001737 /* Validate the mount data */
1738 error = nfs4_validate_mount_data(&data, dev_name, &addr, &authflavour,
1739 &hostname, &mntpath, &ip_addr);
1740 if (error < 0)
1741 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001742
David Howells54ceac42006-08-22 20:06:13 -04001743 /* Get a volume representation */
1744 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
1745 authflavour, &mntfh);
1746 if (IS_ERR(server)) {
1747 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001748 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001749 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001750 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001751
Trond Myklebust75180df2007-05-16 16:53:28 -04001752 if (server->flags & NFS4_MOUNT_UNSHARED)
1753 compare_super = NULL;
1754
David Howells54ceac42006-08-22 20:06:13 -04001755 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001756 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001757 if (IS_ERR(s)) {
1758 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001759 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001760 }
1761
Trond Myklebust5dd31772006-08-24 01:03:05 -04001762 if (s->s_fs_info != server) {
1763 nfs_free_server(server);
1764 server = NULL;
1765 }
1766
David Howells54ceac42006-08-22 20:06:13 -04001767 if (!s->s_root) {
1768 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001769 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001770 }
David Howellsf7b422b2006-06-09 09:34:33 -04001771
David Howells54ceac42006-08-22 20:06:13 -04001772 mntroot = nfs4_get_root(s, &mntfh);
1773 if (IS_ERR(mntroot)) {
1774 error = PTR_ERR(mntroot);
1775 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001776 }
David Howells54ceac42006-08-22 20:06:13 -04001777
David Howellsf7b422b2006-06-09 09:34:33 -04001778 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001779 mnt->mnt_sb = s;
1780 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001781 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001782
Chuck Lever29eb9812007-07-01 12:12:30 -04001783out:
1784 kfree(ip_addr);
David Howells54ceac42006-08-22 20:06:13 -04001785 kfree(mntpath);
1786 kfree(hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001787 return error;
David Howells54ceac42006-08-22 20:06:13 -04001788
Chuck Lever29eb9812007-07-01 12:12:30 -04001789out_free:
1790 nfs_free_server(server);
1791 goto out;
1792
David Howells54ceac42006-08-22 20:06:13 -04001793error_splat_super:
1794 up_write(&s->s_umount);
1795 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001796 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001797}
1798
1799static void nfs4_kill_super(struct super_block *sb)
1800{
1801 struct nfs_server *server = NFS_SB(sb);
1802
1803 nfs_return_all_delegations(sb);
1804 kill_anon_super(sb);
1805
1806 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001807 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001808}
1809
1810/*
David Howells54ceac42006-08-22 20:06:13 -04001811 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001812 */
David Howells54ceac42006-08-22 20:06:13 -04001813static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1814 const char *dev_name, void *raw_data,
1815 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001816{
1817 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001818 struct super_block *s;
1819 struct nfs_server *server;
1820 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001821 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001822 struct nfs_sb_mountdata sb_mntdata = {
1823 .mntflags = flags,
1824 };
David Howells54ceac42006-08-22 20:06:13 -04001825 int error;
1826
1827 dprintk("--> nfs4_xdev_get_sb()\n");
1828
1829 /* create a new volume representation */
1830 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1831 if (IS_ERR(server)) {
1832 error = PTR_ERR(server);
1833 goto out_err_noserver;
1834 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001835 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001836
Trond Myklebust75180df2007-05-16 16:53:28 -04001837 if (server->flags & NFS4_MOUNT_UNSHARED)
1838 compare_super = NULL;
1839
David Howells54ceac42006-08-22 20:06:13 -04001840 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001841 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001842 if (IS_ERR(s)) {
1843 error = PTR_ERR(s);
1844 goto out_err_nosb;
1845 }
1846
1847 if (s->s_fs_info != server) {
1848 nfs_free_server(server);
1849 server = NULL;
1850 }
1851
1852 if (!s->s_root) {
1853 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001854 nfs4_clone_super(s, data->sb);
1855 }
1856
1857 mntroot = nfs4_get_root(s, data->fh);
1858 if (IS_ERR(mntroot)) {
1859 error = PTR_ERR(mntroot);
1860 goto error_splat_super;
1861 }
1862
1863 s->s_flags |= MS_ACTIVE;
1864 mnt->mnt_sb = s;
1865 mnt->mnt_root = mntroot;
1866
1867 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1868 return 0;
1869
1870out_err_nosb:
1871 nfs_free_server(server);
1872out_err_noserver:
1873 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1874 return error;
1875
1876error_splat_super:
1877 up_write(&s->s_umount);
1878 deactivate_super(s);
1879 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1880 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001881}
1882
David Howells54ceac42006-08-22 20:06:13 -04001883/*
1884 * Create an NFS4 server record on referral traversal
1885 */
1886static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1887 const char *dev_name, void *raw_data,
1888 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001889{
1890 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001891 struct super_block *s;
1892 struct nfs_server *server;
1893 struct dentry *mntroot;
1894 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001895 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001896 struct nfs_sb_mountdata sb_mntdata = {
1897 .mntflags = flags,
1898 };
David Howells54ceac42006-08-22 20:06:13 -04001899 int error;
1900
1901 dprintk("--> nfs4_referral_get_sb()\n");
1902
1903 /* create a new volume representation */
1904 server = nfs4_create_referral_server(data, &mntfh);
1905 if (IS_ERR(server)) {
1906 error = PTR_ERR(server);
1907 goto out_err_noserver;
1908 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001909 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001910
Trond Myklebust75180df2007-05-16 16:53:28 -04001911 if (server->flags & NFS4_MOUNT_UNSHARED)
1912 compare_super = NULL;
1913
David Howells54ceac42006-08-22 20:06:13 -04001914 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001915 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001916 if (IS_ERR(s)) {
1917 error = PTR_ERR(s);
1918 goto out_err_nosb;
1919 }
1920
1921 if (s->s_fs_info != server) {
1922 nfs_free_server(server);
1923 server = NULL;
1924 }
1925
1926 if (!s->s_root) {
1927 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001928 nfs4_fill_super(s);
1929 }
1930
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001931 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001932 if (IS_ERR(mntroot)) {
1933 error = PTR_ERR(mntroot);
1934 goto error_splat_super;
1935 }
1936
1937 s->s_flags |= MS_ACTIVE;
1938 mnt->mnt_sb = s;
1939 mnt->mnt_root = mntroot;
1940
1941 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1942 return 0;
1943
1944out_err_nosb:
1945 nfs_free_server(server);
1946out_err_noserver:
1947 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1948 return error;
1949
1950error_splat_super:
1951 up_write(&s->s_umount);
1952 deactivate_super(s);
1953 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1954 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001955}
1956
David Howells54ceac42006-08-22 20:06:13 -04001957#endif /* CONFIG_NFS_V4 */