blob: d27aa1db0074a0f5520c11c2797b2467f22ba20d [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,
Chuck Leverbf0fd762007-07-01 12:13:44 -040068 Opt_posix, Opt_noposix,
69 Opt_cto, Opt_nocto,
70 Opt_ac, Opt_noac,
71 Opt_lock, Opt_nolock,
72 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040073 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040074 Opt_acl, Opt_noacl,
75 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040076 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040077
78 /* Mount options that take integer arguments */
79 Opt_port,
80 Opt_rsize, Opt_wsize, Opt_bsize,
81 Opt_timeo, Opt_retrans,
82 Opt_acregmin, Opt_acregmax,
83 Opt_acdirmin, Opt_acdirmax,
84 Opt_actimeo,
85 Opt_namelen,
86 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040087 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040088 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040089
90 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050091 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040092 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040093
94 /* Mount options that are ignored */
95 Opt_userspace, Opt_deprecated,
96
97 Opt_err
98};
99
100static match_table_t nfs_mount_option_tokens = {
101 { Opt_userspace, "bg" },
102 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400103 { Opt_userspace, "retry=%s" },
104
Chuck Leverbf0fd762007-07-01 12:13:44 -0400105 { Opt_soft, "soft" },
106 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400107 { Opt_deprecated, "intr" },
108 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109 { Opt_posix, "posix" },
110 { Opt_noposix, "noposix" },
111 { Opt_cto, "cto" },
112 { Opt_nocto, "nocto" },
113 { Opt_ac, "ac" },
114 { Opt_noac, "noac" },
115 { Opt_lock, "lock" },
116 { Opt_nolock, "nolock" },
117 { Opt_v2, "v2" },
118 { Opt_v3, "v3" },
119 { Opt_udp, "udp" },
120 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400121 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400122 { Opt_acl, "acl" },
123 { Opt_noacl, "noacl" },
124 { Opt_rdirplus, "rdirplus" },
125 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400126 { Opt_sharecache, "sharecache" },
127 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400128
129 { Opt_port, "port=%u" },
130 { Opt_rsize, "rsize=%u" },
131 { Opt_wsize, "wsize=%u" },
132 { Opt_bsize, "bsize=%u" },
133 { Opt_timeo, "timeo=%u" },
134 { Opt_retrans, "retrans=%u" },
135 { Opt_acregmin, "acregmin=%u" },
136 { Opt_acregmax, "acregmax=%u" },
137 { Opt_acdirmin, "acdirmin=%u" },
138 { Opt_acdirmax, "acdirmax=%u" },
139 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400140 { 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
Al Viro42faad92008-04-24 07:21:56 -0400201static void nfs_umount_begin(struct super_block *);
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 *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400210static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400211
212static struct file_system_type nfs_fs_type = {
213 .owner = THIS_MODULE,
214 .name = "nfs",
215 .get_sb = nfs_get_sb,
216 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700217 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400218};
219
David Howells54ceac42006-08-22 20:06:13 -0400220struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400221 .owner = THIS_MODULE,
222 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400223 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400224 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700225 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400226};
227
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800228static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400229 .alloc_inode = nfs_alloc_inode,
230 .destroy_inode = nfs_destroy_inode,
231 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500232 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400233 .statfs = nfs_statfs,
234 .clear_inode = nfs_clear_inode,
235 .umount_begin = nfs_umount_begin,
236 .show_options = nfs_show_options,
237 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400238 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400239};
240
241#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400242static int nfs4_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400244static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
246static int nfs4_referral_get_sb(struct file_system_type *fs_type,
247 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400248static void nfs4_kill_super(struct super_block *sb);
249
250static struct file_system_type nfs4_fs_type = {
251 .owner = THIS_MODULE,
252 .name = "nfs4",
253 .get_sb = nfs4_get_sb,
254 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400256};
257
David Howells54ceac42006-08-22 20:06:13 -0400258struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .owner = THIS_MODULE,
260 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400261 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400262 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700263 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400264};
265
David Howells54ceac42006-08-22 20:06:13 -0400266struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400267 .owner = THIS_MODULE,
268 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400269 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400270 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700271 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400272};
273
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800274static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400275 .alloc_inode = nfs_alloc_inode,
276 .destroy_inode = nfs_destroy_inode,
277 .write_inode = nfs_write_inode,
278 .statfs = nfs_statfs,
279 .clear_inode = nfs4_clear_inode,
280 .umount_begin = nfs_umount_begin,
281 .show_options = nfs_show_options,
282 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400283 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400284};
285#endif
286
Rusty Russell8e1f9362007-07-17 04:03:17 -0700287static struct shrinker acl_shrinker = {
288 .shrink = nfs_access_cache_shrinker,
289 .seeks = DEFAULT_SEEKS,
290};
Trond Myklebust979df722006-07-25 11:28:19 -0400291
David Howellsf7b422b2006-06-09 09:34:33 -0400292/*
293 * Register the NFS filesystems
294 */
295int __init register_nfs_fs(void)
296{
297 int ret;
298
299 ret = register_filesystem(&nfs_fs_type);
300 if (ret < 0)
301 goto error_0;
302
David Howellsf7b422b2006-06-09 09:34:33 -0400303 ret = nfs_register_sysctl();
304 if (ret < 0)
305 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800306#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400307 ret = register_filesystem(&nfs4_fs_type);
308 if (ret < 0)
309 goto error_2;
310#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700311 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400312 return 0;
313
314#ifdef CONFIG_NFS_V4
315error_2:
316 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800317#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400318error_1:
319 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400320error_0:
321 return ret;
322}
323
324/*
325 * Unregister the NFS filesystems
326 */
327void __exit unregister_nfs_fs(void)
328{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700329 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400330#ifdef CONFIG_NFS_V4
331 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400332#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700333 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400334 unregister_filesystem(&nfs_fs_type);
335}
336
Steve Dicksonef818a22007-11-08 04:05:04 -0500337void nfs_sb_active(struct nfs_server *server)
338{
339 atomic_inc(&server->active);
340}
341
342void nfs_sb_deactive(struct nfs_server *server)
343{
344 if (atomic_dec_and_test(&server->active))
345 wake_up(&server->active_wq);
346}
347
348static void nfs_put_super(struct super_block *sb)
349{
350 struct nfs_server *server = NFS_SB(sb);
351 /*
352 * Make sure there are no outstanding ops to this server.
353 * If so, wait for them to finish before allowing the
354 * unmount to continue.
355 */
356 wait_event(server->active_wq, atomic_read(&server->active) == 0);
357}
358
David Howellsf7b422b2006-06-09 09:34:33 -0400359/*
360 * Deliver file system statistics to userspace
361 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400362static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400363{
David Howells0c7d90c2006-08-22 20:06:10 -0400364 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400365 unsigned char blockbits;
366 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400367 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400368 struct nfs_fattr fattr;
369 struct nfs_fsstat res = {
370 .fattr = &fattr,
371 };
372 int error;
373
374 lock_kernel();
375
David Howells8fa5c002006-08-22 20:06:12 -0400376 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400377 if (error < 0)
378 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700379 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400380
381 /*
382 * Current versions of glibc do not correctly handle the
383 * case where f_frsize != f_bsize. Eventually we want to
384 * report the value of wtmult in this field.
385 */
David Howells0c7d90c2006-08-22 20:06:10 -0400386 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400387
388 /*
389 * On most *nix systems, f_blocks, f_bfree, and f_bavail
390 * are reported in units of f_frsize. Linux hasn't had
391 * an f_frsize field in its statfs struct until recently,
392 * thus historically Linux's sys_statfs reports these
393 * fields in units of f_bsize.
394 */
David Howells0c7d90c2006-08-22 20:06:10 -0400395 buf->f_bsize = dentry->d_sb->s_blocksize;
396 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400397 blockres = (1 << blockbits) - 1;
398 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
399 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
400 buf->f_bavail = (res.abytes + blockres) >> blockbits;
401
402 buf->f_files = res.tfiles;
403 buf->f_ffree = res.afiles;
404
405 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700406
David Howellsf7b422b2006-06-09 09:34:33 -0400407 unlock_kernel();
408 return 0;
409
410 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700411 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700412 unlock_kernel();
413 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400414}
415
David Howells7d4e2742006-08-22 20:06:07 -0400416/*
417 * Map the security flavour number to a name
418 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400419static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
420{
David Howells7d4e2742006-08-22 20:06:07 -0400421 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400422 rpc_authflavor_t flavour;
423 const char *str;
424 } sec_flavours[] = {
425 { RPC_AUTH_NULL, "null" },
426 { RPC_AUTH_UNIX, "sys" },
427 { RPC_AUTH_GSS_KRB5, "krb5" },
428 { RPC_AUTH_GSS_KRB5I, "krb5i" },
429 { RPC_AUTH_GSS_KRB5P, "krb5p" },
430 { RPC_AUTH_GSS_LKEY, "lkey" },
431 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
432 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
433 { RPC_AUTH_GSS_SPKM, "spkm" },
434 { RPC_AUTH_GSS_SPKMI, "spkmi" },
435 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400436 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400437 };
438 int i;
439
Chuck Lever4d81cd12007-07-01 12:12:40 -0400440 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400441 if (sec_flavours[i].flavour == flavour)
442 break;
443 }
444 return sec_flavours[i].str;
445}
446
Chuck Lever82d101d2008-03-14 14:10:37 -0400447static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
448 int showdefaults)
449{
450 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
451
452 switch (sap->sa_family) {
453 case AF_INET: {
454 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
455 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
456 NIPQUAD(sin->sin_addr.s_addr));
457 break;
458 }
459 case AF_INET6: {
460 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
461 seq_printf(m, ",mountaddr=" NIP6_FMT,
462 NIP6(sin6->sin6_addr));
463 break;
464 }
465 default:
466 if (showdefaults)
467 seq_printf(m, ",mountaddr=unspecified");
468 }
469
470 if (nfss->mountd_version || showdefaults)
471 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
472 if (nfss->mountd_port || showdefaults)
473 seq_printf(m, ",mountport=%u", nfss->mountd_port);
474
475 switch (nfss->mountd_protocol) {
476 case IPPROTO_UDP:
477 seq_printf(m, ",mountproto=udp");
478 break;
479 case IPPROTO_TCP:
480 seq_printf(m, ",mountproto=tcp");
481 break;
482 default:
483 if (showdefaults)
484 seq_printf(m, ",mountproto=auto");
485 }
486}
487
David Howellsf7b422b2006-06-09 09:34:33 -0400488/*
489 * Describe the mount options in force on this server representation
490 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400491static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
492 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400493{
David Howells509de812006-08-22 20:06:11 -0400494 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400495 int flag;
David Howells509de812006-08-22 20:06:11 -0400496 const char *str;
497 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400498 } nfs_info[] = {
499 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400500 { NFS_MOUNT_INTR, ",intr", ",nointr" },
501 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400502 { NFS_MOUNT_NOCTO, ",nocto", "" },
503 { NFS_MOUNT_NOAC, ",noac", "" },
504 { NFS_MOUNT_NONLM, ",nolock", "" },
505 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400506 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400507 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400508 { 0, NULL, NULL }
509 };
David Howells509de812006-08-22 20:06:11 -0400510 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400511 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400512 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400513
Chuck Lever82d101d2008-03-14 14:10:37 -0400514 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400515 seq_printf(m, ",rsize=%u", nfss->rsize);
516 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400517 if (nfss->bsize != 0)
518 seq_printf(m, ",bsize=%u", nfss->bsize);
519 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400520 if (nfss->acregmin != 3*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400521 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400522 if (nfss->acregmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400523 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400524 if (nfss->acdirmin != 30*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400525 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400526 if (nfss->acdirmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400527 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400528 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
529 if (nfss->flags & nfs_infop->flag)
530 seq_puts(m, nfs_infop->str);
531 else
532 seq_puts(m, nfs_infop->nostr);
533 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400534 seq_printf(m, ",proto=%s",
535 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400536 if (version == 4) {
537 if (nfss->port != NFS_PORT)
538 seq_printf(m, ",port=%u", nfss->port);
539 } else
540 if (nfss->port)
541 seq_printf(m, ",port=%u", nfss->port);
542
Trond Myklebust33170232007-12-20 16:03:59 -0500543 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
544 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400545 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400546
547 if (version != 4)
548 nfs_show_mountd_options(m, nfss, showdefaults);
549
550#ifdef CONFIG_NFS_V4
551 if (clp->rpc_ops->version == 4)
552 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
553#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400554}
555
556/*
557 * Describe the mount options on this VFS mountpoint
558 */
559static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
560{
561 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
562
563 nfs_show_mount_options(m, nfss, 0);
564
Chuck Lever5d8515c2007-12-10 14:57:16 -0500565 seq_printf(m, ",addr=%s",
566 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
567 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400568
569 return 0;
570}
571
572/*
573 * Present statistical information for this VFS mountpoint
574 */
575static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
576{
577 int i, cpu;
578 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
579 struct rpc_auth *auth = nfss->client->cl_auth;
580 struct nfs_iostats totals = { };
581
582 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
583
584 /*
585 * Display all mount option settings
586 */
587 seq_printf(m, "\n\topts:\t");
588 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
589 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
590 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
591 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
592 nfs_show_mount_options(m, nfss, 1);
593
594 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
595
596 seq_printf(m, "\n\tcaps:\t");
597 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400598 seq_printf(m, ",wtmult=%u", nfss->wtmult);
599 seq_printf(m, ",dtsize=%u", nfss->dtsize);
600 seq_printf(m, ",bsize=%u", nfss->bsize);
601 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400602
603#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500604 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400605 seq_printf(m, "\n\tnfsv4:\t");
606 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
607 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
608 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
609 }
610#endif
611
612 /*
613 * Display security flavor in effect for this mount
614 */
Chuck Lever2d767432008-03-14 14:10:08 -0400615 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400616 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400617 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400618
619 /*
620 * Display superblock I/O counters
621 */
622 for_each_possible_cpu(cpu) {
623 struct nfs_iostats *stats;
624
625 preempt_disable();
626 stats = per_cpu_ptr(nfss->io_stats, cpu);
627
628 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
629 totals.events[i] += stats->events[i];
630 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
631 totals.bytes[i] += stats->bytes[i];
632
633 preempt_enable();
634 }
635
636 seq_printf(m, "\n\tevents:\t");
637 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
638 seq_printf(m, "%lu ", totals.events[i]);
639 seq_printf(m, "\n\tbytes:\t");
640 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
641 seq_printf(m, "%Lu ", totals.bytes[i]);
642 seq_printf(m, "\n");
643
644 rpc_print_iostats(m, nfss->client);
645
646 return 0;
647}
648
649/*
650 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400651 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400652 */
Al Viro42faad92008-04-24 07:21:56 -0400653static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400654{
Al Viro42faad92008-04-24 07:21:56 -0400655 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400656 struct rpc_clnt *rpc;
657
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400658 /* -EIO all pending I/O */
659 rpc = server->client_acl;
660 if (!IS_ERR(rpc))
661 rpc_killall_tasks(rpc);
662 rpc = server->client;
663 if (!IS_ERR(rpc))
664 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400665}
666
667/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500668 * Set the port number in an address. Be agnostic about the address family.
669 */
670static void nfs_set_port(struct sockaddr *sap, unsigned short port)
671{
672 switch (sap->sa_family) {
673 case AF_INET: {
674 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
675 ap->sin_port = htons(port);
676 break;
677 }
678 case AF_INET6: {
679 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
680 ap->sin6_port = htons(port);
681 break;
682 }
683 }
684}
685
686/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500687 * Sanity-check a server address provided by the mount command.
688 *
689 * Address family must be initialized, and address must not be
690 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400691 */
692static int nfs_verify_server_address(struct sockaddr *addr)
693{
694 switch (addr->sa_family) {
695 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500696 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700697 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500698 }
699 case AF_INET6: {
700 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
701 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400702 }
703 }
704
705 return 0;
706}
707
Chuck Leverce3b7e12008-06-23 12:36:53 -0400708static void nfs_parse_ipv4_address(char *string, size_t str_len,
709 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500710{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400711 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
712 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500713
Chuck Leverce3b7e12008-06-23 12:36:53 -0400714 if (str_len <= INET_ADDRSTRLEN) {
715 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
716 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500717
Chuck Leverce3b7e12008-06-23 12:36:53 -0400718 sin->sin_family = AF_INET;
719 *addr_len = sizeof(*sin);
720 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500721 return;
722 }
Chuck Lever9412b922007-12-10 14:59:21 -0500723
724 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400725 *addr_len = 0;
726}
727
728#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
729static void nfs_parse_ipv6_address(char *string, size_t str_len,
730 struct sockaddr *sap, size_t *addr_len)
731{
732 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
733 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
734
735 if (str_len <= INET6_ADDRSTRLEN) {
736 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
737 (int)str_len, string);
738
739 sin6->sin6_family = AF_INET6;
740 *addr_len = sizeof(*sin6);
741 if (in6_pton(string, str_len, addr, '\0', NULL))
742 return;
743 }
744
745 sap->sa_family = AF_UNSPEC;
746 *addr_len = 0;
747}
748#else
749static void nfs_parse_ipv6_address(char *string, size_t str_len,
750 struct sockaddr *sap, size_t *addr_len)
751{
752 sap->sa_family = AF_UNSPEC;
753 *addr_len = 0;
754}
755#endif
756
757/*
758 * Construct a sockaddr based on the contents of a string that contains
759 * an IP address in presentation format.
760 *
761 * If there is a problem constructing the new sockaddr, set the address
762 * family to AF_UNSPEC.
763 */
764static void nfs_parse_ip_address(char *string, size_t str_len,
765 struct sockaddr *sap, size_t *addr_len)
766{
767 unsigned int i, colons;
768
769 colons = 0;
770 for (i = 0; i < str_len; i++)
771 if (string[i] == ':')
772 colons++;
773
774 if (colons >= 2)
775 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
776 else
777 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500778}
779
780/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400781 * Error-check and convert a string of mount options from user space into
782 * a data structure
783 */
784static int nfs_parse_mount_options(char *raw,
785 struct nfs_parsed_mount_data *mnt)
786{
Eric Parisf9c3a382008-03-05 14:20:18 -0500787 char *p, *string, *secdata;
Eric Parisf9c3a382008-03-05 14:20:18 -0500788 int rc;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400789
790 if (!raw) {
791 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
792 return 1;
793 }
794 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
795
Eric Parisf9c3a382008-03-05 14:20:18 -0500796 secdata = alloc_secdata();
797 if (!secdata)
798 goto out_nomem;
799
800 rc = security_sb_copy_data(raw, secdata);
801 if (rc)
802 goto out_security_failure;
803
804 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
805 if (rc)
806 goto out_security_failure;
807
808 free_secdata(secdata);
809
Chuck Leverbf0fd762007-07-01 12:13:44 -0400810 while ((p = strsep(&raw, ",")) != NULL) {
811 substring_t args[MAX_OPT_ARGS];
812 int option, token;
813
814 if (!*p)
815 continue;
816
817 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
818
819 token = match_token(p, nfs_mount_option_tokens, args);
820 switch (token) {
821 case Opt_soft:
822 mnt->flags |= NFS_MOUNT_SOFT;
823 break;
824 case Opt_hard:
825 mnt->flags &= ~NFS_MOUNT_SOFT;
826 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400827 case Opt_posix:
828 mnt->flags |= NFS_MOUNT_POSIX;
829 break;
830 case Opt_noposix:
831 mnt->flags &= ~NFS_MOUNT_POSIX;
832 break;
833 case Opt_cto:
834 mnt->flags &= ~NFS_MOUNT_NOCTO;
835 break;
836 case Opt_nocto:
837 mnt->flags |= NFS_MOUNT_NOCTO;
838 break;
839 case Opt_ac:
840 mnt->flags &= ~NFS_MOUNT_NOAC;
841 break;
842 case Opt_noac:
843 mnt->flags |= NFS_MOUNT_NOAC;
844 break;
845 case Opt_lock:
846 mnt->flags &= ~NFS_MOUNT_NONLM;
847 break;
848 case Opt_nolock:
849 mnt->flags |= NFS_MOUNT_NONLM;
850 break;
851 case Opt_v2:
852 mnt->flags &= ~NFS_MOUNT_VER3;
853 break;
854 case Opt_v3:
855 mnt->flags |= NFS_MOUNT_VER3;
856 break;
857 case Opt_udp:
858 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400859 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400860 mnt->timeo = 7;
861 mnt->retrans = 5;
862 break;
863 case Opt_tcp:
864 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400865 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400866 mnt->timeo = 600;
867 mnt->retrans = 2;
868 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400869 case Opt_rdma:
870 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
871 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
872 mnt->timeo = 600;
873 mnt->retrans = 2;
874 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400875 case Opt_acl:
876 mnt->flags &= ~NFS_MOUNT_NOACL;
877 break;
878 case Opt_noacl:
879 mnt->flags |= NFS_MOUNT_NOACL;
880 break;
881 case Opt_rdirplus:
882 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
883 break;
884 case Opt_nordirplus:
885 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
886 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400887 case Opt_sharecache:
888 mnt->flags &= ~NFS_MOUNT_UNSHARED;
889 break;
890 case Opt_nosharecache:
891 mnt->flags |= NFS_MOUNT_UNSHARED;
892 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400893
894 case Opt_port:
895 if (match_int(args, &option))
896 return 0;
897 if (option < 0 || option > 65535)
898 return 0;
Chuck Leverf22d6d72008-03-14 14:10:22 -0400899 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400900 break;
901 case Opt_rsize:
902 if (match_int(args, &mnt->rsize))
903 return 0;
904 break;
905 case Opt_wsize:
906 if (match_int(args, &mnt->wsize))
907 return 0;
908 break;
909 case Opt_bsize:
910 if (match_int(args, &option))
911 return 0;
912 if (option < 0)
913 return 0;
914 mnt->bsize = option;
915 break;
916 case Opt_timeo:
917 if (match_int(args, &mnt->timeo))
918 return 0;
919 break;
920 case Opt_retrans:
921 if (match_int(args, &mnt->retrans))
922 return 0;
923 break;
924 case Opt_acregmin:
925 if (match_int(args, &mnt->acregmin))
926 return 0;
927 break;
928 case Opt_acregmax:
929 if (match_int(args, &mnt->acregmax))
930 return 0;
931 break;
932 case Opt_acdirmin:
933 if (match_int(args, &mnt->acdirmin))
934 return 0;
935 break;
936 case Opt_acdirmax:
937 if (match_int(args, &mnt->acdirmax))
938 return 0;
939 break;
940 case Opt_actimeo:
941 if (match_int(args, &option))
942 return 0;
943 if (option < 0)
944 return 0;
945 mnt->acregmin =
946 mnt->acregmax =
947 mnt->acdirmin =
948 mnt->acdirmax = option;
949 break;
950 case Opt_namelen:
951 if (match_int(args, &mnt->namlen))
952 return 0;
953 break;
954 case Opt_mountport:
955 if (match_int(args, &option))
956 return 0;
957 if (option < 0 || option > 65535)
958 return 0;
959 mnt->mount_server.port = option;
960 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400961 case Opt_mountvers:
962 if (match_int(args, &option))
963 return 0;
964 if (option < 0)
965 return 0;
966 mnt->mount_server.version = option;
967 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400968 case Opt_nfsvers:
969 if (match_int(args, &option))
970 return 0;
971 switch (option) {
972 case 2:
973 mnt->flags &= ~NFS_MOUNT_VER3;
974 break;
975 case 3:
976 mnt->flags |= NFS_MOUNT_VER3;
977 break;
978 default:
979 goto out_unrec_vers;
980 }
981 break;
982
983 case Opt_sec:
984 string = match_strdup(args);
985 if (string == NULL)
986 goto out_nomem;
987 token = match_token(string, nfs_secflavor_tokens, args);
988 kfree(string);
989
990 /*
991 * The flags setting is for v2/v3. The flavor_len
992 * setting is for v4. v2/v3 also need to know the
993 * difference between NULL and UNIX.
994 */
995 switch (token) {
996 case Opt_sec_none:
997 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
998 mnt->auth_flavor_len = 0;
999 mnt->auth_flavors[0] = RPC_AUTH_NULL;
1000 break;
1001 case Opt_sec_sys:
1002 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
1003 mnt->auth_flavor_len = 0;
1004 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
1005 break;
1006 case Opt_sec_krb5:
1007 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1008 mnt->auth_flavor_len = 1;
1009 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
1010 break;
1011 case Opt_sec_krb5i:
1012 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1013 mnt->auth_flavor_len = 1;
1014 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
1015 break;
1016 case Opt_sec_krb5p:
1017 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1018 mnt->auth_flavor_len = 1;
1019 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
1020 break;
1021 case Opt_sec_lkey:
1022 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1023 mnt->auth_flavor_len = 1;
1024 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
1025 break;
1026 case Opt_sec_lkeyi:
1027 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1028 mnt->auth_flavor_len = 1;
1029 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
1030 break;
1031 case Opt_sec_lkeyp:
1032 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1033 mnt->auth_flavor_len = 1;
1034 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1035 break;
1036 case Opt_sec_spkm:
1037 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1038 mnt->auth_flavor_len = 1;
1039 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1040 break;
1041 case Opt_sec_spkmi:
1042 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1043 mnt->auth_flavor_len = 1;
1044 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1045 break;
1046 case Opt_sec_spkmp:
1047 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1048 mnt->auth_flavor_len = 1;
1049 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1050 break;
1051 default:
1052 goto out_unrec_sec;
1053 }
1054 break;
1055 case Opt_proto:
1056 string = match_strdup(args);
1057 if (string == NULL)
1058 goto out_nomem;
1059 token = match_token(string,
1060 nfs_xprt_protocol_tokens, args);
1061 kfree(string);
1062
1063 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001064 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001065 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001066 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001067 mnt->timeo = 7;
1068 mnt->retrans = 5;
1069 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001070 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001071 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001072 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001073 mnt->timeo = 600;
1074 mnt->retrans = 2;
1075 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001076 case Opt_xprt_rdma:
1077 /* vector side protocols to TCP */
1078 mnt->flags |= NFS_MOUNT_TCP;
1079 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1080 mnt->timeo = 600;
1081 mnt->retrans = 2;
1082 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001083 default:
1084 goto out_unrec_xprt;
1085 }
1086 break;
1087 case Opt_mountproto:
1088 string = match_strdup(args);
1089 if (string == NULL)
1090 goto out_nomem;
1091 token = match_token(string,
1092 nfs_xprt_protocol_tokens, args);
1093 kfree(string);
1094
1095 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001096 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001097 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001098 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001099 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001100 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001101 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001102 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001103 default:
1104 goto out_unrec_xprt;
1105 }
1106 break;
1107 case Opt_addr:
1108 string = match_strdup(args);
1109 if (string == NULL)
1110 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001111 nfs_parse_ip_address(string, strlen(string),
1112 (struct sockaddr *)
1113 &mnt->nfs_server.address,
1114 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001115 kfree(string);
1116 break;
1117 case Opt_clientaddr:
1118 string = match_strdup(args);
1119 if (string == NULL)
1120 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001121 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 mnt->client_address = string;
1123 break;
Chuck Lever33832032007-12-10 14:59:13 -05001124 case Opt_mounthost:
1125 string = match_strdup(args);
1126 if (string == NULL)
1127 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001128 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001129 mnt->mount_server.hostname = string;
1130 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001131 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001132 string = match_strdup(args);
1133 if (string == NULL)
1134 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001135 nfs_parse_ip_address(string, strlen(string),
1136 (struct sockaddr *)
1137 &mnt->mount_server.address,
1138 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001139 kfree(string);
1140 break;
1141
1142 case Opt_userspace:
1143 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001144 dfprintk(MOUNT, "NFS: ignoring mount option "
1145 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001146 break;
1147
1148 default:
1149 goto out_unknown;
1150 }
1151 }
1152
Chuck Leverf22d6d72008-03-14 14:10:22 -04001153 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1154 mnt->nfs_server.port);
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001155
Chuck Leverbf0fd762007-07-01 12:13:44 -04001156 return 1;
1157
1158out_nomem:
1159 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1160 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001161out_security_failure:
1162 free_secdata(secdata);
1163 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1164 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165out_unrec_vers:
1166 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1167 return 0;
1168
1169out_unrec_xprt:
1170 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1171 return 0;
1172
1173out_unrec_sec:
1174 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1175 return 0;
1176
1177out_unknown:
1178 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1179 return 0;
1180}
1181
1182/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001183 * Use the remote server's MOUNT service to request the NFS file handle
1184 * corresponding to the provided path.
1185 */
1186static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1187 struct nfs_fh *root_fh)
1188{
Chuck Lever4c568012007-12-10 14:59:28 -05001189 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001190 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001191 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001192
1193 if (args->mount_server.version == 0) {
1194 if (args->flags & NFS_MOUNT_VER3)
1195 args->mount_server.version = NFS_MNT3_VERSION;
1196 else
1197 args->mount_server.version = NFS_MNT_VERSION;
1198 }
1199
Chuck Lever33832032007-12-10 14:59:13 -05001200 if (args->mount_server.hostname)
1201 hostname = args->mount_server.hostname;
1202 else
1203 hostname = args->nfs_server.hostname;
1204
Chuck Lever0076d7b2007-07-01 12:13:49 -04001205 /*
1206 * Construct the mount server's address.
1207 */
Chuck Lever4c568012007-12-10 14:59:28 -05001208 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1209 memcpy(sap, &args->nfs_server.address,
1210 args->nfs_server.addrlen);
1211 args->mount_server.addrlen = args->nfs_server.addrlen;
1212 }
1213
James Lentiniaad70002007-09-24 17:32:49 -04001214 /*
1215 * autobind will be used if mount_server.port == 0
1216 */
Chuck Lever4c568012007-12-10 14:59:28 -05001217 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001218
1219 /*
1220 * Now ask the mount server to map our export path
1221 * to a file handle.
1222 */
Chuck Lever4c568012007-12-10 14:59:28 -05001223 status = nfs_mount(sap,
1224 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001225 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001226 args->nfs_server.export_path,
1227 args->mount_server.version,
1228 args->mount_server.protocol,
1229 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001230 if (status == 0)
1231 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001232
Chuck Lever396cee972008-06-12 12:37:49 -04001233 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Lever33832032007-12-10 14:59:13 -05001234 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001235 return status;
1236}
1237
Chuck Leverd1aa0822008-06-23 12:36:45 -04001238static int nfs_parse_simple_hostname(const char *dev_name,
1239 char **hostname, size_t maxnamlen,
1240 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001241{
1242 size_t len;
1243 char *colon, *comma;
1244
1245 colon = strchr(dev_name, ':');
1246 if (colon == NULL)
1247 goto out_bad_devname;
1248
1249 len = colon - dev_name;
1250 if (len > maxnamlen)
1251 goto out_hostname;
1252
1253 /* N.B. caller will free nfs_server.hostname in all cases */
1254 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1255 if (!*hostname)
1256 goto out_nomem;
1257
1258 /* kill possible hostname list: not supported */
1259 comma = strchr(*hostname, ',');
1260 if (comma != NULL) {
1261 if (comma == *hostname)
1262 goto out_bad_devname;
1263 *comma = '\0';
1264 }
1265
1266 colon++;
1267 len = strlen(colon);
1268 if (len > maxpathlen)
1269 goto out_path;
1270 *export_path = kstrndup(colon, len, GFP_KERNEL);
1271 if (!*export_path)
1272 goto out_nomem;
1273
1274 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1275 return 0;
1276
1277out_bad_devname:
1278 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1279 return -EINVAL;
1280
1281out_nomem:
1282 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1283 return -ENOMEM;
1284
1285out_hostname:
1286 dfprintk(MOUNT, "NFS: server hostname too long\n");
1287 return -ENAMETOOLONG;
1288
1289out_path:
1290 dfprintk(MOUNT, "NFS: export pathname too long\n");
1291 return -ENAMETOOLONG;
1292}
1293
1294/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001295 * Hostname has square brackets around it because it contains one or
1296 * more colons. We look for the first closing square bracket, and a
1297 * colon must follow it.
1298 */
1299static int nfs_parse_protected_hostname(const char *dev_name,
1300 char **hostname, size_t maxnamlen,
1301 char **export_path, size_t maxpathlen)
1302{
1303 size_t len;
1304 char *start, *end;
1305
1306 start = (char *)(dev_name + 1);
1307
1308 end = strchr(start, ']');
1309 if (end == NULL)
1310 goto out_bad_devname;
1311 if (*(end + 1) != ':')
1312 goto out_bad_devname;
1313
1314 len = end - start;
1315 if (len > maxnamlen)
1316 goto out_hostname;
1317
1318 /* N.B. caller will free nfs_server.hostname in all cases */
1319 *hostname = kstrndup(start, len, GFP_KERNEL);
1320 if (*hostname == NULL)
1321 goto out_nomem;
1322
1323 end += 2;
1324 len = strlen(end);
1325 if (len > maxpathlen)
1326 goto out_path;
1327 *export_path = kstrndup(end, len, GFP_KERNEL);
1328 if (!*export_path)
1329 goto out_nomem;
1330
1331 return 0;
1332
1333out_bad_devname:
1334 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1335 return -EINVAL;
1336
1337out_nomem:
1338 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1339 return -ENOMEM;
1340
1341out_hostname:
1342 dfprintk(MOUNT, "NFS: server hostname too long\n");
1343 return -ENAMETOOLONG;
1344
1345out_path:
1346 dfprintk(MOUNT, "NFS: export pathname too long\n");
1347 return -ENAMETOOLONG;
1348}
1349
1350/*
1351 * Split "dev_name" into "hostname:export_path".
1352 *
1353 * The leftmost colon demarks the split between the server's hostname
1354 * and the export path. If the hostname starts with a left square
1355 * bracket, then it may contain colons.
1356 *
1357 * Note: caller frees hostname and export path, even on error.
1358 */
1359static int nfs_parse_devname(const char *dev_name,
1360 char **hostname, size_t maxnamlen,
1361 char **export_path, size_t maxpathlen)
1362{
1363 if (*dev_name == '[')
1364 return nfs_parse_protected_hostname(dev_name,
1365 hostname, maxnamlen,
1366 export_path, maxpathlen);
1367
1368 return nfs_parse_simple_hostname(dev_name,
1369 hostname, maxnamlen,
1370 export_path, maxpathlen);
1371}
1372
1373/*
David Howells54ceac42006-08-22 20:06:13 -04001374 * Validate the NFS2/NFS3 mount data
1375 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001376 *
1377 * For option strings, user space handles the following behaviors:
1378 *
1379 * + DNS: mapping server host name to IP address ("addr=" option)
1380 *
1381 * + failure mode: how to behave if a mount request can't be handled
1382 * immediately ("fg/bg" option)
1383 *
1384 * + retry: how often to retry a mount request ("retry=" option)
1385 *
1386 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1387 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001388 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001389static int nfs_validate_mount_data(void *options,
1390 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001391 struct nfs_fh *mntfh,
1392 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001393{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001394 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001395
Chuck Lever5df36e72007-07-01 12:12:56 -04001396 if (data == NULL)
1397 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001398
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001399 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1400 args->rsize = NFS_MAX_FILE_IO_SIZE;
1401 args->wsize = NFS_MAX_FILE_IO_SIZE;
1402 args->timeo = 600;
1403 args->retrans = 2;
1404 args->acregmin = 3;
1405 args->acregmax = 60;
1406 args->acdirmin = 30;
1407 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001408 args->mount_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001409 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001410 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001411 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001412
David Howellsf7b422b2006-06-09 09:34:33 -04001413 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001414 case 1:
1415 data->namlen = 0;
1416 case 2:
1417 data->bsize = 0;
1418 case 3:
1419 if (data->flags & NFS_MOUNT_VER3)
1420 goto out_no_v3;
1421 data->root.size = NFS2_FHSIZE;
1422 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1423 case 4:
1424 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1425 goto out_no_sec;
1426 case 5:
1427 memset(data->context, 0, sizeof(data->context));
1428 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001429 if (data->flags & NFS_MOUNT_VER3) {
1430 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1431 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001432 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001433 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001434 mntfh->size = NFS2_FHSIZE;
1435
Chuck Lever5df36e72007-07-01 12:12:56 -04001436
1437 memcpy(mntfh->data, data->root.data, mntfh->size);
1438 if (mntfh->size < sizeof(mntfh->data))
1439 memset(mntfh->data + mntfh->size, 0,
1440 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001441
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001442 /*
1443 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1444 * can deal with.
1445 */
1446 args->flags = data->flags;
1447 args->rsize = data->rsize;
1448 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001449 args->timeo = data->timeo;
1450 args->retrans = data->retrans;
1451 args->acregmin = data->acregmin;
1452 args->acregmax = data->acregmax;
1453 args->acdirmin = data->acdirmin;
1454 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001455
1456 memcpy(&args->nfs_server.address, &data->addr,
1457 sizeof(data->addr));
1458 args->nfs_server.addrlen = sizeof(data->addr);
1459 if (!nfs_verify_server_address((struct sockaddr *)
1460 &args->nfs_server.address))
1461 goto out_no_address;
1462
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001463 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001464 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001465 /* N.B. caller will free nfs_server.hostname in all cases */
1466 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1467 args->namlen = data->namlen;
1468 args->bsize = data->bsize;
1469 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001470 if (!args->nfs_server.hostname)
1471 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001472
1473 /*
1474 * The legacy version 6 binary mount data from userspace has a
1475 * field used only to transport selinux information into the
1476 * the kernel. To continue to support that functionality we
1477 * have a touch of selinux knowledge here in the NFS code. The
1478 * userspace code converted context=blah to just blah so we are
1479 * converting back to the full string selinux understands.
1480 */
1481 if (data->context[0]){
1482#ifdef CONFIG_SECURITY_SELINUX
1483 int rc;
1484 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1485 if (!opts_str)
1486 return -ENOMEM;
1487 strcpy(opts_str, "context=");
1488 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1489 strcat(opts_str, &data->context[0]);
1490 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1491 kfree(opts_str);
1492 if (rc)
1493 return rc;
1494#else
1495 return -EINVAL;
1496#endif
1497 }
1498
Chuck Lever5df36e72007-07-01 12:12:56 -04001499 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001500 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001501 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001502
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001503 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001504 return -EINVAL;
1505
Chuck Lever6e88e062007-09-24 15:39:50 -04001506 if (!nfs_verify_server_address((struct sockaddr *)
1507 &args->nfs_server.address))
1508 goto out_no_address;
1509
Chuck Leverdc045892008-06-23 12:36:37 -04001510 status = nfs_parse_devname(dev_name,
1511 &args->nfs_server.hostname,
1512 PAGE_SIZE,
1513 &args->nfs_server.export_path,
1514 NFS_MAXPATHLEN);
1515 if (!status)
1516 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001517
Chuck Leverdc045892008-06-23 12:36:37 -04001518 kfree(args->nfs_server.export_path);
1519 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001520
Chuck Lever136d5582007-07-01 12:13:54 -04001521 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001522 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001523
Chuck Lever136d5582007-07-01 12:13:54 -04001524 break;
1525 }
David Howellsf7b422b2006-06-09 09:34:33 -04001526 }
David Howells54ceac42006-08-22 20:06:13 -04001527
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001528 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1529 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001530
David Howellsf7b422b2006-06-09 09:34:33 -04001531#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001532 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001533 goto out_v3_not_compiled;
1534#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001535
David Howells54ceac42006-08-22 20:06:13 -04001536 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001537
1538out_no_data:
1539 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1540 return -EINVAL;
1541
1542out_no_v3:
1543 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1544 data->version);
1545 return -EINVAL;
1546
1547out_no_sec:
1548 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1549 return -EINVAL;
1550
Chuck Lever5df36e72007-07-01 12:12:56 -04001551#ifndef CONFIG_NFS_V3
1552out_v3_not_compiled:
1553 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1554 return -EPROTONOSUPPORT;
1555#endif /* !CONFIG_NFS_V3 */
1556
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001557out_nomem:
1558 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1559 return -ENOMEM;
1560
Chuck Lever5df36e72007-07-01 12:12:56 -04001561out_no_address:
1562 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1563 return -EINVAL;
1564
1565out_invalid_fh:
1566 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1567 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001568}
1569
Jeff Layton48b605f2008-06-10 15:38:39 -04001570static int
1571nfs_compare_remount_data(struct nfs_server *nfss,
1572 struct nfs_parsed_mount_data *data)
1573{
1574 if (data->flags != nfss->flags ||
1575 data->rsize != nfss->rsize ||
1576 data->wsize != nfss->wsize ||
1577 data->retrans != nfss->client->cl_timeout->to_retries ||
1578 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1579 data->acregmin != nfss->acregmin / HZ ||
1580 data->acregmax != nfss->acregmax / HZ ||
1581 data->acdirmin != nfss->acdirmin / HZ ||
1582 data->acdirmax != nfss->acdirmax / HZ ||
1583 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1584 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1585 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1586 data->nfs_server.addrlen) != 0)
1587 return -EINVAL;
1588
1589 return 0;
1590}
1591
1592static int
1593nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1594{
1595 int error;
1596 struct nfs_server *nfss = sb->s_fs_info;
1597 struct nfs_parsed_mount_data *data;
1598 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1599 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001600 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001601
1602 /*
1603 * Userspace mount programs that send binary options generally send
1604 * them populated with default values. We have no way to know which
1605 * ones were explicitly specified. Fall back to legacy behavior and
1606 * just return success.
1607 */
Trond Myklebustcd100722008-06-17 16:12:00 -04001608 if ((nfsvers == 4 && options4->version == 1) ||
1609 (nfsvers <= 3 && options->version >= 1 &&
Jeff Layton48b605f2008-06-10 15:38:39 -04001610 options->version <= 6))
1611 return 0;
1612
1613 data = kzalloc(sizeof(*data), GFP_KERNEL);
1614 if (data == NULL)
1615 return -ENOMEM;
1616
1617 /* fill out struct with values from existing mount */
1618 data->flags = nfss->flags;
1619 data->rsize = nfss->rsize;
1620 data->wsize = nfss->wsize;
1621 data->retrans = nfss->client->cl_timeout->to_retries;
1622 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1623 data->acregmin = nfss->acregmin / HZ;
1624 data->acregmax = nfss->acregmax / HZ;
1625 data->acdirmin = nfss->acdirmin / HZ;
1626 data->acdirmax = nfss->acdirmax / HZ;
1627 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1628 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1629 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1630 data->nfs_server.addrlen);
1631
1632 /* overwrite those values with any that were specified */
1633 error = nfs_parse_mount_options((char *)options, data);
1634 if (error < 0)
1635 goto out;
1636
1637 /* compare new mount options with old ones */
1638 error = nfs_compare_remount_data(nfss, data);
1639out:
1640 kfree(data);
1641 return error;
1642}
1643
David Howells54ceac42006-08-22 20:06:13 -04001644/*
1645 * Initialise the common bits of the superblock
1646 */
1647static inline void nfs_initialise_sb(struct super_block *sb)
1648{
1649 struct nfs_server *server = NFS_SB(sb);
1650
1651 sb->s_magic = NFS_SUPER_MAGIC;
1652
1653 /* We probably want something more informative here */
1654 snprintf(sb->s_id, sizeof(sb->s_id),
1655 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1656
1657 if (sb->s_blocksize == 0)
1658 sb->s_blocksize = nfs_block_bits(server->wsize,
1659 &sb->s_blocksize_bits);
1660
1661 if (server->flags & NFS_MOUNT_NOAC)
1662 sb->s_flags |= MS_SYNCHRONOUS;
1663
1664 nfs_super_set_maxbytes(sb, server->maxfilesize);
1665}
1666
1667/*
1668 * Finish setting up an NFS2/3 superblock
1669 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001670static void nfs_fill_super(struct super_block *sb,
1671 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001672{
1673 struct nfs_server *server = NFS_SB(sb);
1674
1675 sb->s_blocksize_bits = 0;
1676 sb->s_blocksize = 0;
1677 if (data->bsize)
1678 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1679
1680 if (server->flags & NFS_MOUNT_VER3) {
1681 /* The VFS shouldn't apply the umask to mode bits. We will do
1682 * so ourselves when necessary.
1683 */
1684 sb->s_flags |= MS_POSIXACL;
1685 sb->s_time_gran = 1;
1686 }
1687
1688 sb->s_op = &nfs_sops;
1689 nfs_initialise_sb(sb);
1690}
1691
1692/*
1693 * Finish setting up a cloned NFS2/3 superblock
1694 */
1695static void nfs_clone_super(struct super_block *sb,
1696 const struct super_block *old_sb)
1697{
1698 struct nfs_server *server = NFS_SB(sb);
1699
1700 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1701 sb->s_blocksize = old_sb->s_blocksize;
1702 sb->s_maxbytes = old_sb->s_maxbytes;
1703
1704 if (server->flags & NFS_MOUNT_VER3) {
1705 /* The VFS shouldn't apply the umask to mode bits. We will do
1706 * so ourselves when necessary.
1707 */
1708 sb->s_flags |= MS_POSIXACL;
1709 sb->s_time_gran = 1;
1710 }
1711
1712 sb->s_op = old_sb->s_op;
1713 nfs_initialise_sb(sb);
1714}
1715
Trond Myklebust275a5d22007-05-16 16:53:28 -04001716#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1717
1718static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1719{
1720 const struct nfs_server *a = s->s_fs_info;
1721 const struct rpc_clnt *clnt_a = a->client;
1722 const struct rpc_clnt *clnt_b = b->client;
1723
1724 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1725 goto Ebusy;
1726 if (a->nfs_client != b->nfs_client)
1727 goto Ebusy;
1728 if (a->flags != b->flags)
1729 goto Ebusy;
1730 if (a->wsize != b->wsize)
1731 goto Ebusy;
1732 if (a->rsize != b->rsize)
1733 goto Ebusy;
1734 if (a->acregmin != b->acregmin)
1735 goto Ebusy;
1736 if (a->acregmax != b->acregmax)
1737 goto Ebusy;
1738 if (a->acdirmin != b->acdirmin)
1739 goto Ebusy;
1740 if (a->acdirmax != b->acdirmax)
1741 goto Ebusy;
1742 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1743 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001744 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001745Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001746 return 0;
1747}
1748
1749struct nfs_sb_mountdata {
1750 struct nfs_server *server;
1751 int mntflags;
1752};
1753
1754static int nfs_set_super(struct super_block *s, void *data)
1755{
1756 struct nfs_sb_mountdata *sb_mntdata = data;
1757 struct nfs_server *server = sb_mntdata->server;
1758 int ret;
1759
1760 s->s_flags = sb_mntdata->mntflags;
1761 s->s_fs_info = server;
1762 ret = set_anon_super(s, server);
1763 if (ret == 0)
1764 server->s_dev = s->s_dev;
1765 return ret;
1766}
1767
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001768static int nfs_compare_super_address(struct nfs_server *server1,
1769 struct nfs_server *server2)
1770{
1771 struct sockaddr *sap1, *sap2;
1772
1773 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1774 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1775
1776 if (sap1->sa_family != sap2->sa_family)
1777 return 0;
1778
1779 switch (sap1->sa_family) {
1780 case AF_INET: {
1781 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1782 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1783 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1784 return 0;
1785 if (sin1->sin_port != sin2->sin_port)
1786 return 0;
1787 break;
1788 }
1789 case AF_INET6: {
1790 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1791 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1792 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1793 return 0;
1794 if (sin1->sin6_port != sin2->sin6_port)
1795 return 0;
1796 break;
1797 }
1798 default:
1799 return 0;
1800 }
1801
1802 return 1;
1803}
1804
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001805static int nfs_compare_super(struct super_block *sb, void *data)
1806{
1807 struct nfs_sb_mountdata *sb_mntdata = data;
1808 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1809 int mntflags = sb_mntdata->mntflags;
1810
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001811 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001812 return 0;
1813 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1814 if (old->flags & NFS_MOUNT_UNSHARED)
1815 return 0;
1816 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1817 return 0;
1818 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001819}
1820
Miklos Szeredifa799752008-04-30 00:54:33 -07001821static int nfs_bdi_register(struct nfs_server *server)
1822{
1823 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1824}
1825
David Howells54ceac42006-08-22 20:06:13 -04001826static int nfs_get_sb(struct file_system_type *fs_type,
1827 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1828{
1829 struct nfs_server *server = NULL;
1830 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001831 struct nfs_parsed_mount_data *data;
1832 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001833 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001834 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001835 struct nfs_sb_mountdata sb_mntdata = {
1836 .mntflags = flags,
1837 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001838 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001839
Trond Myklebust33852a12008-06-19 14:20:11 -04001840 data = kzalloc(sizeof(*data), GFP_KERNEL);
1841 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1842 if (data == NULL || mntfh == NULL)
1843 goto out_free_fh;
1844
1845 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001846
David Howells54ceac42006-08-22 20:06:13 -04001847 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04001848 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001849 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001850 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001851
1852 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001853 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001854 if (IS_ERR(server)) {
1855 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001856 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001857 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001858 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001859
Trond Myklebust75180df2007-05-16 16:53:28 -04001860 if (server->flags & NFS_MOUNT_UNSHARED)
1861 compare_super = NULL;
1862
David Howells54ceac42006-08-22 20:06:13 -04001863 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001864 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001865 if (IS_ERR(s)) {
1866 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001867 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001868 }
1869
David Howells54ceac42006-08-22 20:06:13 -04001870 if (s->s_fs_info != server) {
1871 nfs_free_server(server);
1872 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07001873 } else {
1874 error = nfs_bdi_register(server);
1875 if (error)
1876 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001877 }
David Howells54ceac42006-08-22 20:06:13 -04001878
1879 if (!s->s_root) {
1880 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001881 nfs_fill_super(s, data);
David Howells54ceac42006-08-22 20:06:13 -04001882 }
1883
Trond Myklebust33852a12008-06-19 14:20:11 -04001884 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001885 if (IS_ERR(mntroot)) {
1886 error = PTR_ERR(mntroot);
1887 goto error_splat_super;
1888 }
1889
Trond Myklebust33852a12008-06-19 14:20:11 -04001890 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001891 if (error)
1892 goto error_splat_root;
1893
David Howellsf7b422b2006-06-09 09:34:33 -04001894 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001895 mnt->mnt_sb = s;
1896 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001897 error = 0;
1898
1899out:
Trond Myklebust33852a12008-06-19 14:20:11 -04001900 kfree(data->nfs_server.hostname);
1901 kfree(data->mount_server.hostname);
1902 security_free_mnt_opts(&data->lsm_opts);
1903out_free_fh:
1904 kfree(mntfh);
1905 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04001906 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001907
David Howells54ceac42006-08-22 20:06:13 -04001908out_err_nosb:
1909 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001910 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001911
Eric Parisf9c3a382008-03-05 14:20:18 -05001912error_splat_root:
1913 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04001914error_splat_super:
1915 up_write(&s->s_umount);
1916 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001917 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001918}
1919
David Howells54ceac42006-08-22 20:06:13 -04001920/*
1921 * Destroy an NFS2/3 superblock
1922 */
David Howellsf7b422b2006-06-09 09:34:33 -04001923static void nfs_kill_super(struct super_block *s)
1924{
1925 struct nfs_server *server = NFS_SB(s);
1926
Miklos Szeredifa799752008-04-30 00:54:33 -07001927 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04001928 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001929 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001930}
1931
David Howells54ceac42006-08-22 20:06:13 -04001932/*
1933 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1934 */
1935static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1936 const char *dev_name, void *raw_data,
1937 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001938{
1939 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001940 struct super_block *s;
1941 struct nfs_server *server;
1942 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001943 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001944 struct nfs_sb_mountdata sb_mntdata = {
1945 .mntflags = flags,
1946 };
David Howells54ceac42006-08-22 20:06:13 -04001947 int error;
1948
1949 dprintk("--> nfs_xdev_get_sb()\n");
1950
1951 /* create a new volume representation */
1952 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1953 if (IS_ERR(server)) {
1954 error = PTR_ERR(server);
1955 goto out_err_noserver;
1956 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001957 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001958
Trond Myklebust75180df2007-05-16 16:53:28 -04001959 if (server->flags & NFS_MOUNT_UNSHARED)
1960 compare_super = NULL;
1961
David Howells54ceac42006-08-22 20:06:13 -04001962 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001963 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001964 if (IS_ERR(s)) {
1965 error = PTR_ERR(s);
1966 goto out_err_nosb;
1967 }
1968
1969 if (s->s_fs_info != server) {
1970 nfs_free_server(server);
1971 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07001972 } else {
1973 error = nfs_bdi_register(server);
1974 if (error)
1975 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04001976 }
1977
1978 if (!s->s_root) {
1979 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001980 nfs_clone_super(s, data->sb);
1981 }
1982
1983 mntroot = nfs_get_root(s, data->fh);
1984 if (IS_ERR(mntroot)) {
1985 error = PTR_ERR(mntroot);
1986 goto error_splat_super;
1987 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001988 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001989 dput(mntroot);
1990 error = -ESTALE;
1991 goto error_splat_super;
1992 }
David Howells54ceac42006-08-22 20:06:13 -04001993
1994 s->s_flags |= MS_ACTIVE;
1995 mnt->mnt_sb = s;
1996 mnt->mnt_root = mntroot;
1997
Eric Parisf9c3a382008-03-05 14:20:18 -05001998 /* clone any lsm security options from the parent to the new sb */
1999 security_sb_clone_mnt_opts(data->sb, s);
2000
David Howells54ceac42006-08-22 20:06:13 -04002001 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2002 return 0;
2003
2004out_err_nosb:
2005 nfs_free_server(server);
2006out_err_noserver:
2007 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2008 return error;
2009
2010error_splat_super:
2011 up_write(&s->s_umount);
2012 deactivate_super(s);
2013 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2014 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002015}
2016
2017#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002018
2019/*
2020 * Finish setting up a cloned NFS4 superblock
2021 */
2022static void nfs4_clone_super(struct super_block *sb,
2023 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002024{
David Howells54ceac42006-08-22 20:06:13 -04002025 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2026 sb->s_blocksize = old_sb->s_blocksize;
2027 sb->s_maxbytes = old_sb->s_maxbytes;
2028 sb->s_time_gran = 1;
2029 sb->s_op = old_sb->s_op;
2030 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002031}
2032
2033/*
2034 * Set up an NFS4 superblock
2035 */
David Howells54ceac42006-08-22 20:06:13 -04002036static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002037{
David Howellsf7b422b2006-06-09 09:34:33 -04002038 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002039 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002040 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002041}
2042
David Howells54ceac42006-08-22 20:06:13 -04002043/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002044 * Validate NFSv4 mount options
2045 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002046static int nfs4_validate_mount_data(void *options,
2047 struct nfs_parsed_mount_data *args,
2048 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002049{
Chuck Lever4c568012007-12-10 14:59:28 -05002050 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002051 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002052 char *c;
2053
2054 if (data == NULL)
2055 goto out_no_data;
2056
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002057 args->rsize = NFS_MAX_FILE_IO_SIZE;
2058 args->wsize = NFS_MAX_FILE_IO_SIZE;
2059 args->timeo = 600;
2060 args->retrans = 2;
2061 args->acregmin = 3;
2062 args->acregmax = 60;
2063 args->acdirmin = 30;
2064 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002065 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04002066 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002067
Chuck Leverf0768eb2007-07-01 12:13:01 -04002068 switch (data->version) {
2069 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002070 ap = (struct sockaddr_in *)&args->nfs_server.address;
2071 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002072 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002073 if (data->host_addrlen == 0)
2074 goto out_no_address;
2075 args->nfs_server.addrlen = data->host_addrlen;
2076 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002077 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002078 if (!nfs_verify_server_address((struct sockaddr *)
2079 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002080 goto out_no_address;
2081
2082 switch (data->auth_flavourlen) {
2083 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002084 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002085 break;
2086 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04002087 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002088 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002089 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002090 return -EFAULT;
2091 break;
2092 default:
2093 goto out_inval_auth;
2094 }
2095
2096 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2097 if (IS_ERR(c))
2098 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002099 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002100
2101 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2102 if (IS_ERR(c))
2103 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002104 args->nfs_server.export_path = c;
2105 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002106
2107 c = strndup_user(data->client_addr.data, 16);
2108 if (IS_ERR(c))
2109 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002110 args->client_address = c;
2111
2112 /*
2113 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2114 * can deal with.
2115 */
2116
2117 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2118 args->rsize = data->rsize;
2119 args->wsize = data->wsize;
2120 args->timeo = data->timeo;
2121 args->retrans = data->retrans;
2122 args->acregmin = data->acregmin;
2123 args->acregmax = data->acregmax;
2124 args->acdirmin = data->acdirmin;
2125 args->acdirmax = data->acdirmax;
2126 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002127
2128 break;
Chuck Lever80071222007-07-01 12:13:59 -04002129 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002130 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002131
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002132 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002133 return -EINVAL;
2134
2135 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002136 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002137 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002138
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002139 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04002140 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002141 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04002142 break;
2143 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04002144 break;
2145 default:
2146 goto out_inval_auth;
2147 }
2148
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002149 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002150 goto out_no_client_address;
2151
Chuck Leverdc045892008-06-23 12:36:37 -04002152 status = nfs_parse_devname(dev_name,
2153 &args->nfs_server.hostname,
2154 NFS4_MAXNAMLEN,
2155 &args->nfs_server.export_path,
2156 NFS4_MAXPATHLEN);
2157 if (status < 0)
2158 return status;
2159
Chuck Lever80071222007-07-01 12:13:59 -04002160 break;
2161 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002162 }
2163
2164 return 0;
2165
2166out_no_data:
2167 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2168 return -EINVAL;
2169
2170out_inval_auth:
2171 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2172 data->auth_flavourlen);
2173 return -EINVAL;
2174
2175out_no_address:
2176 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2177 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002178
2179out_no_client_address:
2180 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2181 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002182}
2183
2184/*
David Howells54ceac42006-08-22 20:06:13 -04002185 * Get the superblock for an NFS4 mountpoint
2186 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002187static int nfs4_get_sb(struct file_system_type *fs_type,
2188 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002189{
Trond Myklebust33852a12008-06-19 14:20:11 -04002190 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002191 struct super_block *s;
2192 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002193 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002194 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002195 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002196 struct nfs_sb_mountdata sb_mntdata = {
2197 .mntflags = flags,
2198 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002199 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002200
Trond Myklebust33852a12008-06-19 14:20:11 -04002201 data = kzalloc(sizeof(*data), GFP_KERNEL);
2202 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2203 if (data == NULL || mntfh == NULL)
2204 goto out_free_fh;
2205
2206 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002207
Chuck Leverf0768eb2007-07-01 12:13:01 -04002208 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002209 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002210 if (error < 0)
2211 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002212
David Howells54ceac42006-08-22 20:06:13 -04002213 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002214 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002215 if (IS_ERR(server)) {
2216 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002217 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002218 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002219 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002220
Trond Myklebust75180df2007-05-16 16:53:28 -04002221 if (server->flags & NFS4_MOUNT_UNSHARED)
2222 compare_super = NULL;
2223
David Howells54ceac42006-08-22 20:06:13 -04002224 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002225 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002226 if (IS_ERR(s)) {
2227 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002228 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002229 }
2230
Trond Myklebust5dd31772006-08-24 01:03:05 -04002231 if (s->s_fs_info != server) {
2232 nfs_free_server(server);
2233 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002234 } else {
2235 error = nfs_bdi_register(server);
2236 if (error)
2237 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002238 }
2239
David Howells54ceac42006-08-22 20:06:13 -04002240 if (!s->s_root) {
2241 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002242 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04002243 }
David Howellsf7b422b2006-06-09 09:34:33 -04002244
Trond Myklebust33852a12008-06-19 14:20:11 -04002245 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002246 if (IS_ERR(mntroot)) {
2247 error = PTR_ERR(mntroot);
2248 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002249 }
David Howells54ceac42006-08-22 20:06:13 -04002250
Trond Myklebust33852a12008-06-19 14:20:11 -04002251 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002252 if (error)
2253 goto error_splat_root;
2254
David Howellsf7b422b2006-06-09 09:34:33 -04002255 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002256 mnt->mnt_sb = s;
2257 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002258 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002259
Chuck Lever29eb9812007-07-01 12:12:30 -04002260out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002261 kfree(data->client_address);
2262 kfree(data->nfs_server.export_path);
2263 kfree(data->nfs_server.hostname);
2264 security_free_mnt_opts(&data->lsm_opts);
2265out_free_fh:
2266 kfree(mntfh);
2267 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002268 return error;
David Howells54ceac42006-08-22 20:06:13 -04002269
Chuck Lever29eb9812007-07-01 12:12:30 -04002270out_free:
2271 nfs_free_server(server);
2272 goto out;
2273
Eric Paris46c8ac72008-05-02 13:42:42 -07002274error_splat_root:
2275 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002276error_splat_super:
2277 up_write(&s->s_umount);
2278 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002279 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002280}
2281
2282static void nfs4_kill_super(struct super_block *sb)
2283{
2284 struct nfs_server *server = NFS_SB(sb);
2285
2286 nfs_return_all_delegations(sb);
2287 kill_anon_super(sb);
2288
2289 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002290 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002291}
2292
2293/*
David Howells54ceac42006-08-22 20:06:13 -04002294 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002295 */
David Howells54ceac42006-08-22 20:06:13 -04002296static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2297 const char *dev_name, void *raw_data,
2298 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002299{
2300 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002301 struct super_block *s;
2302 struct nfs_server *server;
2303 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002304 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002305 struct nfs_sb_mountdata sb_mntdata = {
2306 .mntflags = flags,
2307 };
David Howells54ceac42006-08-22 20:06:13 -04002308 int error;
2309
2310 dprintk("--> nfs4_xdev_get_sb()\n");
2311
2312 /* create a new volume representation */
2313 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2314 if (IS_ERR(server)) {
2315 error = PTR_ERR(server);
2316 goto out_err_noserver;
2317 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002318 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002319
Trond Myklebust75180df2007-05-16 16:53:28 -04002320 if (server->flags & NFS4_MOUNT_UNSHARED)
2321 compare_super = NULL;
2322
David Howells54ceac42006-08-22 20:06:13 -04002323 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002324 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002325 if (IS_ERR(s)) {
2326 error = PTR_ERR(s);
2327 goto out_err_nosb;
2328 }
2329
2330 if (s->s_fs_info != server) {
2331 nfs_free_server(server);
2332 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002333 } else {
2334 error = nfs_bdi_register(server);
2335 if (error)
2336 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002337 }
2338
2339 if (!s->s_root) {
2340 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002341 nfs4_clone_super(s, data->sb);
2342 }
2343
2344 mntroot = nfs4_get_root(s, data->fh);
2345 if (IS_ERR(mntroot)) {
2346 error = PTR_ERR(mntroot);
2347 goto error_splat_super;
2348 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002349 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2350 dput(mntroot);
2351 error = -ESTALE;
2352 goto error_splat_super;
2353 }
David Howells54ceac42006-08-22 20:06:13 -04002354
2355 s->s_flags |= MS_ACTIVE;
2356 mnt->mnt_sb = s;
2357 mnt->mnt_root = mntroot;
2358
Eric Paris46c8ac72008-05-02 13:42:42 -07002359 security_sb_clone_mnt_opts(data->sb, s);
2360
David Howells54ceac42006-08-22 20:06:13 -04002361 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2362 return 0;
2363
2364out_err_nosb:
2365 nfs_free_server(server);
2366out_err_noserver:
2367 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2368 return error;
2369
2370error_splat_super:
2371 up_write(&s->s_umount);
2372 deactivate_super(s);
2373 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2374 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002375}
2376
David Howells54ceac42006-08-22 20:06:13 -04002377/*
2378 * Create an NFS4 server record on referral traversal
2379 */
2380static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2381 const char *dev_name, void *raw_data,
2382 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002383{
2384 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002385 struct super_block *s;
2386 struct nfs_server *server;
2387 struct dentry *mntroot;
2388 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002389 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002390 struct nfs_sb_mountdata sb_mntdata = {
2391 .mntflags = flags,
2392 };
David Howells54ceac42006-08-22 20:06:13 -04002393 int error;
2394
2395 dprintk("--> nfs4_referral_get_sb()\n");
2396
2397 /* create a new volume representation */
2398 server = nfs4_create_referral_server(data, &mntfh);
2399 if (IS_ERR(server)) {
2400 error = PTR_ERR(server);
2401 goto out_err_noserver;
2402 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002403 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002404
Trond Myklebust75180df2007-05-16 16:53:28 -04002405 if (server->flags & NFS4_MOUNT_UNSHARED)
2406 compare_super = NULL;
2407
David Howells54ceac42006-08-22 20:06:13 -04002408 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002409 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002410 if (IS_ERR(s)) {
2411 error = PTR_ERR(s);
2412 goto out_err_nosb;
2413 }
2414
2415 if (s->s_fs_info != server) {
2416 nfs_free_server(server);
2417 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002418 } else {
2419 error = nfs_bdi_register(server);
2420 if (error)
2421 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002422 }
2423
2424 if (!s->s_root) {
2425 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002426 nfs4_fill_super(s);
2427 }
2428
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002429 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002430 if (IS_ERR(mntroot)) {
2431 error = PTR_ERR(mntroot);
2432 goto error_splat_super;
2433 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002434 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2435 dput(mntroot);
2436 error = -ESTALE;
2437 goto error_splat_super;
2438 }
David Howells54ceac42006-08-22 20:06:13 -04002439
2440 s->s_flags |= MS_ACTIVE;
2441 mnt->mnt_sb = s;
2442 mnt->mnt_root = mntroot;
2443
Eric Paris46c8ac72008-05-02 13:42:42 -07002444 security_sb_clone_mnt_opts(data->sb, s);
2445
David Howells54ceac42006-08-22 20:06:13 -04002446 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2447 return 0;
2448
2449out_err_nosb:
2450 nfs_free_server(server);
2451out_err_noserver:
2452 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2453 return error;
2454
2455error_splat_super:
2456 up_write(&s->s_umount);
2457 deactivate_super(s);
2458 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2459 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002460}
2461
David Howells54ceac42006-08-22 20:06:13 -04002462#endif /* CONFIG_NFS_V4 */