blob: 2f7e7f20c91770a1a2450eb62a228386595c05f1 [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>
Chuck Leverd8e77482008-06-23 12:37:01 -040050#include <linux/netdevice.h>
David Howellsf7b422b2006-06-09 09:34:33 -040051#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080052#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040053#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040054
55#include <asm/system.h>
56#include <asm/uaccess.h>
57
58#include "nfs4_fs.h"
59#include "callback.h"
60#include "delegation.h"
61#include "iostat.h"
62#include "internal.h"
63
64#define NFSDBG_FACILITY NFSDBG_VFS
65
Chuck Leverbf0fd762007-07-01 12:13:44 -040066enum {
67 /* Mount options that take no arguments */
68 Opt_soft, Opt_hard,
Chuck Leverbf0fd762007-07-01 12:13:44 -040069 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac,
72 Opt_lock, Opt_nolock,
73 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040074 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075 Opt_acl, Opt_noacl,
76 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040077 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078
79 /* Mount options that take integer arguments */
80 Opt_port,
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
85 Opt_actimeo,
86 Opt_namelen,
87 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040088 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040089 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050092 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040093 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
97
98 Opt_err
99};
100
101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400104 { Opt_userspace, "retry=%s" },
105
Chuck Leverbf0fd762007-07-01 12:13:44 -0400106 { Opt_soft, "soft" },
107 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400108 { Opt_deprecated, "intr" },
109 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400110 { Opt_posix, "posix" },
111 { Opt_noposix, "noposix" },
112 { Opt_cto, "cto" },
113 { Opt_nocto, "nocto" },
114 { Opt_ac, "ac" },
115 { Opt_noac, "noac" },
116 { Opt_lock, "lock" },
117 { Opt_nolock, "nolock" },
118 { Opt_v2, "v2" },
119 { Opt_v3, "v3" },
120 { Opt_udp, "udp" },
121 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400122 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400123 { Opt_acl, "acl" },
124 { Opt_noacl, "noacl" },
125 { Opt_rdirplus, "rdirplus" },
126 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400127 { Opt_sharecache, "sharecache" },
128 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400129
130 { Opt_port, "port=%u" },
131 { Opt_rsize, "rsize=%u" },
132 { Opt_wsize, "wsize=%u" },
133 { Opt_bsize, "bsize=%u" },
134 { Opt_timeo, "timeo=%u" },
135 { Opt_retrans, "retrans=%u" },
136 { Opt_acregmin, "acregmin=%u" },
137 { Opt_acregmax, "acregmax=%u" },
138 { Opt_acdirmin, "acdirmin=%u" },
139 { Opt_acdirmax, "acdirmax=%u" },
140 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400141 { Opt_namelen, "namlen=%u" },
142 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144 { Opt_nfsvers, "nfsvers=%u" },
145 { Opt_nfsvers, "vers=%u" },
146
147 { Opt_sec, "sec=%s" },
148 { Opt_proto, "proto=%s" },
149 { Opt_mountproto, "mountproto=%s" },
150 { Opt_addr, "addr=%s" },
151 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500152 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400153 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400154
155 { Opt_err, NULL }
156};
157
158enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400159 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400160
161 Opt_xprt_err
162};
163
164static match_table_t nfs_xprt_protocol_tokens = {
165 { Opt_xprt_udp, "udp" },
166 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400167 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400168
169 { Opt_xprt_err, NULL }
170};
171
172enum {
173 Opt_sec_none, Opt_sec_sys,
174 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
175 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
176 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
177
178 Opt_sec_err
179};
180
181static match_table_t nfs_secflavor_tokens = {
182 { Opt_sec_none, "none" },
183 { Opt_sec_none, "null" },
184 { Opt_sec_sys, "sys" },
185
186 { Opt_sec_krb5, "krb5" },
187 { Opt_sec_krb5i, "krb5i" },
188 { Opt_sec_krb5p, "krb5p" },
189
190 { Opt_sec_lkey, "lkey" },
191 { Opt_sec_lkeyi, "lkeyi" },
192 { Opt_sec_lkeyp, "lkeyp" },
193
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500194 { Opt_sec_spkm, "spkm3" },
195 { Opt_sec_spkmi, "spkm3i" },
196 { Opt_sec_spkmp, "spkm3p" },
197
Chuck Leverbf0fd762007-07-01 12:13:44 -0400198 { Opt_sec_err, NULL }
199};
200
201
Al Viro42faad92008-04-24 07:21:56 -0400202static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400203static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400204static int nfs_show_options(struct seq_file *, struct vfsmount *);
205static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400206static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400207static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400208 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400209static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500210static void nfs_put_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400211static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400212
213static struct file_system_type nfs_fs_type = {
214 .owner = THIS_MODULE,
215 .name = "nfs",
216 .get_sb = nfs_get_sb,
217 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700218 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400219};
220
David Howells54ceac42006-08-22 20:06:13 -0400221struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400222 .owner = THIS_MODULE,
223 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400224 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400225 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700226 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400227};
228
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800229static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400230 .alloc_inode = nfs_alloc_inode,
231 .destroy_inode = nfs_destroy_inode,
232 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500233 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400234 .statfs = nfs_statfs,
235 .clear_inode = nfs_clear_inode,
236 .umount_begin = nfs_umount_begin,
237 .show_options = nfs_show_options,
238 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400239 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400240};
241
242#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400243static int nfs4_get_sb(struct file_system_type *fs_type,
244 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400245static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
246 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
247static int nfs4_referral_get_sb(struct file_system_type *fs_type,
248 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400249static void nfs4_kill_super(struct super_block *sb);
250
251static struct file_system_type nfs4_fs_type = {
252 .owner = THIS_MODULE,
253 .name = "nfs4",
254 .get_sb = nfs4_get_sb,
255 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700256 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400257};
258
David Howells54ceac42006-08-22 20:06:13 -0400259struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400260 .owner = THIS_MODULE,
261 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400262 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400263 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700264 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400265};
266
David Howells54ceac42006-08-22 20:06:13 -0400267struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400268 .owner = THIS_MODULE,
269 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400270 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400271 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700272 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400273};
274
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800275static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400276 .alloc_inode = nfs_alloc_inode,
277 .destroy_inode = nfs_destroy_inode,
278 .write_inode = nfs_write_inode,
279 .statfs = nfs_statfs,
280 .clear_inode = nfs4_clear_inode,
281 .umount_begin = nfs_umount_begin,
282 .show_options = nfs_show_options,
283 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400284 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400285};
286#endif
287
Rusty Russell8e1f9362007-07-17 04:03:17 -0700288static struct shrinker acl_shrinker = {
289 .shrink = nfs_access_cache_shrinker,
290 .seeks = DEFAULT_SEEKS,
291};
Trond Myklebust979df722006-07-25 11:28:19 -0400292
David Howellsf7b422b2006-06-09 09:34:33 -0400293/*
294 * Register the NFS filesystems
295 */
296int __init register_nfs_fs(void)
297{
298 int ret;
299
300 ret = register_filesystem(&nfs_fs_type);
301 if (ret < 0)
302 goto error_0;
303
David Howellsf7b422b2006-06-09 09:34:33 -0400304 ret = nfs_register_sysctl();
305 if (ret < 0)
306 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800307#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400308 ret = register_filesystem(&nfs4_fs_type);
309 if (ret < 0)
310 goto error_2;
311#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700312 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400313 return 0;
314
315#ifdef CONFIG_NFS_V4
316error_2:
317 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800318#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400319error_1:
320 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400321error_0:
322 return ret;
323}
324
325/*
326 * Unregister the NFS filesystems
327 */
328void __exit unregister_nfs_fs(void)
329{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700330 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400331#ifdef CONFIG_NFS_V4
332 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400333#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700334 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400335 unregister_filesystem(&nfs_fs_type);
336}
337
Steve Dicksonef818a22007-11-08 04:05:04 -0500338void nfs_sb_active(struct nfs_server *server)
339{
340 atomic_inc(&server->active);
341}
342
343void nfs_sb_deactive(struct nfs_server *server)
344{
345 if (atomic_dec_and_test(&server->active))
346 wake_up(&server->active_wq);
347}
348
349static void nfs_put_super(struct super_block *sb)
350{
351 struct nfs_server *server = NFS_SB(sb);
352 /*
353 * Make sure there are no outstanding ops to this server.
354 * If so, wait for them to finish before allowing the
355 * unmount to continue.
356 */
357 wait_event(server->active_wq, atomic_read(&server->active) == 0);
358}
359
David Howellsf7b422b2006-06-09 09:34:33 -0400360/*
361 * Deliver file system statistics to userspace
362 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400363static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400364{
David Howells0c7d90c2006-08-22 20:06:10 -0400365 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400366 unsigned char blockbits;
367 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400368 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400369 struct nfs_fattr fattr;
370 struct nfs_fsstat res = {
371 .fattr = &fattr,
372 };
373 int error;
374
375 lock_kernel();
376
David Howells8fa5c002006-08-22 20:06:12 -0400377 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400378 if (error < 0)
379 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700380 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400381
382 /*
383 * Current versions of glibc do not correctly handle the
384 * case where f_frsize != f_bsize. Eventually we want to
385 * report the value of wtmult in this field.
386 */
David Howells0c7d90c2006-08-22 20:06:10 -0400387 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400388
389 /*
390 * On most *nix systems, f_blocks, f_bfree, and f_bavail
391 * are reported in units of f_frsize. Linux hasn't had
392 * an f_frsize field in its statfs struct until recently,
393 * thus historically Linux's sys_statfs reports these
394 * fields in units of f_bsize.
395 */
David Howells0c7d90c2006-08-22 20:06:10 -0400396 buf->f_bsize = dentry->d_sb->s_blocksize;
397 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400398 blockres = (1 << blockbits) - 1;
399 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
400 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
401 buf->f_bavail = (res.abytes + blockres) >> blockbits;
402
403 buf->f_files = res.tfiles;
404 buf->f_ffree = res.afiles;
405
406 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700407
David Howellsf7b422b2006-06-09 09:34:33 -0400408 unlock_kernel();
409 return 0;
410
411 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700412 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700413 unlock_kernel();
414 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400415}
416
David Howells7d4e2742006-08-22 20:06:07 -0400417/*
418 * Map the security flavour number to a name
419 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400420static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
421{
David Howells7d4e2742006-08-22 20:06:07 -0400422 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400423 rpc_authflavor_t flavour;
424 const char *str;
425 } sec_flavours[] = {
426 { RPC_AUTH_NULL, "null" },
427 { RPC_AUTH_UNIX, "sys" },
428 { RPC_AUTH_GSS_KRB5, "krb5" },
429 { RPC_AUTH_GSS_KRB5I, "krb5i" },
430 { RPC_AUTH_GSS_KRB5P, "krb5p" },
431 { RPC_AUTH_GSS_LKEY, "lkey" },
432 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
433 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
434 { RPC_AUTH_GSS_SPKM, "spkm" },
435 { RPC_AUTH_GSS_SPKMI, "spkmi" },
436 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400437 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400438 };
439 int i;
440
Chuck Lever4d81cd12007-07-01 12:12:40 -0400441 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400442 if (sec_flavours[i].flavour == flavour)
443 break;
444 }
445 return sec_flavours[i].str;
446}
447
Chuck Lever82d101d2008-03-14 14:10:37 -0400448static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
449 int showdefaults)
450{
451 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
452
453 switch (sap->sa_family) {
454 case AF_INET: {
455 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
456 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
457 NIPQUAD(sin->sin_addr.s_addr));
458 break;
459 }
460 case AF_INET6: {
461 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
462 seq_printf(m, ",mountaddr=" NIP6_FMT,
463 NIP6(sin6->sin6_addr));
464 break;
465 }
466 default:
467 if (showdefaults)
468 seq_printf(m, ",mountaddr=unspecified");
469 }
470
471 if (nfss->mountd_version || showdefaults)
472 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
473 if (nfss->mountd_port || showdefaults)
474 seq_printf(m, ",mountport=%u", nfss->mountd_port);
475
476 switch (nfss->mountd_protocol) {
477 case IPPROTO_UDP:
478 seq_printf(m, ",mountproto=udp");
479 break;
480 case IPPROTO_TCP:
481 seq_printf(m, ",mountproto=tcp");
482 break;
483 default:
484 if (showdefaults)
485 seq_printf(m, ",mountproto=auto");
486 }
487}
488
David Howellsf7b422b2006-06-09 09:34:33 -0400489/*
490 * Describe the mount options in force on this server representation
491 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400492static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
493 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400494{
David Howells509de812006-08-22 20:06:11 -0400495 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400496 int flag;
David Howells509de812006-08-22 20:06:11 -0400497 const char *str;
498 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400499 } nfs_info[] = {
500 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400501 { NFS_MOUNT_INTR, ",intr", ",nointr" },
502 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400503 { NFS_MOUNT_NOCTO, ",nocto", "" },
504 { NFS_MOUNT_NOAC, ",noac", "" },
505 { NFS_MOUNT_NONLM, ",nolock", "" },
506 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400507 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400508 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400509 { 0, NULL, NULL }
510 };
David Howells509de812006-08-22 20:06:11 -0400511 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400512 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400513 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400514
Chuck Lever82d101d2008-03-14 14:10:37 -0400515 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400516 seq_printf(m, ",rsize=%u", nfss->rsize);
517 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400518 if (nfss->bsize != 0)
519 seq_printf(m, ",bsize=%u", nfss->bsize);
520 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400521 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400522 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400523 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400524 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400525 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400526 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400527 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400528 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400529 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
530 if (nfss->flags & nfs_infop->flag)
531 seq_puts(m, nfs_infop->str);
532 else
533 seq_puts(m, nfs_infop->nostr);
534 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400535 seq_printf(m, ",proto=%s",
536 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400537 if (version == 4) {
538 if (nfss->port != NFS_PORT)
539 seq_printf(m, ",port=%u", nfss->port);
540 } else
541 if (nfss->port)
542 seq_printf(m, ",port=%u", nfss->port);
543
Trond Myklebust33170232007-12-20 16:03:59 -0500544 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
545 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400546 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400547
548 if (version != 4)
549 nfs_show_mountd_options(m, nfss, showdefaults);
550
551#ifdef CONFIG_NFS_V4
552 if (clp->rpc_ops->version == 4)
553 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
554#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400555}
556
557/*
558 * Describe the mount options on this VFS mountpoint
559 */
560static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
561{
562 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
563
564 nfs_show_mount_options(m, nfss, 0);
565
Chuck Lever5d8515c2007-12-10 14:57:16 -0500566 seq_printf(m, ",addr=%s",
567 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
568 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400569
570 return 0;
571}
572
573/*
574 * Present statistical information for this VFS mountpoint
575 */
576static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
577{
578 int i, cpu;
579 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
580 struct rpc_auth *auth = nfss->client->cl_auth;
581 struct nfs_iostats totals = { };
582
583 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
584
585 /*
586 * Display all mount option settings
587 */
588 seq_printf(m, "\n\topts:\t");
589 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
590 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
591 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
592 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
593 nfs_show_mount_options(m, nfss, 1);
594
595 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
596
597 seq_printf(m, "\n\tcaps:\t");
598 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400599 seq_printf(m, ",wtmult=%u", nfss->wtmult);
600 seq_printf(m, ",dtsize=%u", nfss->dtsize);
601 seq_printf(m, ",bsize=%u", nfss->bsize);
602 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400603
604#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500605 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400606 seq_printf(m, "\n\tnfsv4:\t");
607 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
608 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
609 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
610 }
611#endif
612
613 /*
614 * Display security flavor in effect for this mount
615 */
Chuck Lever2d767432008-03-14 14:10:08 -0400616 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400617 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400618 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400619
620 /*
621 * Display superblock I/O counters
622 */
623 for_each_possible_cpu(cpu) {
624 struct nfs_iostats *stats;
625
626 preempt_disable();
627 stats = per_cpu_ptr(nfss->io_stats, cpu);
628
629 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
630 totals.events[i] += stats->events[i];
631 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
632 totals.bytes[i] += stats->bytes[i];
633
634 preempt_enable();
635 }
636
637 seq_printf(m, "\n\tevents:\t");
638 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
639 seq_printf(m, "%lu ", totals.events[i]);
640 seq_printf(m, "\n\tbytes:\t");
641 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
642 seq_printf(m, "%Lu ", totals.bytes[i]);
643 seq_printf(m, "\n");
644
645 rpc_print_iostats(m, nfss->client);
646
647 return 0;
648}
649
650/*
651 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400652 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400653 */
Al Viro42faad92008-04-24 07:21:56 -0400654static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400655{
Al Viro42faad92008-04-24 07:21:56 -0400656 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400657 struct rpc_clnt *rpc;
658
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400659 /* -EIO all pending I/O */
660 rpc = server->client_acl;
661 if (!IS_ERR(rpc))
662 rpc_killall_tasks(rpc);
663 rpc = server->client;
664 if (!IS_ERR(rpc))
665 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400666}
667
668/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500669 * Set the port number in an address. Be agnostic about the address family.
670 */
671static void nfs_set_port(struct sockaddr *sap, unsigned short port)
672{
673 switch (sap->sa_family) {
674 case AF_INET: {
675 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
676 ap->sin_port = htons(port);
677 break;
678 }
679 case AF_INET6: {
680 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
681 ap->sin6_port = htons(port);
682 break;
683 }
684 }
685}
686
687/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500688 * Sanity-check a server address provided by the mount command.
689 *
690 * Address family must be initialized, and address must not be
691 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400692 */
693static int nfs_verify_server_address(struct sockaddr *addr)
694{
695 switch (addr->sa_family) {
696 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500697 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700698 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500699 }
700 case AF_INET6: {
701 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
702 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400703 }
704 }
705
706 return 0;
707}
708
Chuck Leverce3b7e12008-06-23 12:36:53 -0400709static void nfs_parse_ipv4_address(char *string, size_t str_len,
710 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500711{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400712 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
713 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500714
Chuck Leverce3b7e12008-06-23 12:36:53 -0400715 if (str_len <= INET_ADDRSTRLEN) {
716 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
717 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500718
Chuck Leverce3b7e12008-06-23 12:36:53 -0400719 sin->sin_family = AF_INET;
720 *addr_len = sizeof(*sin);
721 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500722 return;
723 }
Chuck Lever9412b922007-12-10 14:59:21 -0500724
725 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400726 *addr_len = 0;
727}
728
Chuck Leverd8e77482008-06-23 12:37:01 -0400729#define IPV6_SCOPE_DELIMITER '%'
730
Chuck Leverce3b7e12008-06-23 12:36:53 -0400731#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Leverd8e77482008-06-23 12:37:01 -0400732static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
733 const char *delim,
734 struct sockaddr_in6 *sin6)
735{
736 char *p;
737 size_t len;
738
739 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
740 return ;
741 if (*delim != IPV6_SCOPE_DELIMITER)
742 return;
743
744 len = (string + str_len) - delim - 1;
745 p = kstrndup(delim + 1, len, GFP_KERNEL);
746 if (p) {
747 unsigned long scope_id = 0;
748 struct net_device *dev;
749
750 dev = dev_get_by_name(&init_net, p);
751 if (dev != NULL) {
752 scope_id = dev->ifindex;
753 dev_put(dev);
754 } else {
755 /* scope_id is set to zero on error */
756 strict_strtoul(p, 10, &scope_id);
757 }
758
759 kfree(p);
760 sin6->sin6_scope_id = scope_id;
761 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
762 }
763}
764
Chuck Leverce3b7e12008-06-23 12:36:53 -0400765static void nfs_parse_ipv6_address(char *string, size_t str_len,
766 struct sockaddr *sap, size_t *addr_len)
767{
768 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
769 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400770 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400771
772 if (str_len <= INET6_ADDRSTRLEN) {
773 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
774 (int)str_len, string);
775
776 sin6->sin6_family = AF_INET6;
777 *addr_len = sizeof(*sin6);
Chuck Leverd8e77482008-06-23 12:37:01 -0400778 if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
779 nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
Chuck Leverce3b7e12008-06-23 12:36:53 -0400780 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400781 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400782 }
783
784 sap->sa_family = AF_UNSPEC;
785 *addr_len = 0;
786}
787#else
788static void nfs_parse_ipv6_address(char *string, size_t str_len,
789 struct sockaddr *sap, size_t *addr_len)
790{
791 sap->sa_family = AF_UNSPEC;
792 *addr_len = 0;
793}
794#endif
795
796/*
797 * Construct a sockaddr based on the contents of a string that contains
798 * an IP address in presentation format.
799 *
800 * If there is a problem constructing the new sockaddr, set the address
801 * family to AF_UNSPEC.
802 */
803static void nfs_parse_ip_address(char *string, size_t str_len,
804 struct sockaddr *sap, size_t *addr_len)
805{
806 unsigned int i, colons;
807
808 colons = 0;
809 for (i = 0; i < str_len; i++)
810 if (string[i] == ':')
811 colons++;
812
813 if (colons >= 2)
814 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
815 else
816 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500817}
818
819/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400820 * Sanity check the NFS transport protocol.
821 *
822 */
823static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
824{
825 switch (mnt->nfs_server.protocol) {
826 case XPRT_TRANSPORT_UDP:
827 case XPRT_TRANSPORT_TCP:
828 case XPRT_TRANSPORT_RDMA:
829 break;
830 default:
831 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
832 }
833}
834
835/*
836 * For text based NFSv2/v3 mounts, the mount protocol transport default
837 * settings should depend upon the specified NFS transport.
838 */
839static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
840{
841 nfs_validate_transport_protocol(mnt);
842
843 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
844 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
845 return;
846 switch (mnt->nfs_server.protocol) {
847 case XPRT_TRANSPORT_UDP:
848 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
849 break;
850 case XPRT_TRANSPORT_TCP:
851 case XPRT_TRANSPORT_RDMA:
852 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
853 }
854}
855
856/*
Chuck Lever01060c82008-06-24 16:33:38 -0400857 * Parse the value of the 'sec=' option.
858 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400859 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400860 */
861static int nfs_parse_security_flavors(char *value,
862 struct nfs_parsed_mount_data *mnt)
863{
864 substring_t args[MAX_OPT_ARGS];
865
866 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
867
868 switch (match_token(value, nfs_secflavor_tokens, args)) {
869 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400870 mnt->auth_flavor_len = 0;
871 mnt->auth_flavors[0] = RPC_AUTH_NULL;
872 break;
873 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400874 mnt->auth_flavor_len = 0;
875 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
876 break;
877 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
880 break;
881 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400882 mnt->auth_flavor_len = 1;
883 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
884 break;
885 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400886 mnt->auth_flavor_len = 1;
887 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
888 break;
889 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400890 mnt->auth_flavor_len = 1;
891 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
892 break;
893 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400894 mnt->auth_flavor_len = 1;
895 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
896 break;
897 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400898 mnt->auth_flavor_len = 1;
899 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
900 break;
901 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400902 mnt->auth_flavor_len = 1;
903 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
904 break;
905 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400906 mnt->auth_flavor_len = 1;
907 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
908 break;
909 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400910 mnt->auth_flavor_len = 1;
911 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
912 break;
913 default:
914 return 0;
915 }
916
917 return 1;
918}
919
920/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400921 * Error-check and convert a string of mount options from user space into
922 * a data structure
923 */
924static int nfs_parse_mount_options(char *raw,
925 struct nfs_parsed_mount_data *mnt)
926{
Eric Parisf9c3a382008-03-05 14:20:18 -0500927 char *p, *string, *secdata;
Eric Parisf9c3a382008-03-05 14:20:18 -0500928 int rc;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400929
930 if (!raw) {
931 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
932 return 1;
933 }
934 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
935
Eric Parisf9c3a382008-03-05 14:20:18 -0500936 secdata = alloc_secdata();
937 if (!secdata)
938 goto out_nomem;
939
940 rc = security_sb_copy_data(raw, secdata);
941 if (rc)
942 goto out_security_failure;
943
944 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
945 if (rc)
946 goto out_security_failure;
947
948 free_secdata(secdata);
949
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950 while ((p = strsep(&raw, ",")) != NULL) {
951 substring_t args[MAX_OPT_ARGS];
952 int option, token;
953
954 if (!*p)
955 continue;
956
957 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
958
959 token = match_token(p, nfs_mount_option_tokens, args);
960 switch (token) {
961 case Opt_soft:
962 mnt->flags |= NFS_MOUNT_SOFT;
963 break;
964 case Opt_hard:
965 mnt->flags &= ~NFS_MOUNT_SOFT;
966 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400967 case Opt_posix:
968 mnt->flags |= NFS_MOUNT_POSIX;
969 break;
970 case Opt_noposix:
971 mnt->flags &= ~NFS_MOUNT_POSIX;
972 break;
973 case Opt_cto:
974 mnt->flags &= ~NFS_MOUNT_NOCTO;
975 break;
976 case Opt_nocto:
977 mnt->flags |= NFS_MOUNT_NOCTO;
978 break;
979 case Opt_ac:
980 mnt->flags &= ~NFS_MOUNT_NOAC;
981 break;
982 case Opt_noac:
983 mnt->flags |= NFS_MOUNT_NOAC;
984 break;
985 case Opt_lock:
986 mnt->flags &= ~NFS_MOUNT_NONLM;
987 break;
988 case Opt_nolock:
989 mnt->flags |= NFS_MOUNT_NONLM;
990 break;
991 case Opt_v2:
992 mnt->flags &= ~NFS_MOUNT_VER3;
993 break;
994 case Opt_v3:
995 mnt->flags |= NFS_MOUNT_VER3;
996 break;
997 case Opt_udp:
998 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400999 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001000 break;
1001 case Opt_tcp:
1002 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001003 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001004 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001005 case Opt_rdma:
1006 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1007 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001008 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001009 case Opt_acl:
1010 mnt->flags &= ~NFS_MOUNT_NOACL;
1011 break;
1012 case Opt_noacl:
1013 mnt->flags |= NFS_MOUNT_NOACL;
1014 break;
1015 case Opt_rdirplus:
1016 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1017 break;
1018 case Opt_nordirplus:
1019 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1020 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001021 case Opt_sharecache:
1022 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1023 break;
1024 case Opt_nosharecache:
1025 mnt->flags |= NFS_MOUNT_UNSHARED;
1026 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001027
1028 case Opt_port:
1029 if (match_int(args, &option))
1030 return 0;
1031 if (option < 0 || option > 65535)
1032 return 0;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001033 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001034 break;
1035 case Opt_rsize:
1036 if (match_int(args, &mnt->rsize))
1037 return 0;
1038 break;
1039 case Opt_wsize:
1040 if (match_int(args, &mnt->wsize))
1041 return 0;
1042 break;
1043 case Opt_bsize:
1044 if (match_int(args, &option))
1045 return 0;
1046 if (option < 0)
1047 return 0;
1048 mnt->bsize = option;
1049 break;
1050 case Opt_timeo:
1051 if (match_int(args, &mnt->timeo))
1052 return 0;
1053 break;
1054 case Opt_retrans:
1055 if (match_int(args, &mnt->retrans))
1056 return 0;
1057 break;
1058 case Opt_acregmin:
1059 if (match_int(args, &mnt->acregmin))
1060 return 0;
1061 break;
1062 case Opt_acregmax:
1063 if (match_int(args, &mnt->acregmax))
1064 return 0;
1065 break;
1066 case Opt_acdirmin:
1067 if (match_int(args, &mnt->acdirmin))
1068 return 0;
1069 break;
1070 case Opt_acdirmax:
1071 if (match_int(args, &mnt->acdirmax))
1072 return 0;
1073 break;
1074 case Opt_actimeo:
1075 if (match_int(args, &option))
1076 return 0;
1077 if (option < 0)
1078 return 0;
1079 mnt->acregmin =
1080 mnt->acregmax =
1081 mnt->acdirmin =
1082 mnt->acdirmax = option;
1083 break;
1084 case Opt_namelen:
1085 if (match_int(args, &mnt->namlen))
1086 return 0;
1087 break;
1088 case Opt_mountport:
1089 if (match_int(args, &option))
1090 return 0;
1091 if (option < 0 || option > 65535)
1092 return 0;
1093 mnt->mount_server.port = option;
1094 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001095 case Opt_mountvers:
1096 if (match_int(args, &option))
1097 return 0;
1098 if (option < 0)
1099 return 0;
1100 mnt->mount_server.version = option;
1101 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001102 case Opt_nfsvers:
1103 if (match_int(args, &option))
1104 return 0;
1105 switch (option) {
1106 case 2:
1107 mnt->flags &= ~NFS_MOUNT_VER3;
1108 break;
1109 case 3:
1110 mnt->flags |= NFS_MOUNT_VER3;
1111 break;
1112 default:
1113 goto out_unrec_vers;
1114 }
1115 break;
1116
1117 case Opt_sec:
1118 string = match_strdup(args);
1119 if (string == NULL)
1120 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001121 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001122 kfree(string);
Chuck Lever01060c82008-06-24 16:33:38 -04001123 if (!rc)
Chuck Leverbf0fd762007-07-01 12:13:44 -04001124 goto out_unrec_sec;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001125 break;
1126 case Opt_proto:
1127 string = match_strdup(args);
1128 if (string == NULL)
1129 goto out_nomem;
1130 token = match_token(string,
1131 nfs_xprt_protocol_tokens, args);
1132 kfree(string);
1133
1134 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001135 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001136 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001137 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001138 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001139 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001140 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001141 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001142 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001143 case Opt_xprt_rdma:
1144 /* vector side protocols to TCP */
1145 mnt->flags |= NFS_MOUNT_TCP;
1146 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001147 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001148 default:
1149 goto out_unrec_xprt;
1150 }
1151 break;
1152 case Opt_mountproto:
1153 string = match_strdup(args);
1154 if (string == NULL)
1155 goto out_nomem;
1156 token = match_token(string,
1157 nfs_xprt_protocol_tokens, args);
1158 kfree(string);
1159
1160 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001161 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001162 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001163 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001164 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001165 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001166 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001167 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001168 default:
1169 goto out_unrec_xprt;
1170 }
1171 break;
1172 case Opt_addr:
1173 string = match_strdup(args);
1174 if (string == NULL)
1175 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001176 nfs_parse_ip_address(string, strlen(string),
1177 (struct sockaddr *)
1178 &mnt->nfs_server.address,
1179 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001180 kfree(string);
1181 break;
1182 case Opt_clientaddr:
1183 string = match_strdup(args);
1184 if (string == NULL)
1185 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001186 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001187 mnt->client_address = string;
1188 break;
Chuck Lever33832032007-12-10 14:59:13 -05001189 case Opt_mounthost:
1190 string = match_strdup(args);
1191 if (string == NULL)
1192 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001193 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001194 mnt->mount_server.hostname = string;
1195 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001196 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001197 string = match_strdup(args);
1198 if (string == NULL)
1199 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001200 nfs_parse_ip_address(string, strlen(string),
1201 (struct sockaddr *)
1202 &mnt->mount_server.address,
1203 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 kfree(string);
1205 break;
1206
1207 case Opt_userspace:
1208 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001209 dfprintk(MOUNT, "NFS: ignoring mount option "
1210 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001211 break;
1212
1213 default:
1214 goto out_unknown;
1215 }
1216 }
1217
1218 return 1;
1219
1220out_nomem:
1221 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1222 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001223out_security_failure:
1224 free_secdata(secdata);
1225 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1226 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227out_unrec_vers:
1228 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1229 return 0;
1230
1231out_unrec_xprt:
1232 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1233 return 0;
1234
1235out_unrec_sec:
1236 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1237 return 0;
1238
1239out_unknown:
1240 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1241 return 0;
1242}
1243
1244/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001245 * Use the remote server's MOUNT service to request the NFS file handle
1246 * corresponding to the provided path.
1247 */
1248static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1249 struct nfs_fh *root_fh)
1250{
Chuck Lever4c568012007-12-10 14:59:28 -05001251 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001252 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001253 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001254
1255 if (args->mount_server.version == 0) {
1256 if (args->flags & NFS_MOUNT_VER3)
1257 args->mount_server.version = NFS_MNT3_VERSION;
1258 else
1259 args->mount_server.version = NFS_MNT_VERSION;
1260 }
1261
Chuck Lever33832032007-12-10 14:59:13 -05001262 if (args->mount_server.hostname)
1263 hostname = args->mount_server.hostname;
1264 else
1265 hostname = args->nfs_server.hostname;
1266
Chuck Lever0076d7b2007-07-01 12:13:49 -04001267 /*
1268 * Construct the mount server's address.
1269 */
Chuck Lever4c568012007-12-10 14:59:28 -05001270 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1271 memcpy(sap, &args->nfs_server.address,
1272 args->nfs_server.addrlen);
1273 args->mount_server.addrlen = args->nfs_server.addrlen;
1274 }
1275
James Lentiniaad70002007-09-24 17:32:49 -04001276 /*
1277 * autobind will be used if mount_server.port == 0
1278 */
Chuck Lever4c568012007-12-10 14:59:28 -05001279 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001280
1281 /*
1282 * Now ask the mount server to map our export path
1283 * to a file handle.
1284 */
Chuck Lever4c568012007-12-10 14:59:28 -05001285 status = nfs_mount(sap,
1286 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001287 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001288 args->nfs_server.export_path,
1289 args->mount_server.version,
1290 args->mount_server.protocol,
1291 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001292 if (status == 0)
1293 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001294
Chuck Lever396cee972008-06-12 12:37:49 -04001295 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Lever33832032007-12-10 14:59:13 -05001296 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001297 return status;
1298}
1299
Chuck Leverd1aa0822008-06-23 12:36:45 -04001300static int nfs_parse_simple_hostname(const char *dev_name,
1301 char **hostname, size_t maxnamlen,
1302 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001303{
1304 size_t len;
1305 char *colon, *comma;
1306
1307 colon = strchr(dev_name, ':');
1308 if (colon == NULL)
1309 goto out_bad_devname;
1310
1311 len = colon - dev_name;
1312 if (len > maxnamlen)
1313 goto out_hostname;
1314
1315 /* N.B. caller will free nfs_server.hostname in all cases */
1316 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1317 if (!*hostname)
1318 goto out_nomem;
1319
1320 /* kill possible hostname list: not supported */
1321 comma = strchr(*hostname, ',');
1322 if (comma != NULL) {
1323 if (comma == *hostname)
1324 goto out_bad_devname;
1325 *comma = '\0';
1326 }
1327
1328 colon++;
1329 len = strlen(colon);
1330 if (len > maxpathlen)
1331 goto out_path;
1332 *export_path = kstrndup(colon, len, GFP_KERNEL);
1333 if (!*export_path)
1334 goto out_nomem;
1335
1336 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1337 return 0;
1338
1339out_bad_devname:
1340 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1341 return -EINVAL;
1342
1343out_nomem:
1344 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1345 return -ENOMEM;
1346
1347out_hostname:
1348 dfprintk(MOUNT, "NFS: server hostname too long\n");
1349 return -ENAMETOOLONG;
1350
1351out_path:
1352 dfprintk(MOUNT, "NFS: export pathname too long\n");
1353 return -ENAMETOOLONG;
1354}
1355
1356/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001357 * Hostname has square brackets around it because it contains one or
1358 * more colons. We look for the first closing square bracket, and a
1359 * colon must follow it.
1360 */
1361static int nfs_parse_protected_hostname(const char *dev_name,
1362 char **hostname, size_t maxnamlen,
1363 char **export_path, size_t maxpathlen)
1364{
1365 size_t len;
1366 char *start, *end;
1367
1368 start = (char *)(dev_name + 1);
1369
1370 end = strchr(start, ']');
1371 if (end == NULL)
1372 goto out_bad_devname;
1373 if (*(end + 1) != ':')
1374 goto out_bad_devname;
1375
1376 len = end - start;
1377 if (len > maxnamlen)
1378 goto out_hostname;
1379
1380 /* N.B. caller will free nfs_server.hostname in all cases */
1381 *hostname = kstrndup(start, len, GFP_KERNEL);
1382 if (*hostname == NULL)
1383 goto out_nomem;
1384
1385 end += 2;
1386 len = strlen(end);
1387 if (len > maxpathlen)
1388 goto out_path;
1389 *export_path = kstrndup(end, len, GFP_KERNEL);
1390 if (!*export_path)
1391 goto out_nomem;
1392
1393 return 0;
1394
1395out_bad_devname:
1396 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1397 return -EINVAL;
1398
1399out_nomem:
1400 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1401 return -ENOMEM;
1402
1403out_hostname:
1404 dfprintk(MOUNT, "NFS: server hostname too long\n");
1405 return -ENAMETOOLONG;
1406
1407out_path:
1408 dfprintk(MOUNT, "NFS: export pathname too long\n");
1409 return -ENAMETOOLONG;
1410}
1411
1412/*
1413 * Split "dev_name" into "hostname:export_path".
1414 *
1415 * The leftmost colon demarks the split between the server's hostname
1416 * and the export path. If the hostname starts with a left square
1417 * bracket, then it may contain colons.
1418 *
1419 * Note: caller frees hostname and export path, even on error.
1420 */
1421static int nfs_parse_devname(const char *dev_name,
1422 char **hostname, size_t maxnamlen,
1423 char **export_path, size_t maxpathlen)
1424{
1425 if (*dev_name == '[')
1426 return nfs_parse_protected_hostname(dev_name,
1427 hostname, maxnamlen,
1428 export_path, maxpathlen);
1429
1430 return nfs_parse_simple_hostname(dev_name,
1431 hostname, maxnamlen,
1432 export_path, maxpathlen);
1433}
1434
1435/*
David Howells54ceac42006-08-22 20:06:13 -04001436 * Validate the NFS2/NFS3 mount data
1437 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001438 *
1439 * For option strings, user space handles the following behaviors:
1440 *
1441 * + DNS: mapping server host name to IP address ("addr=" option)
1442 *
1443 * + failure mode: how to behave if a mount request can't be handled
1444 * immediately ("fg/bg" option)
1445 *
1446 * + retry: how often to retry a mount request ("retry=" option)
1447 *
1448 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1449 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001450 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001451static int nfs_validate_mount_data(void *options,
1452 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001453 struct nfs_fh *mntfh,
1454 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001455{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001456 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001457
Chuck Lever5df36e72007-07-01 12:12:56 -04001458 if (data == NULL)
1459 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001460
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001461 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1462 args->rsize = NFS_MAX_FILE_IO_SIZE;
1463 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001464 args->acregmin = NFS_DEF_ACREGMIN;
1465 args->acregmax = NFS_DEF_ACREGMAX;
1466 args->acdirmin = NFS_DEF_ACDIRMIN;
1467 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001468 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001469 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001470 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001471 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001472
David Howellsf7b422b2006-06-09 09:34:33 -04001473 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001474 case 1:
1475 data->namlen = 0;
1476 case 2:
1477 data->bsize = 0;
1478 case 3:
1479 if (data->flags & NFS_MOUNT_VER3)
1480 goto out_no_v3;
1481 data->root.size = NFS2_FHSIZE;
1482 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1483 case 4:
1484 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1485 goto out_no_sec;
1486 case 5:
1487 memset(data->context, 0, sizeof(data->context));
1488 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001489 if (data->flags & NFS_MOUNT_VER3) {
1490 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1491 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001492 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001493 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001494 mntfh->size = NFS2_FHSIZE;
1495
Chuck Lever5df36e72007-07-01 12:12:56 -04001496
1497 memcpy(mntfh->data, data->root.data, mntfh->size);
1498 if (mntfh->size < sizeof(mntfh->data))
1499 memset(mntfh->data + mntfh->size, 0,
1500 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001501
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001502 /*
1503 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1504 * can deal with.
1505 */
1506 args->flags = data->flags;
1507 args->rsize = data->rsize;
1508 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001509 args->timeo = data->timeo;
1510 args->retrans = data->retrans;
1511 args->acregmin = data->acregmin;
1512 args->acregmax = data->acregmax;
1513 args->acdirmin = data->acdirmin;
1514 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001515
1516 memcpy(&args->nfs_server.address, &data->addr,
1517 sizeof(data->addr));
1518 args->nfs_server.addrlen = sizeof(data->addr);
1519 if (!nfs_verify_server_address((struct sockaddr *)
1520 &args->nfs_server.address))
1521 goto out_no_address;
1522
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001523 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001524 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001525 /* N.B. caller will free nfs_server.hostname in all cases */
1526 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1527 args->namlen = data->namlen;
1528 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001529
1530 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1531 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001532 if (!args->nfs_server.hostname)
1533 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001534
1535 /*
1536 * The legacy version 6 binary mount data from userspace has a
1537 * field used only to transport selinux information into the
1538 * the kernel. To continue to support that functionality we
1539 * have a touch of selinux knowledge here in the NFS code. The
1540 * userspace code converted context=blah to just blah so we are
1541 * converting back to the full string selinux understands.
1542 */
1543 if (data->context[0]){
1544#ifdef CONFIG_SECURITY_SELINUX
1545 int rc;
1546 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1547 if (!opts_str)
1548 return -ENOMEM;
1549 strcpy(opts_str, "context=");
1550 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1551 strcat(opts_str, &data->context[0]);
1552 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1553 kfree(opts_str);
1554 if (rc)
1555 return rc;
1556#else
1557 return -EINVAL;
1558#endif
1559 }
1560
Chuck Lever5df36e72007-07-01 12:12:56 -04001561 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001562 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001563 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001564
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001565 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001566 return -EINVAL;
1567
Chuck Lever6e88e062007-09-24 15:39:50 -04001568 if (!nfs_verify_server_address((struct sockaddr *)
1569 &args->nfs_server.address))
1570 goto out_no_address;
1571
Chuck Levered596a82008-06-26 17:47:05 -04001572 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1573 args->nfs_server.port);
1574
Trond Myklebust259875e2008-07-02 14:43:47 -04001575 nfs_set_mount_transport_protocol(args);
1576
Chuck Leverdc045892008-06-23 12:36:37 -04001577 status = nfs_parse_devname(dev_name,
1578 &args->nfs_server.hostname,
1579 PAGE_SIZE,
1580 &args->nfs_server.export_path,
1581 NFS_MAXPATHLEN);
1582 if (!status)
1583 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001584
Chuck Leverdc045892008-06-23 12:36:37 -04001585 kfree(args->nfs_server.export_path);
1586 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001587
Chuck Lever136d5582007-07-01 12:13:54 -04001588 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001589 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001590
Chuck Lever136d5582007-07-01 12:13:54 -04001591 break;
1592 }
David Howellsf7b422b2006-06-09 09:34:33 -04001593 }
David Howells54ceac42006-08-22 20:06:13 -04001594
David Howellsf7b422b2006-06-09 09:34:33 -04001595#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001596 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001597 goto out_v3_not_compiled;
1598#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001599
David Howells54ceac42006-08-22 20:06:13 -04001600 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001601
1602out_no_data:
1603 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1604 return -EINVAL;
1605
1606out_no_v3:
1607 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1608 data->version);
1609 return -EINVAL;
1610
1611out_no_sec:
1612 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1613 return -EINVAL;
1614
Chuck Lever5df36e72007-07-01 12:12:56 -04001615#ifndef CONFIG_NFS_V3
1616out_v3_not_compiled:
1617 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1618 return -EPROTONOSUPPORT;
1619#endif /* !CONFIG_NFS_V3 */
1620
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001621out_nomem:
1622 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1623 return -ENOMEM;
1624
Chuck Lever5df36e72007-07-01 12:12:56 -04001625out_no_address:
1626 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1627 return -EINVAL;
1628
1629out_invalid_fh:
1630 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1631 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001632}
1633
Jeff Layton48b605f2008-06-10 15:38:39 -04001634static int
1635nfs_compare_remount_data(struct nfs_server *nfss,
1636 struct nfs_parsed_mount_data *data)
1637{
1638 if (data->flags != nfss->flags ||
1639 data->rsize != nfss->rsize ||
1640 data->wsize != nfss->wsize ||
1641 data->retrans != nfss->client->cl_timeout->to_retries ||
1642 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1643 data->acregmin != nfss->acregmin / HZ ||
1644 data->acregmax != nfss->acregmax / HZ ||
1645 data->acdirmin != nfss->acdirmin / HZ ||
1646 data->acdirmax != nfss->acdirmax / HZ ||
1647 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1648 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1649 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1650 data->nfs_server.addrlen) != 0)
1651 return -EINVAL;
1652
1653 return 0;
1654}
1655
1656static int
1657nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1658{
1659 int error;
1660 struct nfs_server *nfss = sb->s_fs_info;
1661 struct nfs_parsed_mount_data *data;
1662 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1663 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001664 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001665
1666 /*
1667 * Userspace mount programs that send binary options generally send
1668 * them populated with default values. We have no way to know which
1669 * ones were explicitly specified. Fall back to legacy behavior and
1670 * just return success.
1671 */
Trond Myklebustcd100722008-06-17 16:12:00 -04001672 if ((nfsvers == 4 && options4->version == 1) ||
1673 (nfsvers <= 3 && options->version >= 1 &&
Jeff Layton48b605f2008-06-10 15:38:39 -04001674 options->version <= 6))
1675 return 0;
1676
1677 data = kzalloc(sizeof(*data), GFP_KERNEL);
1678 if (data == NULL)
1679 return -ENOMEM;
1680
1681 /* fill out struct with values from existing mount */
1682 data->flags = nfss->flags;
1683 data->rsize = nfss->rsize;
1684 data->wsize = nfss->wsize;
1685 data->retrans = nfss->client->cl_timeout->to_retries;
1686 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1687 data->acregmin = nfss->acregmin / HZ;
1688 data->acregmax = nfss->acregmax / HZ;
1689 data->acdirmin = nfss->acdirmin / HZ;
1690 data->acdirmax = nfss->acdirmax / HZ;
1691 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1692 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1693 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1694 data->nfs_server.addrlen);
1695
1696 /* overwrite those values with any that were specified */
1697 error = nfs_parse_mount_options((char *)options, data);
1698 if (error < 0)
1699 goto out;
1700
1701 /* compare new mount options with old ones */
1702 error = nfs_compare_remount_data(nfss, data);
1703out:
1704 kfree(data);
1705 return error;
1706}
1707
David Howells54ceac42006-08-22 20:06:13 -04001708/*
1709 * Initialise the common bits of the superblock
1710 */
1711static inline void nfs_initialise_sb(struct super_block *sb)
1712{
1713 struct nfs_server *server = NFS_SB(sb);
1714
1715 sb->s_magic = NFS_SUPER_MAGIC;
1716
1717 /* We probably want something more informative here */
1718 snprintf(sb->s_id, sizeof(sb->s_id),
1719 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1720
1721 if (sb->s_blocksize == 0)
1722 sb->s_blocksize = nfs_block_bits(server->wsize,
1723 &sb->s_blocksize_bits);
1724
1725 if (server->flags & NFS_MOUNT_NOAC)
1726 sb->s_flags |= MS_SYNCHRONOUS;
1727
1728 nfs_super_set_maxbytes(sb, server->maxfilesize);
1729}
1730
1731/*
1732 * Finish setting up an NFS2/3 superblock
1733 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001734static void nfs_fill_super(struct super_block *sb,
1735 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001736{
1737 struct nfs_server *server = NFS_SB(sb);
1738
1739 sb->s_blocksize_bits = 0;
1740 sb->s_blocksize = 0;
1741 if (data->bsize)
1742 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1743
1744 if (server->flags & NFS_MOUNT_VER3) {
1745 /* The VFS shouldn't apply the umask to mode bits. We will do
1746 * so ourselves when necessary.
1747 */
1748 sb->s_flags |= MS_POSIXACL;
1749 sb->s_time_gran = 1;
1750 }
1751
1752 sb->s_op = &nfs_sops;
1753 nfs_initialise_sb(sb);
1754}
1755
1756/*
1757 * Finish setting up a cloned NFS2/3 superblock
1758 */
1759static void nfs_clone_super(struct super_block *sb,
1760 const struct super_block *old_sb)
1761{
1762 struct nfs_server *server = NFS_SB(sb);
1763
1764 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1765 sb->s_blocksize = old_sb->s_blocksize;
1766 sb->s_maxbytes = old_sb->s_maxbytes;
1767
1768 if (server->flags & NFS_MOUNT_VER3) {
1769 /* The VFS shouldn't apply the umask to mode bits. We will do
1770 * so ourselves when necessary.
1771 */
1772 sb->s_flags |= MS_POSIXACL;
1773 sb->s_time_gran = 1;
1774 }
1775
1776 sb->s_op = old_sb->s_op;
1777 nfs_initialise_sb(sb);
1778}
1779
Trond Myklebust275a5d22007-05-16 16:53:28 -04001780#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1781
1782static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1783{
1784 const struct nfs_server *a = s->s_fs_info;
1785 const struct rpc_clnt *clnt_a = a->client;
1786 const struct rpc_clnt *clnt_b = b->client;
1787
1788 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1789 goto Ebusy;
1790 if (a->nfs_client != b->nfs_client)
1791 goto Ebusy;
1792 if (a->flags != b->flags)
1793 goto Ebusy;
1794 if (a->wsize != b->wsize)
1795 goto Ebusy;
1796 if (a->rsize != b->rsize)
1797 goto Ebusy;
1798 if (a->acregmin != b->acregmin)
1799 goto Ebusy;
1800 if (a->acregmax != b->acregmax)
1801 goto Ebusy;
1802 if (a->acdirmin != b->acdirmin)
1803 goto Ebusy;
1804 if (a->acdirmax != b->acdirmax)
1805 goto Ebusy;
1806 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1807 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001808 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001809Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001810 return 0;
1811}
1812
1813struct nfs_sb_mountdata {
1814 struct nfs_server *server;
1815 int mntflags;
1816};
1817
1818static int nfs_set_super(struct super_block *s, void *data)
1819{
1820 struct nfs_sb_mountdata *sb_mntdata = data;
1821 struct nfs_server *server = sb_mntdata->server;
1822 int ret;
1823
1824 s->s_flags = sb_mntdata->mntflags;
1825 s->s_fs_info = server;
1826 ret = set_anon_super(s, server);
1827 if (ret == 0)
1828 server->s_dev = s->s_dev;
1829 return ret;
1830}
1831
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001832static int nfs_compare_super_address(struct nfs_server *server1,
1833 struct nfs_server *server2)
1834{
1835 struct sockaddr *sap1, *sap2;
1836
1837 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1838 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1839
1840 if (sap1->sa_family != sap2->sa_family)
1841 return 0;
1842
1843 switch (sap1->sa_family) {
1844 case AF_INET: {
1845 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1846 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1847 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1848 return 0;
1849 if (sin1->sin_port != sin2->sin_port)
1850 return 0;
1851 break;
1852 }
1853 case AF_INET6: {
1854 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1855 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1856 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1857 return 0;
1858 if (sin1->sin6_port != sin2->sin6_port)
1859 return 0;
1860 break;
1861 }
1862 default:
1863 return 0;
1864 }
1865
1866 return 1;
1867}
1868
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001869static int nfs_compare_super(struct super_block *sb, void *data)
1870{
1871 struct nfs_sb_mountdata *sb_mntdata = data;
1872 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1873 int mntflags = sb_mntdata->mntflags;
1874
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001875 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001876 return 0;
1877 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1878 if (old->flags & NFS_MOUNT_UNSHARED)
1879 return 0;
1880 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1881 return 0;
1882 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001883}
1884
Miklos Szeredifa799752008-04-30 00:54:33 -07001885static int nfs_bdi_register(struct nfs_server *server)
1886{
1887 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1888}
1889
David Howells54ceac42006-08-22 20:06:13 -04001890static int nfs_get_sb(struct file_system_type *fs_type,
1891 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1892{
1893 struct nfs_server *server = NULL;
1894 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001895 struct nfs_parsed_mount_data *data;
1896 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001897 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001898 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001899 struct nfs_sb_mountdata sb_mntdata = {
1900 .mntflags = flags,
1901 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001902 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001903
Trond Myklebust33852a12008-06-19 14:20:11 -04001904 data = kzalloc(sizeof(*data), GFP_KERNEL);
1905 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1906 if (data == NULL || mntfh == NULL)
1907 goto out_free_fh;
1908
1909 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001910
David Howells54ceac42006-08-22 20:06:13 -04001911 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04001912 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001913 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001914 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001915
1916 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001917 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001918 if (IS_ERR(server)) {
1919 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001920 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001921 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001922 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001923
Trond Myklebust75180df2007-05-16 16:53:28 -04001924 if (server->flags & NFS_MOUNT_UNSHARED)
1925 compare_super = NULL;
1926
David Howells54ceac42006-08-22 20:06:13 -04001927 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001928 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001929 if (IS_ERR(s)) {
1930 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001931 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001932 }
1933
David Howells54ceac42006-08-22 20:06:13 -04001934 if (s->s_fs_info != server) {
1935 nfs_free_server(server);
1936 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07001937 } else {
1938 error = nfs_bdi_register(server);
1939 if (error)
1940 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001941 }
David Howells54ceac42006-08-22 20:06:13 -04001942
1943 if (!s->s_root) {
1944 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001945 nfs_fill_super(s, data);
David Howells54ceac42006-08-22 20:06:13 -04001946 }
1947
Trond Myklebust33852a12008-06-19 14:20:11 -04001948 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001949 if (IS_ERR(mntroot)) {
1950 error = PTR_ERR(mntroot);
1951 goto error_splat_super;
1952 }
1953
Trond Myklebust33852a12008-06-19 14:20:11 -04001954 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001955 if (error)
1956 goto error_splat_root;
1957
David Howellsf7b422b2006-06-09 09:34:33 -04001958 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001959 mnt->mnt_sb = s;
1960 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001961 error = 0;
1962
1963out:
Trond Myklebust33852a12008-06-19 14:20:11 -04001964 kfree(data->nfs_server.hostname);
1965 kfree(data->mount_server.hostname);
1966 security_free_mnt_opts(&data->lsm_opts);
1967out_free_fh:
1968 kfree(mntfh);
1969 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04001970 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001971
David Howells54ceac42006-08-22 20:06:13 -04001972out_err_nosb:
1973 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001974 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001975
Eric Parisf9c3a382008-03-05 14:20:18 -05001976error_splat_root:
1977 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04001978error_splat_super:
1979 up_write(&s->s_umount);
1980 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001981 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001982}
1983
David Howells54ceac42006-08-22 20:06:13 -04001984/*
1985 * Destroy an NFS2/3 superblock
1986 */
David Howellsf7b422b2006-06-09 09:34:33 -04001987static void nfs_kill_super(struct super_block *s)
1988{
1989 struct nfs_server *server = NFS_SB(s);
1990
Miklos Szeredifa799752008-04-30 00:54:33 -07001991 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04001992 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001993 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001994}
1995
David Howells54ceac42006-08-22 20:06:13 -04001996/*
1997 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1998 */
1999static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2000 const char *dev_name, void *raw_data,
2001 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002002{
2003 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002004 struct super_block *s;
2005 struct nfs_server *server;
2006 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002007 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002008 struct nfs_sb_mountdata sb_mntdata = {
2009 .mntflags = flags,
2010 };
David Howells54ceac42006-08-22 20:06:13 -04002011 int error;
2012
2013 dprintk("--> nfs_xdev_get_sb()\n");
2014
2015 /* create a new volume representation */
2016 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2017 if (IS_ERR(server)) {
2018 error = PTR_ERR(server);
2019 goto out_err_noserver;
2020 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002021 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002022
Trond Myklebust75180df2007-05-16 16:53:28 -04002023 if (server->flags & NFS_MOUNT_UNSHARED)
2024 compare_super = NULL;
2025
David Howells54ceac42006-08-22 20:06:13 -04002026 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002027 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002028 if (IS_ERR(s)) {
2029 error = PTR_ERR(s);
2030 goto out_err_nosb;
2031 }
2032
2033 if (s->s_fs_info != server) {
2034 nfs_free_server(server);
2035 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002036 } else {
2037 error = nfs_bdi_register(server);
2038 if (error)
2039 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002040 }
2041
2042 if (!s->s_root) {
2043 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002044 nfs_clone_super(s, data->sb);
2045 }
2046
2047 mntroot = nfs_get_root(s, data->fh);
2048 if (IS_ERR(mntroot)) {
2049 error = PTR_ERR(mntroot);
2050 goto error_splat_super;
2051 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002052 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002053 dput(mntroot);
2054 error = -ESTALE;
2055 goto error_splat_super;
2056 }
David Howells54ceac42006-08-22 20:06:13 -04002057
2058 s->s_flags |= MS_ACTIVE;
2059 mnt->mnt_sb = s;
2060 mnt->mnt_root = mntroot;
2061
Eric Parisf9c3a382008-03-05 14:20:18 -05002062 /* clone any lsm security options from the parent to the new sb */
2063 security_sb_clone_mnt_opts(data->sb, s);
2064
David Howells54ceac42006-08-22 20:06:13 -04002065 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2066 return 0;
2067
2068out_err_nosb:
2069 nfs_free_server(server);
2070out_err_noserver:
2071 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2072 return error;
2073
2074error_splat_super:
2075 up_write(&s->s_umount);
2076 deactivate_super(s);
2077 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2078 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002079}
2080
2081#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002082
2083/*
2084 * Finish setting up a cloned NFS4 superblock
2085 */
2086static void nfs4_clone_super(struct super_block *sb,
2087 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002088{
David Howells54ceac42006-08-22 20:06:13 -04002089 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2090 sb->s_blocksize = old_sb->s_blocksize;
2091 sb->s_maxbytes = old_sb->s_maxbytes;
2092 sb->s_time_gran = 1;
2093 sb->s_op = old_sb->s_op;
2094 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002095}
2096
2097/*
2098 * Set up an NFS4 superblock
2099 */
David Howells54ceac42006-08-22 20:06:13 -04002100static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002101{
David Howellsf7b422b2006-06-09 09:34:33 -04002102 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002103 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002104 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002105}
2106
David Howells54ceac42006-08-22 20:06:13 -04002107/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002108 * Validate NFSv4 mount options
2109 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002110static int nfs4_validate_mount_data(void *options,
2111 struct nfs_parsed_mount_data *args,
2112 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002113{
Chuck Lever4c568012007-12-10 14:59:28 -05002114 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002115 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002116 char *c;
2117
2118 if (data == NULL)
2119 goto out_no_data;
2120
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002121 args->rsize = NFS_MAX_FILE_IO_SIZE;
2122 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002123 args->acregmin = NFS_DEF_ACREGMIN;
2124 args->acregmax = NFS_DEF_ACREGMAX;
2125 args->acdirmin = NFS_DEF_ACDIRMIN;
2126 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002127 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002128
Chuck Leverf0768eb2007-07-01 12:13:01 -04002129 switch (data->version) {
2130 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002131 ap = (struct sockaddr_in *)&args->nfs_server.address;
2132 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002133 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002134 if (data->host_addrlen == 0)
2135 goto out_no_address;
2136 args->nfs_server.addrlen = data->host_addrlen;
2137 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002138 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002139 if (!nfs_verify_server_address((struct sockaddr *)
2140 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002141 goto out_no_address;
2142
2143 switch (data->auth_flavourlen) {
2144 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002145 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002146 break;
2147 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04002148 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002149 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002150 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002151 return -EFAULT;
2152 break;
2153 default:
2154 goto out_inval_auth;
2155 }
2156
2157 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2158 if (IS_ERR(c))
2159 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002160 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002161
2162 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2163 if (IS_ERR(c))
2164 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002165 args->nfs_server.export_path = c;
2166 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002167
2168 c = strndup_user(data->client_addr.data, 16);
2169 if (IS_ERR(c))
2170 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002171 args->client_address = c;
2172
2173 /*
2174 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2175 * can deal with.
2176 */
2177
2178 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2179 args->rsize = data->rsize;
2180 args->wsize = data->wsize;
2181 args->timeo = data->timeo;
2182 args->retrans = data->retrans;
2183 args->acregmin = data->acregmin;
2184 args->acregmax = data->acregmax;
2185 args->acdirmin = data->acdirmin;
2186 args->acdirmax = data->acdirmax;
2187 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002188 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002189
2190 break;
Chuck Lever80071222007-07-01 12:13:59 -04002191 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002192 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002193
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002194 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002195 return -EINVAL;
2196
2197 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002198 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002199 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002200
Chuck Levered596a82008-06-26 17:47:05 -04002201 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2202 args->nfs_server.port);
2203
Trond Myklebust259875e2008-07-02 14:43:47 -04002204 nfs_validate_transport_protocol(args);
2205
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002206 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04002207 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002208 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04002209 break;
2210 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04002211 break;
2212 default:
2213 goto out_inval_auth;
2214 }
2215
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002216 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002217 goto out_no_client_address;
2218
Chuck Leverdc045892008-06-23 12:36:37 -04002219 status = nfs_parse_devname(dev_name,
2220 &args->nfs_server.hostname,
2221 NFS4_MAXNAMLEN,
2222 &args->nfs_server.export_path,
2223 NFS4_MAXPATHLEN);
2224 if (status < 0)
2225 return status;
2226
Chuck Lever80071222007-07-01 12:13:59 -04002227 break;
2228 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002229 }
2230
2231 return 0;
2232
2233out_no_data:
2234 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2235 return -EINVAL;
2236
2237out_inval_auth:
2238 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2239 data->auth_flavourlen);
2240 return -EINVAL;
2241
2242out_no_address:
2243 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2244 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002245
2246out_no_client_address:
2247 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2248 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002249}
2250
2251/*
David Howells54ceac42006-08-22 20:06:13 -04002252 * Get the superblock for an NFS4 mountpoint
2253 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002254static int nfs4_get_sb(struct file_system_type *fs_type,
2255 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002256{
Trond Myklebust33852a12008-06-19 14:20:11 -04002257 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002258 struct super_block *s;
2259 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002260 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002261 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002262 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002263 struct nfs_sb_mountdata sb_mntdata = {
2264 .mntflags = flags,
2265 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002266 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002267
Trond Myklebust33852a12008-06-19 14:20:11 -04002268 data = kzalloc(sizeof(*data), GFP_KERNEL);
2269 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2270 if (data == NULL || mntfh == NULL)
2271 goto out_free_fh;
2272
2273 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002274
Chuck Leverf0768eb2007-07-01 12:13:01 -04002275 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002276 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002277 if (error < 0)
2278 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002279
David Howells54ceac42006-08-22 20:06:13 -04002280 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002281 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002282 if (IS_ERR(server)) {
2283 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002284 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002285 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002286 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002287
Trond Myklebust75180df2007-05-16 16:53:28 -04002288 if (server->flags & NFS4_MOUNT_UNSHARED)
2289 compare_super = NULL;
2290
David Howells54ceac42006-08-22 20:06:13 -04002291 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002292 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002293 if (IS_ERR(s)) {
2294 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002295 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002296 }
2297
Trond Myklebust5dd31772006-08-24 01:03:05 -04002298 if (s->s_fs_info != server) {
2299 nfs_free_server(server);
2300 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002301 } else {
2302 error = nfs_bdi_register(server);
2303 if (error)
2304 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002305 }
2306
David Howells54ceac42006-08-22 20:06:13 -04002307 if (!s->s_root) {
2308 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002309 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04002310 }
David Howellsf7b422b2006-06-09 09:34:33 -04002311
Trond Myklebust33852a12008-06-19 14:20:11 -04002312 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002313 if (IS_ERR(mntroot)) {
2314 error = PTR_ERR(mntroot);
2315 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002316 }
David Howells54ceac42006-08-22 20:06:13 -04002317
Trond Myklebust33852a12008-06-19 14:20:11 -04002318 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002319 if (error)
2320 goto error_splat_root;
2321
David Howellsf7b422b2006-06-09 09:34:33 -04002322 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002323 mnt->mnt_sb = s;
2324 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002325 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002326
Chuck Lever29eb9812007-07-01 12:12:30 -04002327out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002328 kfree(data->client_address);
2329 kfree(data->nfs_server.export_path);
2330 kfree(data->nfs_server.hostname);
2331 security_free_mnt_opts(&data->lsm_opts);
2332out_free_fh:
2333 kfree(mntfh);
2334 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002335 return error;
David Howells54ceac42006-08-22 20:06:13 -04002336
Chuck Lever29eb9812007-07-01 12:12:30 -04002337out_free:
2338 nfs_free_server(server);
2339 goto out;
2340
Eric Paris46c8ac72008-05-02 13:42:42 -07002341error_splat_root:
2342 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002343error_splat_super:
2344 up_write(&s->s_umount);
2345 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002346 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002347}
2348
2349static void nfs4_kill_super(struct super_block *sb)
2350{
2351 struct nfs_server *server = NFS_SB(sb);
2352
2353 nfs_return_all_delegations(sb);
2354 kill_anon_super(sb);
2355
2356 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002357 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002358}
2359
2360/*
David Howells54ceac42006-08-22 20:06:13 -04002361 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002362 */
David Howells54ceac42006-08-22 20:06:13 -04002363static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2364 const char *dev_name, void *raw_data,
2365 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002366{
2367 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002368 struct super_block *s;
2369 struct nfs_server *server;
2370 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002371 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002372 struct nfs_sb_mountdata sb_mntdata = {
2373 .mntflags = flags,
2374 };
David Howells54ceac42006-08-22 20:06:13 -04002375 int error;
2376
2377 dprintk("--> nfs4_xdev_get_sb()\n");
2378
2379 /* create a new volume representation */
2380 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2381 if (IS_ERR(server)) {
2382 error = PTR_ERR(server);
2383 goto out_err_noserver;
2384 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002385 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002386
Trond Myklebust75180df2007-05-16 16:53:28 -04002387 if (server->flags & NFS4_MOUNT_UNSHARED)
2388 compare_super = NULL;
2389
David Howells54ceac42006-08-22 20:06:13 -04002390 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002391 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002392 if (IS_ERR(s)) {
2393 error = PTR_ERR(s);
2394 goto out_err_nosb;
2395 }
2396
2397 if (s->s_fs_info != server) {
2398 nfs_free_server(server);
2399 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002400 } else {
2401 error = nfs_bdi_register(server);
2402 if (error)
2403 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002404 }
2405
2406 if (!s->s_root) {
2407 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002408 nfs4_clone_super(s, data->sb);
2409 }
2410
2411 mntroot = nfs4_get_root(s, data->fh);
2412 if (IS_ERR(mntroot)) {
2413 error = PTR_ERR(mntroot);
2414 goto error_splat_super;
2415 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002416 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2417 dput(mntroot);
2418 error = -ESTALE;
2419 goto error_splat_super;
2420 }
David Howells54ceac42006-08-22 20:06:13 -04002421
2422 s->s_flags |= MS_ACTIVE;
2423 mnt->mnt_sb = s;
2424 mnt->mnt_root = mntroot;
2425
Eric Paris46c8ac72008-05-02 13:42:42 -07002426 security_sb_clone_mnt_opts(data->sb, s);
2427
David Howells54ceac42006-08-22 20:06:13 -04002428 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2429 return 0;
2430
2431out_err_nosb:
2432 nfs_free_server(server);
2433out_err_noserver:
2434 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2435 return error;
2436
2437error_splat_super:
2438 up_write(&s->s_umount);
2439 deactivate_super(s);
2440 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2441 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002442}
2443
David Howells54ceac42006-08-22 20:06:13 -04002444/*
2445 * Create an NFS4 server record on referral traversal
2446 */
2447static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2448 const char *dev_name, void *raw_data,
2449 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002450{
2451 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002452 struct super_block *s;
2453 struct nfs_server *server;
2454 struct dentry *mntroot;
2455 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002456 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002457 struct nfs_sb_mountdata sb_mntdata = {
2458 .mntflags = flags,
2459 };
David Howells54ceac42006-08-22 20:06:13 -04002460 int error;
2461
2462 dprintk("--> nfs4_referral_get_sb()\n");
2463
2464 /* create a new volume representation */
2465 server = nfs4_create_referral_server(data, &mntfh);
2466 if (IS_ERR(server)) {
2467 error = PTR_ERR(server);
2468 goto out_err_noserver;
2469 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002470 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002471
Trond Myklebust75180df2007-05-16 16:53:28 -04002472 if (server->flags & NFS4_MOUNT_UNSHARED)
2473 compare_super = NULL;
2474
David Howells54ceac42006-08-22 20:06:13 -04002475 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002476 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002477 if (IS_ERR(s)) {
2478 error = PTR_ERR(s);
2479 goto out_err_nosb;
2480 }
2481
2482 if (s->s_fs_info != server) {
2483 nfs_free_server(server);
2484 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002485 } else {
2486 error = nfs_bdi_register(server);
2487 if (error)
2488 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002489 }
2490
2491 if (!s->s_root) {
2492 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002493 nfs4_fill_super(s);
2494 }
2495
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002496 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002497 if (IS_ERR(mntroot)) {
2498 error = PTR_ERR(mntroot);
2499 goto error_splat_super;
2500 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002501 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2502 dput(mntroot);
2503 error = -ESTALE;
2504 goto error_splat_super;
2505 }
David Howells54ceac42006-08-22 20:06:13 -04002506
2507 s->s_flags |= MS_ACTIVE;
2508 mnt->mnt_sb = s;
2509 mnt->mnt_root = mntroot;
2510
Eric Paris46c8ac72008-05-02 13:42:42 -07002511 security_sb_clone_mnt_opts(data->sb, s);
2512
David Howells54ceac42006-08-22 20:06:13 -04002513 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2514 return 0;
2515
2516out_err_nosb:
2517 nfs_free_server(server);
2518out_err_noserver:
2519 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2520 return error;
2521
2522error_splat_super:
2523 up_write(&s->s_umount);
2524 deactivate_super(s);
2525 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2526 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002527}
2528
David Howells54ceac42006-08-22 20:06:13 -04002529#endif /* CONFIG_NFS_V4 */