blob: 20a1cb1810fef50c9a4ce67f5ec9a5f1312e25ba [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
David Howellsf7b422b2006-06-09 09:34:33 -040050#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080051#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040052#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053
54#include <asm/system.h>
55#include <asm/uaccess.h>
56
57#include "nfs4_fs.h"
58#include "callback.h"
59#include "delegation.h"
60#include "iostat.h"
61#include "internal.h"
62
63#define NFSDBG_FACILITY NFSDBG_VFS
64
Chuck Leverbf0fd762007-07-01 12:13:44 -040065enum {
66 /* Mount options that take no arguments */
67 Opt_soft, Opt_hard,
68 Opt_intr, Opt_nointr,
69 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac,
72 Opt_lock, Opt_nolock,
73 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040074 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075 Opt_acl, Opt_noacl,
76 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040077 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078
79 /* Mount options that take integer arguments */
80 Opt_port,
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
85 Opt_actimeo,
86 Opt_namelen,
87 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040088 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040089 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050092 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040093 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
97
98 Opt_err
99};
100
101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
110 { Opt_cto, "cto" },
111 { Opt_nocto, "nocto" },
112 { Opt_ac, "ac" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
116 { Opt_v2, "v2" },
117 { Opt_v3, "v3" },
118 { Opt_udp, "udp" },
119 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400120 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_acl, "acl" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
145
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500151 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400152 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153
154 { Opt_err, NULL }
155};
156
157enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400158 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400159
160 Opt_xprt_err
161};
162
163static match_table_t nfs_xprt_protocol_tokens = {
164 { Opt_xprt_udp, "udp" },
165 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400166 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400167
168 { Opt_xprt_err, NULL }
169};
170
171enum {
172 Opt_sec_none, Opt_sec_sys,
173 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
174 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
175 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
176
177 Opt_sec_err
178};
179
180static match_table_t nfs_secflavor_tokens = {
181 { Opt_sec_none, "none" },
182 { Opt_sec_none, "null" },
183 { Opt_sec_sys, "sys" },
184
185 { Opt_sec_krb5, "krb5" },
186 { Opt_sec_krb5i, "krb5i" },
187 { Opt_sec_krb5p, "krb5p" },
188
189 { Opt_sec_lkey, "lkey" },
190 { Opt_sec_lkeyi, "lkeyi" },
191 { Opt_sec_lkeyp, "lkeyp" },
192
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500193 { Opt_sec_spkm, "spkm3" },
194 { Opt_sec_spkmi, "spkm3i" },
195 { Opt_sec_spkmp, "spkm3p" },
196
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197 { Opt_sec_err, NULL }
198};
199
200
David Howellsf7b422b2006-06-09 09:34:33 -0400201static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400202static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400203static int nfs_show_options(struct seq_file *, struct vfsmount *);
204static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400205static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400206static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400207 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400208static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500209static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400210
211static struct file_system_type nfs_fs_type = {
212 .owner = THIS_MODULE,
213 .name = "nfs",
214 .get_sb = nfs_get_sb,
215 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700216 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400217};
218
David Howells54ceac42006-08-22 20:06:13 -0400219struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400220 .owner = THIS_MODULE,
221 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400222 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400223 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700224 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400225};
226
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800227static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400228 .alloc_inode = nfs_alloc_inode,
229 .destroy_inode = nfs_destroy_inode,
230 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500231 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400232 .statfs = nfs_statfs,
233 .clear_inode = nfs_clear_inode,
234 .umount_begin = nfs_umount_begin,
235 .show_options = nfs_show_options,
236 .show_stats = nfs_show_stats,
237};
238
239#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400240static int nfs4_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400242static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
244static int nfs4_referral_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400246static void nfs4_kill_super(struct super_block *sb);
247
248static struct file_system_type nfs4_fs_type = {
249 .owner = THIS_MODULE,
250 .name = "nfs4",
251 .get_sb = nfs4_get_sb,
252 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700253 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400254};
255
David Howells54ceac42006-08-22 20:06:13 -0400256struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400257 .owner = THIS_MODULE,
258 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400259 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400260 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700261 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400262};
263
David Howells54ceac42006-08-22 20:06:13 -0400264struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400265 .owner = THIS_MODULE,
266 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400267 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400268 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700269 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400270};
271
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800272static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400273 .alloc_inode = nfs_alloc_inode,
274 .destroy_inode = nfs_destroy_inode,
275 .write_inode = nfs_write_inode,
276 .statfs = nfs_statfs,
277 .clear_inode = nfs4_clear_inode,
278 .umount_begin = nfs_umount_begin,
279 .show_options = nfs_show_options,
280 .show_stats = nfs_show_stats,
281};
282#endif
283
Rusty Russell8e1f9362007-07-17 04:03:17 -0700284static struct shrinker acl_shrinker = {
285 .shrink = nfs_access_cache_shrinker,
286 .seeks = DEFAULT_SEEKS,
287};
Trond Myklebust979df722006-07-25 11:28:19 -0400288
David Howellsf7b422b2006-06-09 09:34:33 -0400289/*
290 * Register the NFS filesystems
291 */
292int __init register_nfs_fs(void)
293{
294 int ret;
295
296 ret = register_filesystem(&nfs_fs_type);
297 if (ret < 0)
298 goto error_0;
299
David Howellsf7b422b2006-06-09 09:34:33 -0400300 ret = nfs_register_sysctl();
301 if (ret < 0)
302 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800303#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400304 ret = register_filesystem(&nfs4_fs_type);
305 if (ret < 0)
306 goto error_2;
307#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700308 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400309 return 0;
310
311#ifdef CONFIG_NFS_V4
312error_2:
313 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800314#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400315error_1:
316 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400317error_0:
318 return ret;
319}
320
321/*
322 * Unregister the NFS filesystems
323 */
324void __exit unregister_nfs_fs(void)
325{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700326 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400327#ifdef CONFIG_NFS_V4
328 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400329#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700330 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400331 unregister_filesystem(&nfs_fs_type);
332}
333
Steve Dicksonef818a22007-11-08 04:05:04 -0500334void nfs_sb_active(struct nfs_server *server)
335{
336 atomic_inc(&server->active);
337}
338
339void nfs_sb_deactive(struct nfs_server *server)
340{
341 if (atomic_dec_and_test(&server->active))
342 wake_up(&server->active_wq);
343}
344
345static void nfs_put_super(struct super_block *sb)
346{
347 struct nfs_server *server = NFS_SB(sb);
348 /*
349 * Make sure there are no outstanding ops to this server.
350 * If so, wait for them to finish before allowing the
351 * unmount to continue.
352 */
353 wait_event(server->active_wq, atomic_read(&server->active) == 0);
354}
355
David Howellsf7b422b2006-06-09 09:34:33 -0400356/*
357 * Deliver file system statistics to userspace
358 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400359static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400360{
David Howells0c7d90c2006-08-22 20:06:10 -0400361 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400362 unsigned char blockbits;
363 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400364 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400365 struct nfs_fattr fattr;
366 struct nfs_fsstat res = {
367 .fattr = &fattr,
368 };
369 int error;
370
371 lock_kernel();
372
David Howells8fa5c002006-08-22 20:06:12 -0400373 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400374 if (error < 0)
375 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700376 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400377
378 /*
379 * Current versions of glibc do not correctly handle the
380 * case where f_frsize != f_bsize. Eventually we want to
381 * report the value of wtmult in this field.
382 */
David Howells0c7d90c2006-08-22 20:06:10 -0400383 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400384
385 /*
386 * On most *nix systems, f_blocks, f_bfree, and f_bavail
387 * are reported in units of f_frsize. Linux hasn't had
388 * an f_frsize field in its statfs struct until recently,
389 * thus historically Linux's sys_statfs reports these
390 * fields in units of f_bsize.
391 */
David Howells0c7d90c2006-08-22 20:06:10 -0400392 buf->f_bsize = dentry->d_sb->s_blocksize;
393 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400394 blockres = (1 << blockbits) - 1;
395 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
396 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
397 buf->f_bavail = (res.abytes + blockres) >> blockbits;
398
399 buf->f_files = res.tfiles;
400 buf->f_ffree = res.afiles;
401
402 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700403
David Howellsf7b422b2006-06-09 09:34:33 -0400404 unlock_kernel();
405 return 0;
406
407 out_err:
408 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700409 unlock_kernel();
410 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400411}
412
David Howells7d4e2742006-08-22 20:06:07 -0400413/*
414 * Map the security flavour number to a name
415 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400416static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
417{
David Howells7d4e2742006-08-22 20:06:07 -0400418 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400419 rpc_authflavor_t flavour;
420 const char *str;
421 } sec_flavours[] = {
422 { RPC_AUTH_NULL, "null" },
423 { RPC_AUTH_UNIX, "sys" },
424 { RPC_AUTH_GSS_KRB5, "krb5" },
425 { RPC_AUTH_GSS_KRB5I, "krb5i" },
426 { RPC_AUTH_GSS_KRB5P, "krb5p" },
427 { RPC_AUTH_GSS_LKEY, "lkey" },
428 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
429 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
430 { RPC_AUTH_GSS_SPKM, "spkm" },
431 { RPC_AUTH_GSS_SPKMI, "spkmi" },
432 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400433 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400434 };
435 int i;
436
Chuck Lever4d81cd12007-07-01 12:12:40 -0400437 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400438 if (sec_flavours[i].flavour == flavour)
439 break;
440 }
441 return sec_flavours[i].str;
442}
443
Chuck Lever82d101d2008-03-14 14:10:37 -0400444static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
445 int showdefaults)
446{
447 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
448
449 switch (sap->sa_family) {
450 case AF_INET: {
451 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
452 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
453 NIPQUAD(sin->sin_addr.s_addr));
454 break;
455 }
456 case AF_INET6: {
457 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
458 seq_printf(m, ",mountaddr=" NIP6_FMT,
459 NIP6(sin6->sin6_addr));
460 break;
461 }
462 default:
463 if (showdefaults)
464 seq_printf(m, ",mountaddr=unspecified");
465 }
466
467 if (nfss->mountd_version || showdefaults)
468 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
469 if (nfss->mountd_port || showdefaults)
470 seq_printf(m, ",mountport=%u", nfss->mountd_port);
471
472 switch (nfss->mountd_protocol) {
473 case IPPROTO_UDP:
474 seq_printf(m, ",mountproto=udp");
475 break;
476 case IPPROTO_TCP:
477 seq_printf(m, ",mountproto=tcp");
478 break;
479 default:
480 if (showdefaults)
481 seq_printf(m, ",mountproto=auto");
482 }
483}
484
David Howellsf7b422b2006-06-09 09:34:33 -0400485/*
486 * Describe the mount options in force on this server representation
487 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400488static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
489 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400490{
David Howells509de812006-08-22 20:06:11 -0400491 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400492 int flag;
David Howells509de812006-08-22 20:06:11 -0400493 const char *str;
494 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400495 } nfs_info[] = {
496 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400497 { NFS_MOUNT_INTR, ",intr", ",nointr" },
498 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400499 { NFS_MOUNT_NOCTO, ",nocto", "" },
500 { NFS_MOUNT_NOAC, ",noac", "" },
501 { NFS_MOUNT_NONLM, ",nolock", "" },
502 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400503 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400504 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400505 { 0, NULL, NULL }
506 };
David Howells509de812006-08-22 20:06:11 -0400507 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400508 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400509 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400510
Chuck Lever82d101d2008-03-14 14:10:37 -0400511 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400512 seq_printf(m, ",rsize=%u", nfss->rsize);
513 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400514 if (nfss->bsize != 0)
515 seq_printf(m, ",bsize=%u", nfss->bsize);
516 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400517 if (nfss->acregmin != 3*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400518 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400519 if (nfss->acregmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400520 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400521 if (nfss->acdirmin != 30*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400522 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400523 if (nfss->acdirmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400524 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400525 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
526 if (nfss->flags & nfs_infop->flag)
527 seq_puts(m, nfs_infop->str);
528 else
529 seq_puts(m, nfs_infop->nostr);
530 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400531 seq_printf(m, ",proto=%s",
532 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400533 if (version == 4) {
534 if (nfss->port != NFS_PORT)
535 seq_printf(m, ",port=%u", nfss->port);
536 } else
537 if (nfss->port)
538 seq_printf(m, ",port=%u", nfss->port);
539
Trond Myklebust33170232007-12-20 16:03:59 -0500540 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
541 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400542 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400543
544 if (version != 4)
545 nfs_show_mountd_options(m, nfss, showdefaults);
546
547#ifdef CONFIG_NFS_V4
548 if (clp->rpc_ops->version == 4)
549 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
550#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400551}
552
553/*
554 * Describe the mount options on this VFS mountpoint
555 */
556static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
557{
558 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
559
560 nfs_show_mount_options(m, nfss, 0);
561
Chuck Lever5d8515c2007-12-10 14:57:16 -0500562 seq_printf(m, ",addr=%s",
563 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
564 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400565
566 return 0;
567}
568
569/*
570 * Present statistical information for this VFS mountpoint
571 */
572static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
573{
574 int i, cpu;
575 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
576 struct rpc_auth *auth = nfss->client->cl_auth;
577 struct nfs_iostats totals = { };
578
579 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
580
581 /*
582 * Display all mount option settings
583 */
584 seq_printf(m, "\n\topts:\t");
585 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
586 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
587 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
588 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
589 nfs_show_mount_options(m, nfss, 1);
590
591 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
592
593 seq_printf(m, "\n\tcaps:\t");
594 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400595 seq_printf(m, ",wtmult=%u", nfss->wtmult);
596 seq_printf(m, ",dtsize=%u", nfss->dtsize);
597 seq_printf(m, ",bsize=%u", nfss->bsize);
598 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400599
600#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500601 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400602 seq_printf(m, "\n\tnfsv4:\t");
603 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
604 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
605 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
606 }
607#endif
608
609 /*
610 * Display security flavor in effect for this mount
611 */
Chuck Lever2d767432008-03-14 14:10:08 -0400612 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400613 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400614 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400615
616 /*
617 * Display superblock I/O counters
618 */
619 for_each_possible_cpu(cpu) {
620 struct nfs_iostats *stats;
621
622 preempt_disable();
623 stats = per_cpu_ptr(nfss->io_stats, cpu);
624
625 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
626 totals.events[i] += stats->events[i];
627 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
628 totals.bytes[i] += stats->bytes[i];
629
630 preempt_enable();
631 }
632
633 seq_printf(m, "\n\tevents:\t");
634 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
635 seq_printf(m, "%lu ", totals.events[i]);
636 seq_printf(m, "\n\tbytes:\t");
637 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
638 seq_printf(m, "%Lu ", totals.bytes[i]);
639 seq_printf(m, "\n");
640
641 rpc_print_iostats(m, nfss->client);
642
643 return 0;
644}
645
646/*
647 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400648 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400649 */
650static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
651{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400652 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
653 struct rpc_clnt *rpc;
654
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400655 if (!(flags & MNT_FORCE))
656 return;
657 /* -EIO all pending I/O */
658 rpc = server->client_acl;
659 if (!IS_ERR(rpc))
660 rpc_killall_tasks(rpc);
661 rpc = server->client;
662 if (!IS_ERR(rpc))
663 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400664}
665
666/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500667 * Set the port number in an address. Be agnostic about the address family.
668 */
669static void nfs_set_port(struct sockaddr *sap, unsigned short port)
670{
671 switch (sap->sa_family) {
672 case AF_INET: {
673 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
674 ap->sin_port = htons(port);
675 break;
676 }
677 case AF_INET6: {
678 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
679 ap->sin6_port = htons(port);
680 break;
681 }
682 }
683}
684
685/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500686 * Sanity-check a server address provided by the mount command.
687 *
688 * Address family must be initialized, and address must not be
689 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400690 */
691static int nfs_verify_server_address(struct sockaddr *addr)
692{
693 switch (addr->sa_family) {
694 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500695 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700696 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500697 }
698 case AF_INET6: {
699 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
700 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400701 }
702 }
703
704 return 0;
705}
706
707/*
Chuck Lever9412b922007-12-10 14:59:21 -0500708 * Parse string addresses passed in via a mount option,
709 * and construct a sockaddr based on the result.
710 *
711 * If address parsing fails, set the sockaddr's address
712 * family to AF_UNSPEC to force nfs_verify_server_address()
713 * to punt the mount.
714 */
715static void nfs_parse_server_address(char *value,
Chuck Lever4c568012007-12-10 14:59:28 -0500716 struct sockaddr *sap,
717 size_t *len)
Chuck Lever9412b922007-12-10 14:59:21 -0500718{
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500719 if (strchr(value, ':')) {
720 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
721 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
Chuck Lever9412b922007-12-10 14:59:21 -0500722
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500723 ap->sin6_family = AF_INET6;
724 *len = sizeof(*ap);
725 if (in6_pton(value, -1, addr, '\0', NULL))
726 return;
727 } else {
728 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
729 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
730
731 ap->sin_family = AF_INET;
732 *len = sizeof(*ap);
733 if (in4_pton(value, -1, addr, '\0', NULL))
734 return;
735 }
Chuck Lever9412b922007-12-10 14:59:21 -0500736
737 sap->sa_family = AF_UNSPEC;
Chuck Lever4c568012007-12-10 14:59:28 -0500738 *len = 0;
Chuck Lever9412b922007-12-10 14:59:21 -0500739}
740
741/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400742 * Error-check and convert a string of mount options from user space into
743 * a data structure
744 */
745static int nfs_parse_mount_options(char *raw,
746 struct nfs_parsed_mount_data *mnt)
747{
Eric Parisf9c3a382008-03-05 14:20:18 -0500748 char *p, *string, *secdata;
Eric Parisf9c3a382008-03-05 14:20:18 -0500749 int rc;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400750
751 if (!raw) {
752 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
753 return 1;
754 }
755 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
756
Eric Parisf9c3a382008-03-05 14:20:18 -0500757 secdata = alloc_secdata();
758 if (!secdata)
759 goto out_nomem;
760
761 rc = security_sb_copy_data(raw, secdata);
762 if (rc)
763 goto out_security_failure;
764
765 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
766 if (rc)
767 goto out_security_failure;
768
769 free_secdata(secdata);
770
Chuck Leverbf0fd762007-07-01 12:13:44 -0400771 while ((p = strsep(&raw, ",")) != NULL) {
772 substring_t args[MAX_OPT_ARGS];
773 int option, token;
774
775 if (!*p)
776 continue;
777
778 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
779
780 token = match_token(p, nfs_mount_option_tokens, args);
781 switch (token) {
782 case Opt_soft:
783 mnt->flags |= NFS_MOUNT_SOFT;
784 break;
785 case Opt_hard:
786 mnt->flags &= ~NFS_MOUNT_SOFT;
787 break;
788 case Opt_intr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400789 case Opt_nointr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400790 break;
791 case Opt_posix:
792 mnt->flags |= NFS_MOUNT_POSIX;
793 break;
794 case Opt_noposix:
795 mnt->flags &= ~NFS_MOUNT_POSIX;
796 break;
797 case Opt_cto:
798 mnt->flags &= ~NFS_MOUNT_NOCTO;
799 break;
800 case Opt_nocto:
801 mnt->flags |= NFS_MOUNT_NOCTO;
802 break;
803 case Opt_ac:
804 mnt->flags &= ~NFS_MOUNT_NOAC;
805 break;
806 case Opt_noac:
807 mnt->flags |= NFS_MOUNT_NOAC;
808 break;
809 case Opt_lock:
810 mnt->flags &= ~NFS_MOUNT_NONLM;
811 break;
812 case Opt_nolock:
813 mnt->flags |= NFS_MOUNT_NONLM;
814 break;
815 case Opt_v2:
816 mnt->flags &= ~NFS_MOUNT_VER3;
817 break;
818 case Opt_v3:
819 mnt->flags |= NFS_MOUNT_VER3;
820 break;
821 case Opt_udp:
822 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400823 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400824 mnt->timeo = 7;
825 mnt->retrans = 5;
826 break;
827 case Opt_tcp:
828 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400829 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400830 mnt->timeo = 600;
831 mnt->retrans = 2;
832 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400833 case Opt_rdma:
834 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
835 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
836 mnt->timeo = 600;
837 mnt->retrans = 2;
838 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400839 case Opt_acl:
840 mnt->flags &= ~NFS_MOUNT_NOACL;
841 break;
842 case Opt_noacl:
843 mnt->flags |= NFS_MOUNT_NOACL;
844 break;
845 case Opt_rdirplus:
846 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
847 break;
848 case Opt_nordirplus:
849 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
850 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400851 case Opt_sharecache:
852 mnt->flags &= ~NFS_MOUNT_UNSHARED;
853 break;
854 case Opt_nosharecache:
855 mnt->flags |= NFS_MOUNT_UNSHARED;
856 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400857
858 case Opt_port:
859 if (match_int(args, &option))
860 return 0;
861 if (option < 0 || option > 65535)
862 return 0;
Chuck Leverf22d6d72008-03-14 14:10:22 -0400863 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400864 break;
865 case Opt_rsize:
866 if (match_int(args, &mnt->rsize))
867 return 0;
868 break;
869 case Opt_wsize:
870 if (match_int(args, &mnt->wsize))
871 return 0;
872 break;
873 case Opt_bsize:
874 if (match_int(args, &option))
875 return 0;
876 if (option < 0)
877 return 0;
878 mnt->bsize = option;
879 break;
880 case Opt_timeo:
881 if (match_int(args, &mnt->timeo))
882 return 0;
883 break;
884 case Opt_retrans:
885 if (match_int(args, &mnt->retrans))
886 return 0;
887 break;
888 case Opt_acregmin:
889 if (match_int(args, &mnt->acregmin))
890 return 0;
891 break;
892 case Opt_acregmax:
893 if (match_int(args, &mnt->acregmax))
894 return 0;
895 break;
896 case Opt_acdirmin:
897 if (match_int(args, &mnt->acdirmin))
898 return 0;
899 break;
900 case Opt_acdirmax:
901 if (match_int(args, &mnt->acdirmax))
902 return 0;
903 break;
904 case Opt_actimeo:
905 if (match_int(args, &option))
906 return 0;
907 if (option < 0)
908 return 0;
909 mnt->acregmin =
910 mnt->acregmax =
911 mnt->acdirmin =
912 mnt->acdirmax = option;
913 break;
914 case Opt_namelen:
915 if (match_int(args, &mnt->namlen))
916 return 0;
917 break;
918 case Opt_mountport:
919 if (match_int(args, &option))
920 return 0;
921 if (option < 0 || option > 65535)
922 return 0;
923 mnt->mount_server.port = option;
924 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400925 case Opt_mountvers:
926 if (match_int(args, &option))
927 return 0;
928 if (option < 0)
929 return 0;
930 mnt->mount_server.version = option;
931 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400932 case Opt_nfsvers:
933 if (match_int(args, &option))
934 return 0;
935 switch (option) {
936 case 2:
937 mnt->flags &= ~NFS_MOUNT_VER3;
938 break;
939 case 3:
940 mnt->flags |= NFS_MOUNT_VER3;
941 break;
942 default:
943 goto out_unrec_vers;
944 }
945 break;
946
947 case Opt_sec:
948 string = match_strdup(args);
949 if (string == NULL)
950 goto out_nomem;
951 token = match_token(string, nfs_secflavor_tokens, args);
952 kfree(string);
953
954 /*
955 * The flags setting is for v2/v3. The flavor_len
956 * setting is for v4. v2/v3 also need to know the
957 * difference between NULL and UNIX.
958 */
959 switch (token) {
960 case Opt_sec_none:
961 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
962 mnt->auth_flavor_len = 0;
963 mnt->auth_flavors[0] = RPC_AUTH_NULL;
964 break;
965 case Opt_sec_sys:
966 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
967 mnt->auth_flavor_len = 0;
968 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
969 break;
970 case Opt_sec_krb5:
971 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
972 mnt->auth_flavor_len = 1;
973 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
974 break;
975 case Opt_sec_krb5i:
976 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
977 mnt->auth_flavor_len = 1;
978 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
979 break;
980 case Opt_sec_krb5p:
981 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
982 mnt->auth_flavor_len = 1;
983 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
984 break;
985 case Opt_sec_lkey:
986 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
987 mnt->auth_flavor_len = 1;
988 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
989 break;
990 case Opt_sec_lkeyi:
991 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
992 mnt->auth_flavor_len = 1;
993 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
994 break;
995 case Opt_sec_lkeyp:
996 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
997 mnt->auth_flavor_len = 1;
998 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
999 break;
1000 case Opt_sec_spkm:
1001 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1002 mnt->auth_flavor_len = 1;
1003 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1004 break;
1005 case Opt_sec_spkmi:
1006 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1007 mnt->auth_flavor_len = 1;
1008 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1009 break;
1010 case Opt_sec_spkmp:
1011 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1012 mnt->auth_flavor_len = 1;
1013 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1014 break;
1015 default:
1016 goto out_unrec_sec;
1017 }
1018 break;
1019 case Opt_proto:
1020 string = match_strdup(args);
1021 if (string == NULL)
1022 goto out_nomem;
1023 token = match_token(string,
1024 nfs_xprt_protocol_tokens, args);
1025 kfree(string);
1026
1027 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001028 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001029 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001030 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001031 mnt->timeo = 7;
1032 mnt->retrans = 5;
1033 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001034 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001035 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001036 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001037 mnt->timeo = 600;
1038 mnt->retrans = 2;
1039 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001040 case Opt_xprt_rdma:
1041 /* vector side protocols to TCP */
1042 mnt->flags |= NFS_MOUNT_TCP;
1043 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1044 mnt->timeo = 600;
1045 mnt->retrans = 2;
1046 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001047 default:
1048 goto out_unrec_xprt;
1049 }
1050 break;
1051 case Opt_mountproto:
1052 string = match_strdup(args);
1053 if (string == NULL)
1054 goto out_nomem;
1055 token = match_token(string,
1056 nfs_xprt_protocol_tokens, args);
1057 kfree(string);
1058
1059 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001060 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001061 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001062 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001063 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001064 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001065 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001066 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001067 default:
1068 goto out_unrec_xprt;
1069 }
1070 break;
1071 case Opt_addr:
1072 string = match_strdup(args);
1073 if (string == NULL)
1074 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001075 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001076 &mnt->nfs_server.address,
1077 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001078 kfree(string);
1079 break;
1080 case Opt_clientaddr:
1081 string = match_strdup(args);
1082 if (string == NULL)
1083 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001084 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001085 mnt->client_address = string;
1086 break;
Chuck Lever33832032007-12-10 14:59:13 -05001087 case Opt_mounthost:
1088 string = match_strdup(args);
1089 if (string == NULL)
1090 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001091 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001092 mnt->mount_server.hostname = string;
1093 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001094 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001095 string = match_strdup(args);
1096 if (string == NULL)
1097 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001098 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001099 &mnt->mount_server.address,
1100 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 kfree(string);
1102 break;
1103
1104 case Opt_userspace:
1105 case Opt_deprecated:
1106 break;
1107
1108 default:
1109 goto out_unknown;
1110 }
1111 }
1112
Chuck Leverf22d6d72008-03-14 14:10:22 -04001113 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1114 mnt->nfs_server.port);
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001115
Chuck Leverbf0fd762007-07-01 12:13:44 -04001116 return 1;
1117
1118out_nomem:
1119 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1120 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001121out_security_failure:
1122 free_secdata(secdata);
1123 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1124 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001125out_unrec_vers:
1126 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1127 return 0;
1128
1129out_unrec_xprt:
1130 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1131 return 0;
1132
1133out_unrec_sec:
1134 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1135 return 0;
1136
1137out_unknown:
1138 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1139 return 0;
1140}
1141
1142/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001143 * Use the remote server's MOUNT service to request the NFS file handle
1144 * corresponding to the provided path.
1145 */
1146static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1147 struct nfs_fh *root_fh)
1148{
Chuck Lever4c568012007-12-10 14:59:28 -05001149 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001150 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001151 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001152
1153 if (args->mount_server.version == 0) {
1154 if (args->flags & NFS_MOUNT_VER3)
1155 args->mount_server.version = NFS_MNT3_VERSION;
1156 else
1157 args->mount_server.version = NFS_MNT_VERSION;
1158 }
1159
Chuck Lever33832032007-12-10 14:59:13 -05001160 if (args->mount_server.hostname)
1161 hostname = args->mount_server.hostname;
1162 else
1163 hostname = args->nfs_server.hostname;
1164
Chuck Lever0076d7b2007-07-01 12:13:49 -04001165 /*
1166 * Construct the mount server's address.
1167 */
Chuck Lever4c568012007-12-10 14:59:28 -05001168 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1169 memcpy(sap, &args->nfs_server.address,
1170 args->nfs_server.addrlen);
1171 args->mount_server.addrlen = args->nfs_server.addrlen;
1172 }
1173
James Lentiniaad70002007-09-24 17:32:49 -04001174 /*
1175 * autobind will be used if mount_server.port == 0
1176 */
Chuck Lever4c568012007-12-10 14:59:28 -05001177 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001178
1179 /*
1180 * Now ask the mount server to map our export path
1181 * to a file handle.
1182 */
Chuck Lever4c568012007-12-10 14:59:28 -05001183 status = nfs_mount(sap,
1184 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001185 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001186 args->nfs_server.export_path,
1187 args->mount_server.version,
1188 args->mount_server.protocol,
1189 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001190 if (status == 0)
1191 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001192
Chuck Lever33832032007-12-10 14:59:13 -05001193 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1194 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001195 return status;
1196}
1197
1198/*
David Howells54ceac42006-08-22 20:06:13 -04001199 * Validate the NFS2/NFS3 mount data
1200 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001201 *
1202 * For option strings, user space handles the following behaviors:
1203 *
1204 * + DNS: mapping server host name to IP address ("addr=" option)
1205 *
1206 * + failure mode: how to behave if a mount request can't be handled
1207 * immediately ("fg/bg" option)
1208 *
1209 * + retry: how often to retry a mount request ("retry=" option)
1210 *
1211 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1212 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001213 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001214static int nfs_validate_mount_data(void *options,
1215 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001216 struct nfs_fh *mntfh,
1217 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001218{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001219 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001220
Russell Kingf16c9602007-11-16 22:13:24 +00001221 memset(args, 0, sizeof(*args));
1222
Chuck Lever5df36e72007-07-01 12:12:56 -04001223 if (data == NULL)
1224 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001225
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001226 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1227 args->rsize = NFS_MAX_FILE_IO_SIZE;
1228 args->wsize = NFS_MAX_FILE_IO_SIZE;
1229 args->timeo = 600;
1230 args->retrans = 2;
1231 args->acregmin = 3;
1232 args->acregmax = 60;
1233 args->acdirmin = 30;
1234 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001235 args->mount_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001236 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001237 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001238 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001239
David Howellsf7b422b2006-06-09 09:34:33 -04001240 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001241 case 1:
1242 data->namlen = 0;
1243 case 2:
1244 data->bsize = 0;
1245 case 3:
1246 if (data->flags & NFS_MOUNT_VER3)
1247 goto out_no_v3;
1248 data->root.size = NFS2_FHSIZE;
1249 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1250 case 4:
1251 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1252 goto out_no_sec;
1253 case 5:
1254 memset(data->context, 0, sizeof(data->context));
1255 case 6:
1256 if (data->flags & NFS_MOUNT_VER3)
1257 mntfh->size = data->root.size;
1258 else
1259 mntfh->size = NFS2_FHSIZE;
1260
1261 if (mntfh->size > sizeof(mntfh->data))
1262 goto out_invalid_fh;
1263
1264 memcpy(mntfh->data, data->root.data, mntfh->size);
1265 if (mntfh->size < sizeof(mntfh->data))
1266 memset(mntfh->data + mntfh->size, 0,
1267 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001268
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001269 /*
1270 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1271 * can deal with.
1272 */
1273 args->flags = data->flags;
1274 args->rsize = data->rsize;
1275 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001276 args->timeo = data->timeo;
1277 args->retrans = data->retrans;
1278 args->acregmin = data->acregmin;
1279 args->acregmax = data->acregmax;
1280 args->acdirmin = data->acdirmin;
1281 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001282
1283 memcpy(&args->nfs_server.address, &data->addr,
1284 sizeof(data->addr));
1285 args->nfs_server.addrlen = sizeof(data->addr);
1286 if (!nfs_verify_server_address((struct sockaddr *)
1287 &args->nfs_server.address))
1288 goto out_no_address;
1289
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001290 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001291 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001292 /* N.B. caller will free nfs_server.hostname in all cases */
1293 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1294 args->namlen = data->namlen;
1295 args->bsize = data->bsize;
1296 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001297 if (!args->nfs_server.hostname)
1298 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001299
1300 /*
1301 * The legacy version 6 binary mount data from userspace has a
1302 * field used only to transport selinux information into the
1303 * the kernel. To continue to support that functionality we
1304 * have a touch of selinux knowledge here in the NFS code. The
1305 * userspace code converted context=blah to just blah so we are
1306 * converting back to the full string selinux understands.
1307 */
1308 if (data->context[0]){
1309#ifdef CONFIG_SECURITY_SELINUX
1310 int rc;
1311 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1312 if (!opts_str)
1313 return -ENOMEM;
1314 strcpy(opts_str, "context=");
1315 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1316 strcat(opts_str, &data->context[0]);
1317 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1318 kfree(opts_str);
1319 if (rc)
1320 return rc;
1321#else
1322 return -EINVAL;
1323#endif
1324 }
1325
Chuck Lever5df36e72007-07-01 12:12:56 -04001326 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001327 default: {
1328 unsigned int len;
1329 char *c;
1330 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001331
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001332 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001333 return -EINVAL;
1334
Chuck Lever6e88e062007-09-24 15:39:50 -04001335 if (!nfs_verify_server_address((struct sockaddr *)
1336 &args->nfs_server.address))
1337 goto out_no_address;
1338
Chuck Lever136d5582007-07-01 12:13:54 -04001339 c = strchr(dev_name, ':');
1340 if (c == NULL)
1341 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001342 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001343 /* N.B. caller will free nfs_server.hostname in all cases */
1344 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001345 if (!args->nfs_server.hostname)
1346 goto out_nomem;
Chuck Lever136d5582007-07-01 12:13:54 -04001347
1348 c++;
1349 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001350 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001351 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001352
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001353 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001354 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001355 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001356
Chuck Lever136d5582007-07-01 12:13:54 -04001357 break;
1358 }
David Howellsf7b422b2006-06-09 09:34:33 -04001359 }
David Howells54ceac42006-08-22 20:06:13 -04001360
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001361 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1362 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001363
David Howellsf7b422b2006-06-09 09:34:33 -04001364#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001365 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001366 goto out_v3_not_compiled;
1367#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001368
David Howells54ceac42006-08-22 20:06:13 -04001369 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001370
1371out_no_data:
1372 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1373 return -EINVAL;
1374
1375out_no_v3:
1376 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1377 data->version);
1378 return -EINVAL;
1379
1380out_no_sec:
1381 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1382 return -EINVAL;
1383
Chuck Lever5df36e72007-07-01 12:12:56 -04001384#ifndef CONFIG_NFS_V3
1385out_v3_not_compiled:
1386 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1387 return -EPROTONOSUPPORT;
1388#endif /* !CONFIG_NFS_V3 */
1389
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001390out_nomem:
1391 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1392 return -ENOMEM;
1393
Chuck Lever5df36e72007-07-01 12:12:56 -04001394out_no_address:
1395 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1396 return -EINVAL;
1397
1398out_invalid_fh:
1399 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1400 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001401}
1402
1403/*
1404 * Initialise the common bits of the superblock
1405 */
1406static inline void nfs_initialise_sb(struct super_block *sb)
1407{
1408 struct nfs_server *server = NFS_SB(sb);
1409
1410 sb->s_magic = NFS_SUPER_MAGIC;
1411
1412 /* We probably want something more informative here */
1413 snprintf(sb->s_id, sizeof(sb->s_id),
1414 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1415
1416 if (sb->s_blocksize == 0)
1417 sb->s_blocksize = nfs_block_bits(server->wsize,
1418 &sb->s_blocksize_bits);
1419
1420 if (server->flags & NFS_MOUNT_NOAC)
1421 sb->s_flags |= MS_SYNCHRONOUS;
1422
1423 nfs_super_set_maxbytes(sb, server->maxfilesize);
1424}
1425
1426/*
1427 * Finish setting up an NFS2/3 superblock
1428 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001429static void nfs_fill_super(struct super_block *sb,
1430 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001431{
1432 struct nfs_server *server = NFS_SB(sb);
1433
1434 sb->s_blocksize_bits = 0;
1435 sb->s_blocksize = 0;
1436 if (data->bsize)
1437 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1438
1439 if (server->flags & NFS_MOUNT_VER3) {
1440 /* The VFS shouldn't apply the umask to mode bits. We will do
1441 * so ourselves when necessary.
1442 */
1443 sb->s_flags |= MS_POSIXACL;
1444 sb->s_time_gran = 1;
1445 }
1446
1447 sb->s_op = &nfs_sops;
1448 nfs_initialise_sb(sb);
1449}
1450
1451/*
1452 * Finish setting up a cloned NFS2/3 superblock
1453 */
1454static void nfs_clone_super(struct super_block *sb,
1455 const struct super_block *old_sb)
1456{
1457 struct nfs_server *server = NFS_SB(sb);
1458
1459 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1460 sb->s_blocksize = old_sb->s_blocksize;
1461 sb->s_maxbytes = old_sb->s_maxbytes;
1462
1463 if (server->flags & NFS_MOUNT_VER3) {
1464 /* The VFS shouldn't apply the umask to mode bits. We will do
1465 * so ourselves when necessary.
1466 */
1467 sb->s_flags |= MS_POSIXACL;
1468 sb->s_time_gran = 1;
1469 }
1470
1471 sb->s_op = old_sb->s_op;
1472 nfs_initialise_sb(sb);
1473}
1474
Trond Myklebust275a5d22007-05-16 16:53:28 -04001475#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1476
1477static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1478{
1479 const struct nfs_server *a = s->s_fs_info;
1480 const struct rpc_clnt *clnt_a = a->client;
1481 const struct rpc_clnt *clnt_b = b->client;
1482
1483 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1484 goto Ebusy;
1485 if (a->nfs_client != b->nfs_client)
1486 goto Ebusy;
1487 if (a->flags != b->flags)
1488 goto Ebusy;
1489 if (a->wsize != b->wsize)
1490 goto Ebusy;
1491 if (a->rsize != b->rsize)
1492 goto Ebusy;
1493 if (a->acregmin != b->acregmin)
1494 goto Ebusy;
1495 if (a->acregmax != b->acregmax)
1496 goto Ebusy;
1497 if (a->acdirmin != b->acdirmin)
1498 goto Ebusy;
1499 if (a->acdirmax != b->acdirmax)
1500 goto Ebusy;
1501 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1502 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001503 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001504Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001505 return 0;
1506}
1507
1508struct nfs_sb_mountdata {
1509 struct nfs_server *server;
1510 int mntflags;
1511};
1512
1513static int nfs_set_super(struct super_block *s, void *data)
1514{
1515 struct nfs_sb_mountdata *sb_mntdata = data;
1516 struct nfs_server *server = sb_mntdata->server;
1517 int ret;
1518
1519 s->s_flags = sb_mntdata->mntflags;
1520 s->s_fs_info = server;
1521 ret = set_anon_super(s, server);
1522 if (ret == 0)
1523 server->s_dev = s->s_dev;
1524 return ret;
1525}
1526
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001527static int nfs_compare_super_address(struct nfs_server *server1,
1528 struct nfs_server *server2)
1529{
1530 struct sockaddr *sap1, *sap2;
1531
1532 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1533 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1534
1535 if (sap1->sa_family != sap2->sa_family)
1536 return 0;
1537
1538 switch (sap1->sa_family) {
1539 case AF_INET: {
1540 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1541 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1542 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1543 return 0;
1544 if (sin1->sin_port != sin2->sin_port)
1545 return 0;
1546 break;
1547 }
1548 case AF_INET6: {
1549 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1550 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1551 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1552 return 0;
1553 if (sin1->sin6_port != sin2->sin6_port)
1554 return 0;
1555 break;
1556 }
1557 default:
1558 return 0;
1559 }
1560
1561 return 1;
1562}
1563
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001564static int nfs_compare_super(struct super_block *sb, void *data)
1565{
1566 struct nfs_sb_mountdata *sb_mntdata = data;
1567 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1568 int mntflags = sb_mntdata->mntflags;
1569
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001570 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001571 return 0;
1572 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1573 if (old->flags & NFS_MOUNT_UNSHARED)
1574 return 0;
1575 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1576 return 0;
1577 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001578}
1579
David Howells54ceac42006-08-22 20:06:13 -04001580static int nfs_get_sb(struct file_system_type *fs_type,
1581 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1582{
1583 struct nfs_server *server = NULL;
1584 struct super_block *s;
1585 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001586 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001587 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001588 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001589 struct nfs_sb_mountdata sb_mntdata = {
1590 .mntflags = flags,
1591 };
David Howells54ceac42006-08-22 20:06:13 -04001592 int error;
1593
Eric Parisf9c3a382008-03-05 14:20:18 -05001594 security_init_mnt_opts(&data.lsm_opts);
1595
David Howells54ceac42006-08-22 20:06:13 -04001596 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001597 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001598 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001599 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001600
1601 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001602 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001603 if (IS_ERR(server)) {
1604 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001605 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001606 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001607 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001608
Trond Myklebust75180df2007-05-16 16:53:28 -04001609 if (server->flags & NFS_MOUNT_UNSHARED)
1610 compare_super = NULL;
1611
David Howells54ceac42006-08-22 20:06:13 -04001612 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001613 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001614 if (IS_ERR(s)) {
1615 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001616 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001617 }
1618
David Howells54ceac42006-08-22 20:06:13 -04001619 if (s->s_fs_info != server) {
1620 nfs_free_server(server);
1621 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001622 }
David Howells54ceac42006-08-22 20:06:13 -04001623
1624 if (!s->s_root) {
1625 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001626 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001627 }
1628
1629 mntroot = nfs_get_root(s, &mntfh);
1630 if (IS_ERR(mntroot)) {
1631 error = PTR_ERR(mntroot);
1632 goto error_splat_super;
1633 }
1634
Eric Parisf9c3a382008-03-05 14:20:18 -05001635 error = security_sb_set_mnt_opts(s, &data.lsm_opts);
1636 if (error)
1637 goto error_splat_root;
1638
David Howellsf7b422b2006-06-09 09:34:33 -04001639 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001640 mnt->mnt_sb = s;
1641 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001642 error = 0;
1643
1644out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001645 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001646 kfree(data.mount_server.hostname);
Eric Parisf9c3a382008-03-05 14:20:18 -05001647 security_free_mnt_opts(&data.lsm_opts);
Chuck Lever06559602007-07-01 12:12:35 -04001648 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001649
David Howells54ceac42006-08-22 20:06:13 -04001650out_err_nosb:
1651 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001652 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001653
Eric Parisf9c3a382008-03-05 14:20:18 -05001654error_splat_root:
1655 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04001656error_splat_super:
1657 up_write(&s->s_umount);
1658 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001659 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001660}
1661
David Howells54ceac42006-08-22 20:06:13 -04001662/*
1663 * Destroy an NFS2/3 superblock
1664 */
David Howellsf7b422b2006-06-09 09:34:33 -04001665static void nfs_kill_super(struct super_block *s)
1666{
1667 struct nfs_server *server = NFS_SB(s);
1668
1669 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001670 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001671}
1672
David Howells54ceac42006-08-22 20:06:13 -04001673/*
1674 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1675 */
1676static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1677 const char *dev_name, void *raw_data,
1678 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001679{
1680 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001681 struct super_block *s;
1682 struct nfs_server *server;
1683 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001684 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001685 struct nfs_sb_mountdata sb_mntdata = {
1686 .mntflags = flags,
1687 };
David Howells54ceac42006-08-22 20:06:13 -04001688 int error;
1689
1690 dprintk("--> nfs_xdev_get_sb()\n");
1691
1692 /* create a new volume representation */
1693 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1694 if (IS_ERR(server)) {
1695 error = PTR_ERR(server);
1696 goto out_err_noserver;
1697 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001698 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001699
Trond Myklebust75180df2007-05-16 16:53:28 -04001700 if (server->flags & NFS_MOUNT_UNSHARED)
1701 compare_super = NULL;
1702
David Howells54ceac42006-08-22 20:06:13 -04001703 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001704 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001705 if (IS_ERR(s)) {
1706 error = PTR_ERR(s);
1707 goto out_err_nosb;
1708 }
1709
1710 if (s->s_fs_info != server) {
1711 nfs_free_server(server);
1712 server = NULL;
1713 }
1714
1715 if (!s->s_root) {
1716 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001717 nfs_clone_super(s, data->sb);
1718 }
1719
1720 mntroot = nfs_get_root(s, data->fh);
1721 if (IS_ERR(mntroot)) {
1722 error = PTR_ERR(mntroot);
1723 goto error_splat_super;
1724 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001725 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001726 dput(mntroot);
1727 error = -ESTALE;
1728 goto error_splat_super;
1729 }
David Howells54ceac42006-08-22 20:06:13 -04001730
1731 s->s_flags |= MS_ACTIVE;
1732 mnt->mnt_sb = s;
1733 mnt->mnt_root = mntroot;
1734
Eric Parisf9c3a382008-03-05 14:20:18 -05001735 /* clone any lsm security options from the parent to the new sb */
1736 security_sb_clone_mnt_opts(data->sb, s);
1737
David Howells54ceac42006-08-22 20:06:13 -04001738 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1739 return 0;
1740
1741out_err_nosb:
1742 nfs_free_server(server);
1743out_err_noserver:
1744 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1745 return error;
1746
1747error_splat_super:
1748 up_write(&s->s_umount);
1749 deactivate_super(s);
1750 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1751 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001752}
1753
1754#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001755
1756/*
1757 * Finish setting up a cloned NFS4 superblock
1758 */
1759static void nfs4_clone_super(struct super_block *sb,
1760 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001761{
David Howells54ceac42006-08-22 20:06:13 -04001762 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1763 sb->s_blocksize = old_sb->s_blocksize;
1764 sb->s_maxbytes = old_sb->s_maxbytes;
1765 sb->s_time_gran = 1;
1766 sb->s_op = old_sb->s_op;
1767 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001768}
1769
1770/*
1771 * Set up an NFS4 superblock
1772 */
David Howells54ceac42006-08-22 20:06:13 -04001773static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001774{
David Howellsf7b422b2006-06-09 09:34:33 -04001775 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001776 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001777 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001778}
1779
David Howells54ceac42006-08-22 20:06:13 -04001780/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001781 * Validate NFSv4 mount options
1782 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001783static int nfs4_validate_mount_data(void *options,
1784 struct nfs_parsed_mount_data *args,
1785 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001786{
Chuck Lever4c568012007-12-10 14:59:28 -05001787 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001788 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001789 char *c;
1790
Russell Kingf16c9602007-11-16 22:13:24 +00001791 memset(args, 0, sizeof(*args));
1792
Chuck Leverf0768eb2007-07-01 12:13:01 -04001793 if (data == NULL)
1794 goto out_no_data;
1795
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001796 args->rsize = NFS_MAX_FILE_IO_SIZE;
1797 args->wsize = NFS_MAX_FILE_IO_SIZE;
1798 args->timeo = 600;
1799 args->retrans = 2;
1800 args->acregmin = 3;
1801 args->acregmax = 60;
1802 args->acdirmin = 30;
1803 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001804 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001805 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001806
Chuck Leverf0768eb2007-07-01 12:13:01 -04001807 switch (data->version) {
1808 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05001809 ap = (struct sockaddr_in *)&args->nfs_server.address;
1810 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001811 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05001812 if (data->host_addrlen == 0)
1813 goto out_no_address;
1814 args->nfs_server.addrlen = data->host_addrlen;
1815 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001816 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001817 if (!nfs_verify_server_address((struct sockaddr *)
1818 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001819 goto out_no_address;
1820
1821 switch (data->auth_flavourlen) {
1822 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001823 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001824 break;
1825 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001826 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001827 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001828 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001829 return -EFAULT;
1830 break;
1831 default:
1832 goto out_inval_auth;
1833 }
1834
1835 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1836 if (IS_ERR(c))
1837 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001838 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001839
1840 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1841 if (IS_ERR(c))
1842 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001843 args->nfs_server.export_path = c;
1844 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001845
1846 c = strndup_user(data->client_addr.data, 16);
1847 if (IS_ERR(c))
1848 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001849 args->client_address = c;
1850
1851 /*
1852 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1853 * can deal with.
1854 */
1855
1856 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1857 args->rsize = data->rsize;
1858 args->wsize = data->wsize;
1859 args->timeo = data->timeo;
1860 args->retrans = data->retrans;
1861 args->acregmin = data->acregmin;
1862 args->acregmax = data->acregmax;
1863 args->acdirmin = data->acdirmin;
1864 args->acdirmax = data->acdirmax;
1865 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001866
1867 break;
Chuck Lever80071222007-07-01 12:13:59 -04001868 default: {
1869 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001870
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001871 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001872 return -EINVAL;
1873
1874 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001875 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001876 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001877
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001878 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001879 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001880 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001881 break;
1882 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001883 break;
1884 default:
1885 goto out_inval_auth;
1886 }
1887
1888 /*
Chuck Lever80071222007-07-01 12:13:59 -04001889 * Split "dev_name" into "hostname:mntpath".
1890 */
1891 c = strchr(dev_name, ':');
1892 if (c == NULL)
1893 return -EINVAL;
1894 /* while calculating len, pretend ':' is '\0' */
1895 len = c - dev_name;
1896 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001897 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001898 /* N.B. caller will free nfs_server.hostname in all cases */
1899 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001900 if (!args->nfs_server.hostname)
1901 goto out_nomem;
Chuck Lever80071222007-07-01 12:13:59 -04001902
1903 c++; /* step over the ':' */
1904 len = strlen(c);
1905 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001906 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001907 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001908 if (!args->nfs_server.export_path)
1909 goto out_nomem;
Chuck Lever80071222007-07-01 12:13:59 -04001910
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001911 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001912
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001913 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001914 goto out_no_client_address;
1915
Chuck Lever80071222007-07-01 12:13:59 -04001916 break;
1917 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001918 }
1919
1920 return 0;
1921
1922out_no_data:
1923 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1924 return -EINVAL;
1925
1926out_inval_auth:
1927 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1928 data->auth_flavourlen);
1929 return -EINVAL;
1930
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001931out_nomem:
1932 dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n");
1933 return -ENOMEM;
1934
Chuck Leverf0768eb2007-07-01 12:13:01 -04001935out_no_address:
1936 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1937 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001938
1939out_no_client_address:
1940 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1941 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001942}
1943
1944/*
David Howells54ceac42006-08-22 20:06:13 -04001945 * Get the superblock for an NFS4 mountpoint
1946 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001947static int nfs4_get_sb(struct file_system_type *fs_type,
1948 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001949{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001950 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001951 struct super_block *s;
1952 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001953 struct nfs_fh mntfh;
1954 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001955 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001956 struct nfs_sb_mountdata sb_mntdata = {
1957 .mntflags = flags,
1958 };
David Howells54ceac42006-08-22 20:06:13 -04001959 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001960
Eric Parisf9c3a382008-03-05 14:20:18 -05001961 security_init_mnt_opts(&data.lsm_opts);
1962
Chuck Leverf0768eb2007-07-01 12:13:01 -04001963 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001964 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001965 if (error < 0)
1966 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001967
David Howells54ceac42006-08-22 20:06:13 -04001968 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001969 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001970 if (IS_ERR(server)) {
1971 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001972 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001973 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001974 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001975
Trond Myklebust75180df2007-05-16 16:53:28 -04001976 if (server->flags & NFS4_MOUNT_UNSHARED)
1977 compare_super = NULL;
1978
David Howells54ceac42006-08-22 20:06:13 -04001979 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001980 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001981 if (IS_ERR(s)) {
1982 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001983 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001984 }
1985
Trond Myklebust5dd31772006-08-24 01:03:05 -04001986 if (s->s_fs_info != server) {
1987 nfs_free_server(server);
1988 server = NULL;
1989 }
1990
David Howells54ceac42006-08-22 20:06:13 -04001991 if (!s->s_root) {
1992 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001993 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001994 }
David Howellsf7b422b2006-06-09 09:34:33 -04001995
David Howells54ceac42006-08-22 20:06:13 -04001996 mntroot = nfs4_get_root(s, &mntfh);
1997 if (IS_ERR(mntroot)) {
1998 error = PTR_ERR(mntroot);
1999 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002000 }
David Howells54ceac42006-08-22 20:06:13 -04002001
David Howellsf7b422b2006-06-09 09:34:33 -04002002 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002003 mnt->mnt_sb = s;
2004 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002005 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002006
Chuck Lever29eb9812007-07-01 12:12:30 -04002007out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002008 kfree(data.client_address);
2009 kfree(data.nfs_server.export_path);
2010 kfree(data.nfs_server.hostname);
Eric Parisf9c3a382008-03-05 14:20:18 -05002011 security_free_mnt_opts(&data.lsm_opts);
Trond Myklebust816724e2006-06-24 08:41:41 -04002012 return error;
David Howells54ceac42006-08-22 20:06:13 -04002013
Chuck Lever29eb9812007-07-01 12:12:30 -04002014out_free:
2015 nfs_free_server(server);
2016 goto out;
2017
David Howells54ceac42006-08-22 20:06:13 -04002018error_splat_super:
2019 up_write(&s->s_umount);
2020 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002021 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002022}
2023
2024static void nfs4_kill_super(struct super_block *sb)
2025{
2026 struct nfs_server *server = NFS_SB(sb);
2027
2028 nfs_return_all_delegations(sb);
2029 kill_anon_super(sb);
2030
2031 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002032 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002033}
2034
2035/*
David Howells54ceac42006-08-22 20:06:13 -04002036 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002037 */
David Howells54ceac42006-08-22 20:06:13 -04002038static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2039 const char *dev_name, void *raw_data,
2040 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002041{
2042 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002043 struct super_block *s;
2044 struct nfs_server *server;
2045 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002046 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002047 struct nfs_sb_mountdata sb_mntdata = {
2048 .mntflags = flags,
2049 };
David Howells54ceac42006-08-22 20:06:13 -04002050 int error;
2051
2052 dprintk("--> nfs4_xdev_get_sb()\n");
2053
2054 /* create a new volume representation */
2055 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2056 if (IS_ERR(server)) {
2057 error = PTR_ERR(server);
2058 goto out_err_noserver;
2059 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002060 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002061
Trond Myklebust75180df2007-05-16 16:53:28 -04002062 if (server->flags & NFS4_MOUNT_UNSHARED)
2063 compare_super = NULL;
2064
David Howells54ceac42006-08-22 20:06:13 -04002065 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002066 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002067 if (IS_ERR(s)) {
2068 error = PTR_ERR(s);
2069 goto out_err_nosb;
2070 }
2071
2072 if (s->s_fs_info != server) {
2073 nfs_free_server(server);
2074 server = NULL;
2075 }
2076
2077 if (!s->s_root) {
2078 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002079 nfs4_clone_super(s, data->sb);
2080 }
2081
2082 mntroot = nfs4_get_root(s, data->fh);
2083 if (IS_ERR(mntroot)) {
2084 error = PTR_ERR(mntroot);
2085 goto error_splat_super;
2086 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002087 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2088 dput(mntroot);
2089 error = -ESTALE;
2090 goto error_splat_super;
2091 }
David Howells54ceac42006-08-22 20:06:13 -04002092
2093 s->s_flags |= MS_ACTIVE;
2094 mnt->mnt_sb = s;
2095 mnt->mnt_root = mntroot;
2096
2097 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2098 return 0;
2099
2100out_err_nosb:
2101 nfs_free_server(server);
2102out_err_noserver:
2103 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2104 return error;
2105
2106error_splat_super:
2107 up_write(&s->s_umount);
2108 deactivate_super(s);
2109 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2110 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002111}
2112
David Howells54ceac42006-08-22 20:06:13 -04002113/*
2114 * Create an NFS4 server record on referral traversal
2115 */
2116static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2117 const char *dev_name, void *raw_data,
2118 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002119{
2120 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002121 struct super_block *s;
2122 struct nfs_server *server;
2123 struct dentry *mntroot;
2124 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002125 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002126 struct nfs_sb_mountdata sb_mntdata = {
2127 .mntflags = flags,
2128 };
David Howells54ceac42006-08-22 20:06:13 -04002129 int error;
2130
2131 dprintk("--> nfs4_referral_get_sb()\n");
2132
2133 /* create a new volume representation */
2134 server = nfs4_create_referral_server(data, &mntfh);
2135 if (IS_ERR(server)) {
2136 error = PTR_ERR(server);
2137 goto out_err_noserver;
2138 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002139 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002140
Trond Myklebust75180df2007-05-16 16:53:28 -04002141 if (server->flags & NFS4_MOUNT_UNSHARED)
2142 compare_super = NULL;
2143
David Howells54ceac42006-08-22 20:06:13 -04002144 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002145 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002146 if (IS_ERR(s)) {
2147 error = PTR_ERR(s);
2148 goto out_err_nosb;
2149 }
2150
2151 if (s->s_fs_info != server) {
2152 nfs_free_server(server);
2153 server = NULL;
2154 }
2155
2156 if (!s->s_root) {
2157 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002158 nfs4_fill_super(s);
2159 }
2160
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002161 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002162 if (IS_ERR(mntroot)) {
2163 error = PTR_ERR(mntroot);
2164 goto error_splat_super;
2165 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002166 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2167 dput(mntroot);
2168 error = -ESTALE;
2169 goto error_splat_super;
2170 }
David Howells54ceac42006-08-22 20:06:13 -04002171
2172 s->s_flags |= MS_ACTIVE;
2173 mnt->mnt_sb = s;
2174 mnt->mnt_root = mntroot;
2175
2176 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2177 return 0;
2178
2179out_err_nosb:
2180 nfs_free_server(server);
2181out_err_noserver:
2182 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2183 return error;
2184
2185error_splat_super:
2186 up_write(&s->s_umount);
2187 deactivate_super(s);
2188 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2189 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002190}
2191
David Howells54ceac42006-08-22 20:06:13 -04002192#endif /* CONFIG_NFS_V4 */