blob: f9219024f31aca9fd56962050823d4e46bdbbb37 [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
David Howellsf7b422b2006-06-09 09:34:33 -0400444/*
445 * Describe the mount options in force on this server representation
446 */
447static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
448{
David Howells509de812006-08-22 20:06:11 -0400449 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400450 int flag;
David Howells509de812006-08-22 20:06:11 -0400451 const char *str;
452 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400453 } nfs_info[] = {
454 { NFS_MOUNT_SOFT, ",soft", ",hard" },
David Howellsf7b422b2006-06-09 09:34:33 -0400455 { NFS_MOUNT_NOCTO, ",nocto", "" },
456 { NFS_MOUNT_NOAC, ",noac", "" },
457 { NFS_MOUNT_NONLM, ",nolock", "" },
458 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400459 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400460 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400461 { 0, NULL, NULL }
462 };
David Howells509de812006-08-22 20:06:11 -0400463 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400464 struct nfs_client *clp = nfss->nfs_client;
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 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400483 seq_printf(m, ",proto=%s",
484 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Trond Myklebust33170232007-12-20 16:03:59 -0500485 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
486 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400487 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400488}
489
490/*
491 * Describe the mount options on this VFS mountpoint
492 */
493static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
494{
495 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
496
497 nfs_show_mount_options(m, nfss, 0);
498
Chuck Lever5d8515c2007-12-10 14:57:16 -0500499 seq_printf(m, ",addr=%s",
500 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
501 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400502
503 return 0;
504}
505
506/*
507 * Present statistical information for this VFS mountpoint
508 */
509static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
510{
511 int i, cpu;
512 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
513 struct rpc_auth *auth = nfss->client->cl_auth;
514 struct nfs_iostats totals = { };
515
516 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
517
518 /*
519 * Display all mount option settings
520 */
521 seq_printf(m, "\n\topts:\t");
522 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
523 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
524 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
525 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
526 nfs_show_mount_options(m, nfss, 1);
527
528 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
529
530 seq_printf(m, "\n\tcaps:\t");
531 seq_printf(m, "caps=0x%x", nfss->caps);
532 seq_printf(m, ",wtmult=%d", nfss->wtmult);
533 seq_printf(m, ",dtsize=%d", nfss->dtsize);
534 seq_printf(m, ",bsize=%d", nfss->bsize);
535 seq_printf(m, ",namelen=%d", nfss->namelen);
536
537#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500538 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400539 seq_printf(m, "\n\tnfsv4:\t");
540 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
541 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
542 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
543 }
544#endif
545
546 /*
547 * Display security flavor in effect for this mount
548 */
549 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
550 if (auth->au_flavor)
551 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
552
553 /*
554 * Display superblock I/O counters
555 */
556 for_each_possible_cpu(cpu) {
557 struct nfs_iostats *stats;
558
559 preempt_disable();
560 stats = per_cpu_ptr(nfss->io_stats, cpu);
561
562 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
563 totals.events[i] += stats->events[i];
564 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
565 totals.bytes[i] += stats->bytes[i];
566
567 preempt_enable();
568 }
569
570 seq_printf(m, "\n\tevents:\t");
571 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
572 seq_printf(m, "%lu ", totals.events[i]);
573 seq_printf(m, "\n\tbytes:\t");
574 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
575 seq_printf(m, "%Lu ", totals.bytes[i]);
576 seq_printf(m, "\n");
577
578 rpc_print_iostats(m, nfss->client);
579
580 return 0;
581}
582
583/*
584 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400585 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400586 */
587static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
588{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400589 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
590 struct rpc_clnt *rpc;
591
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400592 if (!(flags & MNT_FORCE))
593 return;
594 /* -EIO all pending I/O */
595 rpc = server->client_acl;
596 if (!IS_ERR(rpc))
597 rpc_killall_tasks(rpc);
598 rpc = server->client;
599 if (!IS_ERR(rpc))
600 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400601}
602
603/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500604 * Set the port number in an address. Be agnostic about the address family.
605 */
606static void nfs_set_port(struct sockaddr *sap, unsigned short port)
607{
608 switch (sap->sa_family) {
609 case AF_INET: {
610 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
611 ap->sin_port = htons(port);
612 break;
613 }
614 case AF_INET6: {
615 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
616 ap->sin6_port = htons(port);
617 break;
618 }
619 }
620}
621
622/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500623 * Sanity-check a server address provided by the mount command.
624 *
625 * Address family must be initialized, and address must not be
626 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400627 */
628static int nfs_verify_server_address(struct sockaddr *addr)
629{
630 switch (addr->sa_family) {
631 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500632 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700633 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500634 }
635 case AF_INET6: {
636 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
637 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400638 }
639 }
640
641 return 0;
642}
643
644/*
Chuck Lever9412b922007-12-10 14:59:21 -0500645 * Parse string addresses passed in via a mount option,
646 * and construct a sockaddr based on the result.
647 *
648 * If address parsing fails, set the sockaddr's address
649 * family to AF_UNSPEC to force nfs_verify_server_address()
650 * to punt the mount.
651 */
652static void nfs_parse_server_address(char *value,
Chuck Lever4c568012007-12-10 14:59:28 -0500653 struct sockaddr *sap,
654 size_t *len)
Chuck Lever9412b922007-12-10 14:59:21 -0500655{
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500656 if (strchr(value, ':')) {
657 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
658 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
Chuck Lever9412b922007-12-10 14:59:21 -0500659
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500660 ap->sin6_family = AF_INET6;
661 *len = sizeof(*ap);
662 if (in6_pton(value, -1, addr, '\0', NULL))
663 return;
664 } else {
665 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
666 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
667
668 ap->sin_family = AF_INET;
669 *len = sizeof(*ap);
670 if (in4_pton(value, -1, addr, '\0', NULL))
671 return;
672 }
Chuck Lever9412b922007-12-10 14:59:21 -0500673
674 sap->sa_family = AF_UNSPEC;
Chuck Lever4c568012007-12-10 14:59:28 -0500675 *len = 0;
Chuck Lever9412b922007-12-10 14:59:21 -0500676}
677
678/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400679 * Error-check and convert a string of mount options from user space into
680 * a data structure
681 */
682static int nfs_parse_mount_options(char *raw,
683 struct nfs_parsed_mount_data *mnt)
684{
Eric Parisf9c3a382008-03-05 14:20:18 -0500685 char *p, *string, *secdata;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500686 unsigned short port = 0;
Eric Parisf9c3a382008-03-05 14:20:18 -0500687 int rc;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400688
689 if (!raw) {
690 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
691 return 1;
692 }
693 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
694
Eric Parisf9c3a382008-03-05 14:20:18 -0500695 secdata = alloc_secdata();
696 if (!secdata)
697 goto out_nomem;
698
699 rc = security_sb_copy_data(raw, secdata);
700 if (rc)
701 goto out_security_failure;
702
703 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
704 if (rc)
705 goto out_security_failure;
706
707 free_secdata(secdata);
708
Chuck Leverbf0fd762007-07-01 12:13:44 -0400709 while ((p = strsep(&raw, ",")) != NULL) {
710 substring_t args[MAX_OPT_ARGS];
711 int option, token;
712
713 if (!*p)
714 continue;
715
716 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
717
718 token = match_token(p, nfs_mount_option_tokens, args);
719 switch (token) {
720 case Opt_soft:
721 mnt->flags |= NFS_MOUNT_SOFT;
722 break;
723 case Opt_hard:
724 mnt->flags &= ~NFS_MOUNT_SOFT;
725 break;
726 case Opt_intr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400727 case Opt_nointr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400728 break;
729 case Opt_posix:
730 mnt->flags |= NFS_MOUNT_POSIX;
731 break;
732 case Opt_noposix:
733 mnt->flags &= ~NFS_MOUNT_POSIX;
734 break;
735 case Opt_cto:
736 mnt->flags &= ~NFS_MOUNT_NOCTO;
737 break;
738 case Opt_nocto:
739 mnt->flags |= NFS_MOUNT_NOCTO;
740 break;
741 case Opt_ac:
742 mnt->flags &= ~NFS_MOUNT_NOAC;
743 break;
744 case Opt_noac:
745 mnt->flags |= NFS_MOUNT_NOAC;
746 break;
747 case Opt_lock:
748 mnt->flags &= ~NFS_MOUNT_NONLM;
749 break;
750 case Opt_nolock:
751 mnt->flags |= NFS_MOUNT_NONLM;
752 break;
753 case Opt_v2:
754 mnt->flags &= ~NFS_MOUNT_VER3;
755 break;
756 case Opt_v3:
757 mnt->flags |= NFS_MOUNT_VER3;
758 break;
759 case Opt_udp:
760 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400761 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400762 mnt->timeo = 7;
763 mnt->retrans = 5;
764 break;
765 case Opt_tcp:
766 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400767 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400768 mnt->timeo = 600;
769 mnt->retrans = 2;
770 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400771 case Opt_rdma:
772 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
773 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
774 mnt->timeo = 600;
775 mnt->retrans = 2;
776 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400777 case Opt_acl:
778 mnt->flags &= ~NFS_MOUNT_NOACL;
779 break;
780 case Opt_noacl:
781 mnt->flags |= NFS_MOUNT_NOACL;
782 break;
783 case Opt_rdirplus:
784 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
785 break;
786 case Opt_nordirplus:
787 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
788 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400789 case Opt_sharecache:
790 mnt->flags &= ~NFS_MOUNT_UNSHARED;
791 break;
792 case Opt_nosharecache:
793 mnt->flags |= NFS_MOUNT_UNSHARED;
794 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400795
796 case Opt_port:
797 if (match_int(args, &option))
798 return 0;
799 if (option < 0 || option > 65535)
800 return 0;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500801 port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400802 break;
803 case Opt_rsize:
804 if (match_int(args, &mnt->rsize))
805 return 0;
806 break;
807 case Opt_wsize:
808 if (match_int(args, &mnt->wsize))
809 return 0;
810 break;
811 case Opt_bsize:
812 if (match_int(args, &option))
813 return 0;
814 if (option < 0)
815 return 0;
816 mnt->bsize = option;
817 break;
818 case Opt_timeo:
819 if (match_int(args, &mnt->timeo))
820 return 0;
821 break;
822 case Opt_retrans:
823 if (match_int(args, &mnt->retrans))
824 return 0;
825 break;
826 case Opt_acregmin:
827 if (match_int(args, &mnt->acregmin))
828 return 0;
829 break;
830 case Opt_acregmax:
831 if (match_int(args, &mnt->acregmax))
832 return 0;
833 break;
834 case Opt_acdirmin:
835 if (match_int(args, &mnt->acdirmin))
836 return 0;
837 break;
838 case Opt_acdirmax:
839 if (match_int(args, &mnt->acdirmax))
840 return 0;
841 break;
842 case Opt_actimeo:
843 if (match_int(args, &option))
844 return 0;
845 if (option < 0)
846 return 0;
847 mnt->acregmin =
848 mnt->acregmax =
849 mnt->acdirmin =
850 mnt->acdirmax = option;
851 break;
852 case Opt_namelen:
853 if (match_int(args, &mnt->namlen))
854 return 0;
855 break;
856 case Opt_mountport:
857 if (match_int(args, &option))
858 return 0;
859 if (option < 0 || option > 65535)
860 return 0;
861 mnt->mount_server.port = option;
862 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400863 case Opt_mountvers:
864 if (match_int(args, &option))
865 return 0;
866 if (option < 0)
867 return 0;
868 mnt->mount_server.version = option;
869 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400870 case Opt_nfsvers:
871 if (match_int(args, &option))
872 return 0;
873 switch (option) {
874 case 2:
875 mnt->flags &= ~NFS_MOUNT_VER3;
876 break;
877 case 3:
878 mnt->flags |= NFS_MOUNT_VER3;
879 break;
880 default:
881 goto out_unrec_vers;
882 }
883 break;
884
885 case Opt_sec:
886 string = match_strdup(args);
887 if (string == NULL)
888 goto out_nomem;
889 token = match_token(string, nfs_secflavor_tokens, args);
890 kfree(string);
891
892 /*
893 * The flags setting is for v2/v3. The flavor_len
894 * setting is for v4. v2/v3 also need to know the
895 * difference between NULL and UNIX.
896 */
897 switch (token) {
898 case Opt_sec_none:
899 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
900 mnt->auth_flavor_len = 0;
901 mnt->auth_flavors[0] = RPC_AUTH_NULL;
902 break;
903 case Opt_sec_sys:
904 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
905 mnt->auth_flavor_len = 0;
906 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
907 break;
908 case Opt_sec_krb5:
909 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
910 mnt->auth_flavor_len = 1;
911 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
912 break;
913 case Opt_sec_krb5i:
914 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
915 mnt->auth_flavor_len = 1;
916 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
917 break;
918 case Opt_sec_krb5p:
919 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
920 mnt->auth_flavor_len = 1;
921 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
922 break;
923 case Opt_sec_lkey:
924 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
925 mnt->auth_flavor_len = 1;
926 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
927 break;
928 case Opt_sec_lkeyi:
929 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
930 mnt->auth_flavor_len = 1;
931 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
932 break;
933 case Opt_sec_lkeyp:
934 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
935 mnt->auth_flavor_len = 1;
936 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
937 break;
938 case Opt_sec_spkm:
939 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
940 mnt->auth_flavor_len = 1;
941 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
942 break;
943 case Opt_sec_spkmi:
944 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
945 mnt->auth_flavor_len = 1;
946 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
947 break;
948 case Opt_sec_spkmp:
949 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
950 mnt->auth_flavor_len = 1;
951 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
952 break;
953 default:
954 goto out_unrec_sec;
955 }
956 break;
957 case Opt_proto:
958 string = match_strdup(args);
959 if (string == NULL)
960 goto out_nomem;
961 token = match_token(string,
962 nfs_xprt_protocol_tokens, args);
963 kfree(string);
964
965 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400966 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400967 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400968 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400969 mnt->timeo = 7;
970 mnt->retrans = 5;
971 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400972 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400973 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400974 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400975 mnt->timeo = 600;
976 mnt->retrans = 2;
977 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400978 case Opt_xprt_rdma:
979 /* vector side protocols to TCP */
980 mnt->flags |= NFS_MOUNT_TCP;
981 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
982 mnt->timeo = 600;
983 mnt->retrans = 2;
984 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400985 default:
986 goto out_unrec_xprt;
987 }
988 break;
989 case Opt_mountproto:
990 string = match_strdup(args);
991 if (string == NULL)
992 goto out_nomem;
993 token = match_token(string,
994 nfs_xprt_protocol_tokens, args);
995 kfree(string);
996
997 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400998 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400999 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001001 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001002 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001003 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001004 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001005 default:
1006 goto out_unrec_xprt;
1007 }
1008 break;
1009 case Opt_addr:
1010 string = match_strdup(args);
1011 if (string == NULL)
1012 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001013 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001014 &mnt->nfs_server.address,
1015 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001016 kfree(string);
1017 break;
1018 case Opt_clientaddr:
1019 string = match_strdup(args);
1020 if (string == NULL)
1021 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001022 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001023 mnt->client_address = string;
1024 break;
Chuck Lever33832032007-12-10 14:59:13 -05001025 case Opt_mounthost:
1026 string = match_strdup(args);
1027 if (string == NULL)
1028 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001029 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001030 mnt->mount_server.hostname = string;
1031 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001032 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001033 string = match_strdup(args);
1034 if (string == NULL)
1035 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001036 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001037 &mnt->mount_server.address,
1038 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001039 kfree(string);
1040 break;
1041
1042 case Opt_userspace:
1043 case Opt_deprecated:
1044 break;
1045
1046 default:
1047 goto out_unknown;
1048 }
1049 }
1050
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001051 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port);
1052
Chuck Leverbf0fd762007-07-01 12:13:44 -04001053 return 1;
1054
1055out_nomem:
1056 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1057 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001058out_security_failure:
1059 free_secdata(secdata);
1060 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1061 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001062out_unrec_vers:
1063 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1064 return 0;
1065
1066out_unrec_xprt:
1067 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1068 return 0;
1069
1070out_unrec_sec:
1071 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1072 return 0;
1073
1074out_unknown:
1075 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1076 return 0;
1077}
1078
1079/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001080 * Use the remote server's MOUNT service to request the NFS file handle
1081 * corresponding to the provided path.
1082 */
1083static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1084 struct nfs_fh *root_fh)
1085{
Chuck Lever4c568012007-12-10 14:59:28 -05001086 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001087 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001088 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001089
1090 if (args->mount_server.version == 0) {
1091 if (args->flags & NFS_MOUNT_VER3)
1092 args->mount_server.version = NFS_MNT3_VERSION;
1093 else
1094 args->mount_server.version = NFS_MNT_VERSION;
1095 }
1096
Chuck Lever33832032007-12-10 14:59:13 -05001097 if (args->mount_server.hostname)
1098 hostname = args->mount_server.hostname;
1099 else
1100 hostname = args->nfs_server.hostname;
1101
Chuck Lever0076d7b2007-07-01 12:13:49 -04001102 /*
1103 * Construct the mount server's address.
1104 */
Chuck Lever4c568012007-12-10 14:59:28 -05001105 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1106 memcpy(sap, &args->nfs_server.address,
1107 args->nfs_server.addrlen);
1108 args->mount_server.addrlen = args->nfs_server.addrlen;
1109 }
1110
James Lentiniaad70002007-09-24 17:32:49 -04001111 /*
1112 * autobind will be used if mount_server.port == 0
1113 */
Chuck Lever4c568012007-12-10 14:59:28 -05001114 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001115
1116 /*
1117 * Now ask the mount server to map our export path
1118 * to a file handle.
1119 */
Chuck Lever4c568012007-12-10 14:59:28 -05001120 status = nfs_mount(sap,
1121 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001122 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001123 args->nfs_server.export_path,
1124 args->mount_server.version,
1125 args->mount_server.protocol,
1126 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001127 if (status == 0)
1128 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001129
Chuck Lever33832032007-12-10 14:59:13 -05001130 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1131 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001132 return status;
1133}
1134
1135/*
David Howells54ceac42006-08-22 20:06:13 -04001136 * Validate the NFS2/NFS3 mount data
1137 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001138 *
1139 * For option strings, user space handles the following behaviors:
1140 *
1141 * + DNS: mapping server host name to IP address ("addr=" option)
1142 *
1143 * + failure mode: how to behave if a mount request can't be handled
1144 * immediately ("fg/bg" option)
1145 *
1146 * + retry: how often to retry a mount request ("retry=" option)
1147 *
1148 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1149 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001150 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001151static int nfs_validate_mount_data(void *options,
1152 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001153 struct nfs_fh *mntfh,
1154 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001155{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001156 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001157
Russell Kingf16c9602007-11-16 22:13:24 +00001158 memset(args, 0, sizeof(*args));
1159
Chuck Lever5df36e72007-07-01 12:12:56 -04001160 if (data == NULL)
1161 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001162
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001163 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1164 args->rsize = NFS_MAX_FILE_IO_SIZE;
1165 args->wsize = NFS_MAX_FILE_IO_SIZE;
1166 args->timeo = 600;
1167 args->retrans = 2;
1168 args->acregmin = 3;
1169 args->acregmax = 60;
1170 args->acdirmin = 30;
1171 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001172 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001173 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001174
David Howellsf7b422b2006-06-09 09:34:33 -04001175 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001176 case 1:
1177 data->namlen = 0;
1178 case 2:
1179 data->bsize = 0;
1180 case 3:
1181 if (data->flags & NFS_MOUNT_VER3)
1182 goto out_no_v3;
1183 data->root.size = NFS2_FHSIZE;
1184 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1185 case 4:
1186 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1187 goto out_no_sec;
1188 case 5:
1189 memset(data->context, 0, sizeof(data->context));
1190 case 6:
1191 if (data->flags & NFS_MOUNT_VER3)
1192 mntfh->size = data->root.size;
1193 else
1194 mntfh->size = NFS2_FHSIZE;
1195
1196 if (mntfh->size > sizeof(mntfh->data))
1197 goto out_invalid_fh;
1198
1199 memcpy(mntfh->data, data->root.data, mntfh->size);
1200 if (mntfh->size < sizeof(mntfh->data))
1201 memset(mntfh->data + mntfh->size, 0,
1202 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001203
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001204 /*
1205 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1206 * can deal with.
1207 */
1208 args->flags = data->flags;
1209 args->rsize = data->rsize;
1210 args->wsize = data->wsize;
1211 args->flags = data->flags;
1212 args->timeo = data->timeo;
1213 args->retrans = data->retrans;
1214 args->acregmin = data->acregmin;
1215 args->acregmax = data->acregmax;
1216 args->acdirmin = data->acdirmin;
1217 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001218
1219 memcpy(&args->nfs_server.address, &data->addr,
1220 sizeof(data->addr));
1221 args->nfs_server.addrlen = sizeof(data->addr);
1222 if (!nfs_verify_server_address((struct sockaddr *)
1223 &args->nfs_server.address))
1224 goto out_no_address;
1225
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001226 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001227 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001228 /* N.B. caller will free nfs_server.hostname in all cases */
1229 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1230 args->namlen = data->namlen;
1231 args->bsize = data->bsize;
1232 args->auth_flavors[0] = data->pseudoflavor;
Eric Parisf9c3a382008-03-05 14:20:18 -05001233
1234 /*
1235 * The legacy version 6 binary mount data from userspace has a
1236 * field used only to transport selinux information into the
1237 * the kernel. To continue to support that functionality we
1238 * have a touch of selinux knowledge here in the NFS code. The
1239 * userspace code converted context=blah to just blah so we are
1240 * converting back to the full string selinux understands.
1241 */
1242 if (data->context[0]){
1243#ifdef CONFIG_SECURITY_SELINUX
1244 int rc;
1245 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1246 if (!opts_str)
1247 return -ENOMEM;
1248 strcpy(opts_str, "context=");
1249 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1250 strcat(opts_str, &data->context[0]);
1251 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1252 kfree(opts_str);
1253 if (rc)
1254 return rc;
1255#else
1256 return -EINVAL;
1257#endif
1258 }
1259
Chuck Lever5df36e72007-07-01 12:12:56 -04001260 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001261 default: {
1262 unsigned int len;
1263 char *c;
1264 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001265
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001266 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001267 return -EINVAL;
1268
Chuck Lever6e88e062007-09-24 15:39:50 -04001269 if (!nfs_verify_server_address((struct sockaddr *)
1270 &args->nfs_server.address))
1271 goto out_no_address;
1272
Chuck Lever136d5582007-07-01 12:13:54 -04001273 c = strchr(dev_name, ':');
1274 if (c == NULL)
1275 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001276 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001277 /* N.B. caller will free nfs_server.hostname in all cases */
1278 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001279
1280 c++;
1281 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001282 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001283 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001284
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001285 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001286 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001287 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001288
Chuck Lever136d5582007-07-01 12:13:54 -04001289 break;
1290 }
David Howellsf7b422b2006-06-09 09:34:33 -04001291 }
David Howells54ceac42006-08-22 20:06:13 -04001292
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001293 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1294 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001295
David Howellsf7b422b2006-06-09 09:34:33 -04001296#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001297 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001298 goto out_v3_not_compiled;
1299#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001300
David Howells54ceac42006-08-22 20:06:13 -04001301 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001302
1303out_no_data:
1304 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1305 return -EINVAL;
1306
1307out_no_v3:
1308 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1309 data->version);
1310 return -EINVAL;
1311
1312out_no_sec:
1313 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1314 return -EINVAL;
1315
Chuck Lever5df36e72007-07-01 12:12:56 -04001316#ifndef CONFIG_NFS_V3
1317out_v3_not_compiled:
1318 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1319 return -EPROTONOSUPPORT;
1320#endif /* !CONFIG_NFS_V3 */
1321
1322out_no_address:
1323 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1324 return -EINVAL;
1325
1326out_invalid_fh:
1327 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1328 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001329}
1330
1331/*
1332 * Initialise the common bits of the superblock
1333 */
1334static inline void nfs_initialise_sb(struct super_block *sb)
1335{
1336 struct nfs_server *server = NFS_SB(sb);
1337
1338 sb->s_magic = NFS_SUPER_MAGIC;
1339
1340 /* We probably want something more informative here */
1341 snprintf(sb->s_id, sizeof(sb->s_id),
1342 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1343
1344 if (sb->s_blocksize == 0)
1345 sb->s_blocksize = nfs_block_bits(server->wsize,
1346 &sb->s_blocksize_bits);
1347
1348 if (server->flags & NFS_MOUNT_NOAC)
1349 sb->s_flags |= MS_SYNCHRONOUS;
1350
1351 nfs_super_set_maxbytes(sb, server->maxfilesize);
1352}
1353
1354/*
1355 * Finish setting up an NFS2/3 superblock
1356 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001357static void nfs_fill_super(struct super_block *sb,
1358 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001359{
1360 struct nfs_server *server = NFS_SB(sb);
1361
1362 sb->s_blocksize_bits = 0;
1363 sb->s_blocksize = 0;
1364 if (data->bsize)
1365 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1366
1367 if (server->flags & NFS_MOUNT_VER3) {
1368 /* The VFS shouldn't apply the umask to mode bits. We will do
1369 * so ourselves when necessary.
1370 */
1371 sb->s_flags |= MS_POSIXACL;
1372 sb->s_time_gran = 1;
1373 }
1374
1375 sb->s_op = &nfs_sops;
1376 nfs_initialise_sb(sb);
1377}
1378
1379/*
1380 * Finish setting up a cloned NFS2/3 superblock
1381 */
1382static void nfs_clone_super(struct super_block *sb,
1383 const struct super_block *old_sb)
1384{
1385 struct nfs_server *server = NFS_SB(sb);
1386
1387 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1388 sb->s_blocksize = old_sb->s_blocksize;
1389 sb->s_maxbytes = old_sb->s_maxbytes;
1390
1391 if (server->flags & NFS_MOUNT_VER3) {
1392 /* The VFS shouldn't apply the umask to mode bits. We will do
1393 * so ourselves when necessary.
1394 */
1395 sb->s_flags |= MS_POSIXACL;
1396 sb->s_time_gran = 1;
1397 }
1398
1399 sb->s_op = old_sb->s_op;
1400 nfs_initialise_sb(sb);
1401}
1402
Trond Myklebust275a5d22007-05-16 16:53:28 -04001403#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1404
1405static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1406{
1407 const struct nfs_server *a = s->s_fs_info;
1408 const struct rpc_clnt *clnt_a = a->client;
1409 const struct rpc_clnt *clnt_b = b->client;
1410
1411 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1412 goto Ebusy;
1413 if (a->nfs_client != b->nfs_client)
1414 goto Ebusy;
1415 if (a->flags != b->flags)
1416 goto Ebusy;
1417 if (a->wsize != b->wsize)
1418 goto Ebusy;
1419 if (a->rsize != b->rsize)
1420 goto Ebusy;
1421 if (a->acregmin != b->acregmin)
1422 goto Ebusy;
1423 if (a->acregmax != b->acregmax)
1424 goto Ebusy;
1425 if (a->acdirmin != b->acdirmin)
1426 goto Ebusy;
1427 if (a->acdirmax != b->acdirmax)
1428 goto Ebusy;
1429 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1430 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001431 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001432Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001433 return 0;
1434}
1435
1436struct nfs_sb_mountdata {
1437 struct nfs_server *server;
1438 int mntflags;
1439};
1440
1441static int nfs_set_super(struct super_block *s, void *data)
1442{
1443 struct nfs_sb_mountdata *sb_mntdata = data;
1444 struct nfs_server *server = sb_mntdata->server;
1445 int ret;
1446
1447 s->s_flags = sb_mntdata->mntflags;
1448 s->s_fs_info = server;
1449 ret = set_anon_super(s, server);
1450 if (ret == 0)
1451 server->s_dev = s->s_dev;
1452 return ret;
1453}
1454
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001455static int nfs_compare_super_address(struct nfs_server *server1,
1456 struct nfs_server *server2)
1457{
1458 struct sockaddr *sap1, *sap2;
1459
1460 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1461 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1462
1463 if (sap1->sa_family != sap2->sa_family)
1464 return 0;
1465
1466 switch (sap1->sa_family) {
1467 case AF_INET: {
1468 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1469 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1470 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1471 return 0;
1472 if (sin1->sin_port != sin2->sin_port)
1473 return 0;
1474 break;
1475 }
1476 case AF_INET6: {
1477 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1478 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1479 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1480 return 0;
1481 if (sin1->sin6_port != sin2->sin6_port)
1482 return 0;
1483 break;
1484 }
1485 default:
1486 return 0;
1487 }
1488
1489 return 1;
1490}
1491
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001492static int nfs_compare_super(struct super_block *sb, void *data)
1493{
1494 struct nfs_sb_mountdata *sb_mntdata = data;
1495 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1496 int mntflags = sb_mntdata->mntflags;
1497
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001498 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001499 return 0;
1500 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1501 if (old->flags & NFS_MOUNT_UNSHARED)
1502 return 0;
1503 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1504 return 0;
1505 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001506}
1507
David Howells54ceac42006-08-22 20:06:13 -04001508static int nfs_get_sb(struct file_system_type *fs_type,
1509 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1510{
1511 struct nfs_server *server = NULL;
1512 struct super_block *s;
1513 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001514 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001515 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001516 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001517 struct nfs_sb_mountdata sb_mntdata = {
1518 .mntflags = flags,
1519 };
David Howells54ceac42006-08-22 20:06:13 -04001520 int error;
1521
Eric Parisf9c3a382008-03-05 14:20:18 -05001522 security_init_mnt_opts(&data.lsm_opts);
1523
David Howells54ceac42006-08-22 20:06:13 -04001524 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001525 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001526 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001527 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001528
1529 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001530 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001531 if (IS_ERR(server)) {
1532 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001533 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001534 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001535 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001536
Trond Myklebust75180df2007-05-16 16:53:28 -04001537 if (server->flags & NFS_MOUNT_UNSHARED)
1538 compare_super = NULL;
1539
David Howells54ceac42006-08-22 20:06:13 -04001540 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001541 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001542 if (IS_ERR(s)) {
1543 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001544 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001545 }
1546
David Howells54ceac42006-08-22 20:06:13 -04001547 if (s->s_fs_info != server) {
1548 nfs_free_server(server);
1549 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001550 }
David Howells54ceac42006-08-22 20:06:13 -04001551
1552 if (!s->s_root) {
1553 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001554 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001555 }
1556
1557 mntroot = nfs_get_root(s, &mntfh);
1558 if (IS_ERR(mntroot)) {
1559 error = PTR_ERR(mntroot);
1560 goto error_splat_super;
1561 }
1562
Eric Parisf9c3a382008-03-05 14:20:18 -05001563 error = security_sb_set_mnt_opts(s, &data.lsm_opts);
1564 if (error)
1565 goto error_splat_root;
1566
David Howellsf7b422b2006-06-09 09:34:33 -04001567 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001568 mnt->mnt_sb = s;
1569 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001570 error = 0;
1571
1572out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001573 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001574 kfree(data.mount_server.hostname);
Eric Parisf9c3a382008-03-05 14:20:18 -05001575 security_free_mnt_opts(&data.lsm_opts);
Chuck Lever06559602007-07-01 12:12:35 -04001576 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001577
David Howells54ceac42006-08-22 20:06:13 -04001578out_err_nosb:
1579 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001580 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001581
Eric Parisf9c3a382008-03-05 14:20:18 -05001582error_splat_root:
1583 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04001584error_splat_super:
1585 up_write(&s->s_umount);
1586 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001587 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001588}
1589
David Howells54ceac42006-08-22 20:06:13 -04001590/*
1591 * Destroy an NFS2/3 superblock
1592 */
David Howellsf7b422b2006-06-09 09:34:33 -04001593static void nfs_kill_super(struct super_block *s)
1594{
1595 struct nfs_server *server = NFS_SB(s);
1596
1597 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001598 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001599}
1600
David Howells54ceac42006-08-22 20:06:13 -04001601/*
1602 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1603 */
1604static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1605 const char *dev_name, void *raw_data,
1606 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001607{
1608 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001609 struct super_block *s;
1610 struct nfs_server *server;
1611 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001612 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001613 struct nfs_sb_mountdata sb_mntdata = {
1614 .mntflags = flags,
1615 };
David Howells54ceac42006-08-22 20:06:13 -04001616 int error;
1617
1618 dprintk("--> nfs_xdev_get_sb()\n");
1619
1620 /* create a new volume representation */
1621 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1622 if (IS_ERR(server)) {
1623 error = PTR_ERR(server);
1624 goto out_err_noserver;
1625 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001626 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001627
Trond Myklebust75180df2007-05-16 16:53:28 -04001628 if (server->flags & NFS_MOUNT_UNSHARED)
1629 compare_super = NULL;
1630
David Howells54ceac42006-08-22 20:06:13 -04001631 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001632 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001633 if (IS_ERR(s)) {
1634 error = PTR_ERR(s);
1635 goto out_err_nosb;
1636 }
1637
1638 if (s->s_fs_info != server) {
1639 nfs_free_server(server);
1640 server = NULL;
1641 }
1642
1643 if (!s->s_root) {
1644 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001645 nfs_clone_super(s, data->sb);
1646 }
1647
1648 mntroot = nfs_get_root(s, data->fh);
1649 if (IS_ERR(mntroot)) {
1650 error = PTR_ERR(mntroot);
1651 goto error_splat_super;
1652 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001653 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001654 dput(mntroot);
1655 error = -ESTALE;
1656 goto error_splat_super;
1657 }
David Howells54ceac42006-08-22 20:06:13 -04001658
1659 s->s_flags |= MS_ACTIVE;
1660 mnt->mnt_sb = s;
1661 mnt->mnt_root = mntroot;
1662
Eric Parisf9c3a382008-03-05 14:20:18 -05001663 /* clone any lsm security options from the parent to the new sb */
1664 security_sb_clone_mnt_opts(data->sb, s);
1665
David Howells54ceac42006-08-22 20:06:13 -04001666 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1667 return 0;
1668
1669out_err_nosb:
1670 nfs_free_server(server);
1671out_err_noserver:
1672 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1673 return error;
1674
1675error_splat_super:
1676 up_write(&s->s_umount);
1677 deactivate_super(s);
1678 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1679 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001680}
1681
1682#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001683
1684/*
1685 * Finish setting up a cloned NFS4 superblock
1686 */
1687static void nfs4_clone_super(struct super_block *sb,
1688 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001689{
David Howells54ceac42006-08-22 20:06:13 -04001690 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1691 sb->s_blocksize = old_sb->s_blocksize;
1692 sb->s_maxbytes = old_sb->s_maxbytes;
1693 sb->s_time_gran = 1;
1694 sb->s_op = old_sb->s_op;
1695 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001696}
1697
1698/*
1699 * Set up an NFS4 superblock
1700 */
David Howells54ceac42006-08-22 20:06:13 -04001701static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001702{
David Howellsf7b422b2006-06-09 09:34:33 -04001703 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001704 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001705 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001706}
1707
David Howells54ceac42006-08-22 20:06:13 -04001708/*
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001709 * If the user didn't specify a port, set the port number to
1710 * the NFS version 4 default port.
1711 */
1712static void nfs4_default_port(struct sockaddr *sap)
1713{
1714 switch (sap->sa_family) {
1715 case AF_INET: {
1716 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1717 if (ap->sin_port == 0)
1718 ap->sin_port = htons(NFS_PORT);
1719 break;
1720 }
1721 case AF_INET6: {
1722 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1723 if (ap->sin6_port == 0)
1724 ap->sin6_port = htons(NFS_PORT);
1725 break;
1726 }
1727 }
1728}
1729
1730/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001731 * Validate NFSv4 mount options
1732 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001733static int nfs4_validate_mount_data(void *options,
1734 struct nfs_parsed_mount_data *args,
1735 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001736{
Chuck Lever4c568012007-12-10 14:59:28 -05001737 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001738 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001739 char *c;
1740
Russell Kingf16c9602007-11-16 22:13:24 +00001741 memset(args, 0, sizeof(*args));
1742
Chuck Leverf0768eb2007-07-01 12:13:01 -04001743 if (data == NULL)
1744 goto out_no_data;
1745
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001746 args->rsize = NFS_MAX_FILE_IO_SIZE;
1747 args->wsize = NFS_MAX_FILE_IO_SIZE;
1748 args->timeo = 600;
1749 args->retrans = 2;
1750 args->acregmin = 3;
1751 args->acregmax = 60;
1752 args->acdirmin = 30;
1753 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001754 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001755
Chuck Leverf0768eb2007-07-01 12:13:01 -04001756 switch (data->version) {
1757 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05001758 ap = (struct sockaddr_in *)&args->nfs_server.address;
1759 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001760 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05001761 if (data->host_addrlen == 0)
1762 goto out_no_address;
1763 args->nfs_server.addrlen = data->host_addrlen;
1764 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001765 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001766 if (!nfs_verify_server_address((struct sockaddr *)
1767 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001768 goto out_no_address;
1769
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001770 nfs4_default_port((struct sockaddr *)
1771 &args->nfs_server.address);
1772
Chuck Leverf0768eb2007-07-01 12:13:01 -04001773 switch (data->auth_flavourlen) {
1774 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001775 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001776 break;
1777 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001778 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001779 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001780 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001781 return -EFAULT;
1782 break;
1783 default:
1784 goto out_inval_auth;
1785 }
1786
1787 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1788 if (IS_ERR(c))
1789 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001790 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001791
1792 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1793 if (IS_ERR(c))
1794 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001795 args->nfs_server.export_path = c;
1796 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001797
1798 c = strndup_user(data->client_addr.data, 16);
1799 if (IS_ERR(c))
1800 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001801 args->client_address = c;
1802
1803 /*
1804 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1805 * can deal with.
1806 */
1807
1808 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1809 args->rsize = data->rsize;
1810 args->wsize = data->wsize;
1811 args->timeo = data->timeo;
1812 args->retrans = data->retrans;
1813 args->acregmin = data->acregmin;
1814 args->acregmax = data->acregmax;
1815 args->acdirmin = data->acdirmin;
1816 args->acdirmax = data->acdirmax;
1817 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001818
1819 break;
Chuck Lever80071222007-07-01 12:13:59 -04001820 default: {
1821 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001822
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001823 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001824 return -EINVAL;
1825
1826 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001827 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001828 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001829
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001830 nfs4_default_port((struct sockaddr *)
1831 &args->nfs_server.address);
1832
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001833 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001834 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001835 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001836 break;
1837 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001838 break;
1839 default:
1840 goto out_inval_auth;
1841 }
1842
1843 /*
Chuck Lever80071222007-07-01 12:13:59 -04001844 * Split "dev_name" into "hostname:mntpath".
1845 */
1846 c = strchr(dev_name, ':');
1847 if (c == NULL)
1848 return -EINVAL;
1849 /* while calculating len, pretend ':' is '\0' */
1850 len = c - dev_name;
1851 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001852 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001853 /* N.B. caller will free nfs_server.hostname in all cases */
1854 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001855
1856 c++; /* step over the ':' */
1857 len = strlen(c);
1858 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001859 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001860 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001861
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001862 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001863
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001864 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001865 goto out_no_client_address;
1866
Chuck Lever80071222007-07-01 12:13:59 -04001867 break;
1868 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001869 }
1870
1871 return 0;
1872
1873out_no_data:
1874 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1875 return -EINVAL;
1876
1877out_inval_auth:
1878 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1879 data->auth_flavourlen);
1880 return -EINVAL;
1881
1882out_no_address:
1883 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1884 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001885
1886out_no_client_address:
1887 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1888 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001889}
1890
1891/*
David Howells54ceac42006-08-22 20:06:13 -04001892 * Get the superblock for an NFS4 mountpoint
1893 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001894static int nfs4_get_sb(struct file_system_type *fs_type,
1895 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001896{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001897 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001898 struct super_block *s;
1899 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001900 struct nfs_fh mntfh;
1901 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001902 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001903 struct nfs_sb_mountdata sb_mntdata = {
1904 .mntflags = flags,
1905 };
David Howells54ceac42006-08-22 20:06:13 -04001906 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001907
Eric Parisf9c3a382008-03-05 14:20:18 -05001908 security_init_mnt_opts(&data.lsm_opts);
1909
Chuck Leverf0768eb2007-07-01 12:13:01 -04001910 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001911 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001912 if (error < 0)
1913 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001914
David Howells54ceac42006-08-22 20:06:13 -04001915 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001916 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001917 if (IS_ERR(server)) {
1918 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001919 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001920 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001921 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001922
Trond Myklebust75180df2007-05-16 16:53:28 -04001923 if (server->flags & NFS4_MOUNT_UNSHARED)
1924 compare_super = NULL;
1925
David Howells54ceac42006-08-22 20:06:13 -04001926 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001927 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001928 if (IS_ERR(s)) {
1929 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001930 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001931 }
1932
Trond Myklebust5dd31772006-08-24 01:03:05 -04001933 if (s->s_fs_info != server) {
1934 nfs_free_server(server);
1935 server = NULL;
1936 }
1937
David Howells54ceac42006-08-22 20:06:13 -04001938 if (!s->s_root) {
1939 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001940 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001941 }
David Howellsf7b422b2006-06-09 09:34:33 -04001942
David Howells54ceac42006-08-22 20:06:13 -04001943 mntroot = nfs4_get_root(s, &mntfh);
1944 if (IS_ERR(mntroot)) {
1945 error = PTR_ERR(mntroot);
1946 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001947 }
David Howells54ceac42006-08-22 20:06:13 -04001948
David Howellsf7b422b2006-06-09 09:34:33 -04001949 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001950 mnt->mnt_sb = s;
1951 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001952 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001953
Chuck Lever29eb9812007-07-01 12:12:30 -04001954out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001955 kfree(data.client_address);
1956 kfree(data.nfs_server.export_path);
1957 kfree(data.nfs_server.hostname);
Eric Parisf9c3a382008-03-05 14:20:18 -05001958 security_free_mnt_opts(&data.lsm_opts);
Trond Myklebust816724e2006-06-24 08:41:41 -04001959 return error;
David Howells54ceac42006-08-22 20:06:13 -04001960
Chuck Lever29eb9812007-07-01 12:12:30 -04001961out_free:
1962 nfs_free_server(server);
1963 goto out;
1964
David Howells54ceac42006-08-22 20:06:13 -04001965error_splat_super:
1966 up_write(&s->s_umount);
1967 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001968 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001969}
1970
1971static void nfs4_kill_super(struct super_block *sb)
1972{
1973 struct nfs_server *server = NFS_SB(sb);
1974
1975 nfs_return_all_delegations(sb);
1976 kill_anon_super(sb);
1977
1978 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001979 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001980}
1981
1982/*
David Howells54ceac42006-08-22 20:06:13 -04001983 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001984 */
David Howells54ceac42006-08-22 20:06:13 -04001985static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1986 const char *dev_name, void *raw_data,
1987 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001988{
1989 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001990 struct super_block *s;
1991 struct nfs_server *server;
1992 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001993 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001994 struct nfs_sb_mountdata sb_mntdata = {
1995 .mntflags = flags,
1996 };
David Howells54ceac42006-08-22 20:06:13 -04001997 int error;
1998
1999 dprintk("--> nfs4_xdev_get_sb()\n");
2000
2001 /* create a new volume representation */
2002 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2003 if (IS_ERR(server)) {
2004 error = PTR_ERR(server);
2005 goto out_err_noserver;
2006 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002007 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002008
Trond Myklebust75180df2007-05-16 16:53:28 -04002009 if (server->flags & NFS4_MOUNT_UNSHARED)
2010 compare_super = NULL;
2011
David Howells54ceac42006-08-22 20:06:13 -04002012 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002013 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002014 if (IS_ERR(s)) {
2015 error = PTR_ERR(s);
2016 goto out_err_nosb;
2017 }
2018
2019 if (s->s_fs_info != server) {
2020 nfs_free_server(server);
2021 server = NULL;
2022 }
2023
2024 if (!s->s_root) {
2025 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002026 nfs4_clone_super(s, data->sb);
2027 }
2028
2029 mntroot = nfs4_get_root(s, data->fh);
2030 if (IS_ERR(mntroot)) {
2031 error = PTR_ERR(mntroot);
2032 goto error_splat_super;
2033 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002034 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2035 dput(mntroot);
2036 error = -ESTALE;
2037 goto error_splat_super;
2038 }
David Howells54ceac42006-08-22 20:06:13 -04002039
2040 s->s_flags |= MS_ACTIVE;
2041 mnt->mnt_sb = s;
2042 mnt->mnt_root = mntroot;
2043
2044 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2045 return 0;
2046
2047out_err_nosb:
2048 nfs_free_server(server);
2049out_err_noserver:
2050 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2051 return error;
2052
2053error_splat_super:
2054 up_write(&s->s_umount);
2055 deactivate_super(s);
2056 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2057 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002058}
2059
David Howells54ceac42006-08-22 20:06:13 -04002060/*
2061 * Create an NFS4 server record on referral traversal
2062 */
2063static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2064 const char *dev_name, void *raw_data,
2065 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002066{
2067 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002068 struct super_block *s;
2069 struct nfs_server *server;
2070 struct dentry *mntroot;
2071 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002072 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002073 struct nfs_sb_mountdata sb_mntdata = {
2074 .mntflags = flags,
2075 };
David Howells54ceac42006-08-22 20:06:13 -04002076 int error;
2077
2078 dprintk("--> nfs4_referral_get_sb()\n");
2079
2080 /* create a new volume representation */
2081 server = nfs4_create_referral_server(data, &mntfh);
2082 if (IS_ERR(server)) {
2083 error = PTR_ERR(server);
2084 goto out_err_noserver;
2085 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002086 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002087
Trond Myklebust75180df2007-05-16 16:53:28 -04002088 if (server->flags & NFS4_MOUNT_UNSHARED)
2089 compare_super = NULL;
2090
David Howells54ceac42006-08-22 20:06:13 -04002091 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002092 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002093 if (IS_ERR(s)) {
2094 error = PTR_ERR(s);
2095 goto out_err_nosb;
2096 }
2097
2098 if (s->s_fs_info != server) {
2099 nfs_free_server(server);
2100 server = NULL;
2101 }
2102
2103 if (!s->s_root) {
2104 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002105 nfs4_fill_super(s);
2106 }
2107
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002108 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002109 if (IS_ERR(mntroot)) {
2110 error = PTR_ERR(mntroot);
2111 goto error_splat_super;
2112 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002113 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2114 dput(mntroot);
2115 error = -ESTALE;
2116 goto error_splat_super;
2117 }
David Howells54ceac42006-08-22 20:06:13 -04002118
2119 s->s_flags |= MS_ACTIVE;
2120 mnt->mnt_sb = s;
2121 mnt->mnt_root = mntroot;
2122
2123 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2124 return 0;
2125
2126out_err_nosb:
2127 nfs_free_server(server);
2128out_err_noserver:
2129 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2130 return error;
2131
2132error_splat_super:
2133 up_write(&s->s_umount);
2134 deactivate_super(s);
2135 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2136 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002137}
2138
David Howells54ceac42006-08-22 20:06:13 -04002139#endif /* CONFIG_NFS_V4 */