blob: b550e921f66193efd438dcbccac103ab8548307c [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
David Howellsf7b422b2006-06-09 09:34:33 -040050#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080051#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040052#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053
54#include <asm/system.h>
55#include <asm/uaccess.h>
56
57#include "nfs4_fs.h"
58#include "callback.h"
59#include "delegation.h"
60#include "iostat.h"
61#include "internal.h"
62
63#define NFSDBG_FACILITY NFSDBG_VFS
64
Chuck Leverbf0fd762007-07-01 12:13:44 -040065enum {
66 /* Mount options that take no arguments */
67 Opt_soft, Opt_hard,
68 Opt_intr, Opt_nointr,
69 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac,
72 Opt_lock, Opt_nolock,
73 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040074 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075 Opt_acl, Opt_noacl,
76 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040077 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078
79 /* Mount options that take integer arguments */
80 Opt_port,
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
85 Opt_actimeo,
86 Opt_namelen,
87 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040088 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040089 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050092 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040093 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
97
98 Opt_err
99};
100
101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
110 { Opt_cto, "cto" },
111 { Opt_nocto, "nocto" },
112 { Opt_ac, "ac" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
116 { Opt_v2, "v2" },
117 { Opt_v3, "v3" },
118 { Opt_udp, "udp" },
119 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400120 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_acl, "acl" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
145
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500151 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400152 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153
154 { Opt_err, NULL }
155};
156
157enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400158 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400159
160 Opt_xprt_err
161};
162
163static match_table_t nfs_xprt_protocol_tokens = {
164 { Opt_xprt_udp, "udp" },
165 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400166 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400167
168 { Opt_xprt_err, NULL }
169};
170
171enum {
172 Opt_sec_none, Opt_sec_sys,
173 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
174 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
175 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
176
177 Opt_sec_err
178};
179
180static match_table_t nfs_secflavor_tokens = {
181 { Opt_sec_none, "none" },
182 { Opt_sec_none, "null" },
183 { Opt_sec_sys, "sys" },
184
185 { Opt_sec_krb5, "krb5" },
186 { Opt_sec_krb5i, "krb5i" },
187 { Opt_sec_krb5p, "krb5p" },
188
189 { Opt_sec_lkey, "lkey" },
190 { Opt_sec_lkeyi, "lkeyi" },
191 { Opt_sec_lkeyp, "lkeyp" },
192
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500193 { Opt_sec_spkm, "spkm3" },
194 { Opt_sec_spkmi, "spkm3i" },
195 { Opt_sec_spkmp, "spkm3p" },
196
Chuck Leverbf0fd762007-07-01 12:13:44 -0400197 { Opt_sec_err, NULL }
198};
199
200
Al Viro42faad92008-04-24 07:21:56 -0400201static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400202static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400203static int nfs_show_options(struct seq_file *, struct vfsmount *);
204static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400205static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400206static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400207 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400208static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500209static void nfs_put_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400210static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400211
212static struct file_system_type nfs_fs_type = {
213 .owner = THIS_MODULE,
214 .name = "nfs",
215 .get_sb = nfs_get_sb,
216 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700217 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400218};
219
David Howells54ceac42006-08-22 20:06:13 -0400220struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400221 .owner = THIS_MODULE,
222 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400223 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400224 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700225 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400226};
227
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800228static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400229 .alloc_inode = nfs_alloc_inode,
230 .destroy_inode = nfs_destroy_inode,
231 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500232 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400233 .statfs = nfs_statfs,
234 .clear_inode = nfs_clear_inode,
235 .umount_begin = nfs_umount_begin,
236 .show_options = nfs_show_options,
237 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400238 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400239};
240
241#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400242static int nfs4_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400244static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
245 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
246static int nfs4_referral_get_sb(struct file_system_type *fs_type,
247 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400248static void nfs4_kill_super(struct super_block *sb);
249
250static struct file_system_type nfs4_fs_type = {
251 .owner = THIS_MODULE,
252 .name = "nfs4",
253 .get_sb = nfs4_get_sb,
254 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700255 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400256};
257
David Howells54ceac42006-08-22 20:06:13 -0400258struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400259 .owner = THIS_MODULE,
260 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400261 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400262 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700263 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400264};
265
David Howells54ceac42006-08-22 20:06:13 -0400266struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400267 .owner = THIS_MODULE,
268 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400269 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400270 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700271 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400272};
273
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800274static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400275 .alloc_inode = nfs_alloc_inode,
276 .destroy_inode = nfs_destroy_inode,
277 .write_inode = nfs_write_inode,
278 .statfs = nfs_statfs,
279 .clear_inode = nfs4_clear_inode,
280 .umount_begin = nfs_umount_begin,
281 .show_options = nfs_show_options,
282 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400283 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400284};
285#endif
286
Rusty Russell8e1f9362007-07-17 04:03:17 -0700287static struct shrinker acl_shrinker = {
288 .shrink = nfs_access_cache_shrinker,
289 .seeks = DEFAULT_SEEKS,
290};
Trond Myklebust979df722006-07-25 11:28:19 -0400291
David Howellsf7b422b2006-06-09 09:34:33 -0400292/*
293 * Register the NFS filesystems
294 */
295int __init register_nfs_fs(void)
296{
297 int ret;
298
299 ret = register_filesystem(&nfs_fs_type);
300 if (ret < 0)
301 goto error_0;
302
David Howellsf7b422b2006-06-09 09:34:33 -0400303 ret = nfs_register_sysctl();
304 if (ret < 0)
305 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800306#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400307 ret = register_filesystem(&nfs4_fs_type);
308 if (ret < 0)
309 goto error_2;
310#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700311 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400312 return 0;
313
314#ifdef CONFIG_NFS_V4
315error_2:
316 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800317#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400318error_1:
319 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400320error_0:
321 return ret;
322}
323
324/*
325 * Unregister the NFS filesystems
326 */
327void __exit unregister_nfs_fs(void)
328{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700329 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400330#ifdef CONFIG_NFS_V4
331 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400332#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700333 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400334 unregister_filesystem(&nfs_fs_type);
335}
336
Steve Dicksonef818a22007-11-08 04:05:04 -0500337void nfs_sb_active(struct nfs_server *server)
338{
339 atomic_inc(&server->active);
340}
341
342void nfs_sb_deactive(struct nfs_server *server)
343{
344 if (atomic_dec_and_test(&server->active))
345 wake_up(&server->active_wq);
346}
347
348static void nfs_put_super(struct super_block *sb)
349{
350 struct nfs_server *server = NFS_SB(sb);
351 /*
352 * Make sure there are no outstanding ops to this server.
353 * If so, wait for them to finish before allowing the
354 * unmount to continue.
355 */
356 wait_event(server->active_wq, atomic_read(&server->active) == 0);
357}
358
David Howellsf7b422b2006-06-09 09:34:33 -0400359/*
360 * Deliver file system statistics to userspace
361 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400362static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400363{
David Howells0c7d90c2006-08-22 20:06:10 -0400364 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400365 unsigned char blockbits;
366 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400367 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400368 struct nfs_fattr fattr;
369 struct nfs_fsstat res = {
370 .fattr = &fattr,
371 };
372 int error;
373
374 lock_kernel();
375
David Howells8fa5c002006-08-22 20:06:12 -0400376 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400377 if (error < 0)
378 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700379 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400380
381 /*
382 * Current versions of glibc do not correctly handle the
383 * case where f_frsize != f_bsize. Eventually we want to
384 * report the value of wtmult in this field.
385 */
David Howells0c7d90c2006-08-22 20:06:10 -0400386 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400387
388 /*
389 * On most *nix systems, f_blocks, f_bfree, and f_bavail
390 * are reported in units of f_frsize. Linux hasn't had
391 * an f_frsize field in its statfs struct until recently,
392 * thus historically Linux's sys_statfs reports these
393 * fields in units of f_bsize.
394 */
David Howells0c7d90c2006-08-22 20:06:10 -0400395 buf->f_bsize = dentry->d_sb->s_blocksize;
396 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400397 blockres = (1 << blockbits) - 1;
398 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
399 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
400 buf->f_bavail = (res.abytes + blockres) >> blockbits;
401
402 buf->f_files = res.tfiles;
403 buf->f_ffree = res.afiles;
404
405 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700406
David Howellsf7b422b2006-06-09 09:34:33 -0400407 unlock_kernel();
408 return 0;
409
410 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700411 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700412 unlock_kernel();
413 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400414}
415
David Howells7d4e2742006-08-22 20:06:07 -0400416/*
417 * Map the security flavour number to a name
418 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400419static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
420{
David Howells7d4e2742006-08-22 20:06:07 -0400421 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400422 rpc_authflavor_t flavour;
423 const char *str;
424 } sec_flavours[] = {
425 { RPC_AUTH_NULL, "null" },
426 { RPC_AUTH_UNIX, "sys" },
427 { RPC_AUTH_GSS_KRB5, "krb5" },
428 { RPC_AUTH_GSS_KRB5I, "krb5i" },
429 { RPC_AUTH_GSS_KRB5P, "krb5p" },
430 { RPC_AUTH_GSS_LKEY, "lkey" },
431 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
432 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
433 { RPC_AUTH_GSS_SPKM, "spkm" },
434 { RPC_AUTH_GSS_SPKMI, "spkmi" },
435 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400436 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400437 };
438 int i;
439
Chuck Lever4d81cd12007-07-01 12:12:40 -0400440 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400441 if (sec_flavours[i].flavour == flavour)
442 break;
443 }
444 return sec_flavours[i].str;
445}
446
Chuck Lever82d101d2008-03-14 14:10:37 -0400447static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
448 int showdefaults)
449{
450 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
451
452 switch (sap->sa_family) {
453 case AF_INET: {
454 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
455 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
456 NIPQUAD(sin->sin_addr.s_addr));
457 break;
458 }
459 case AF_INET6: {
460 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
461 seq_printf(m, ",mountaddr=" NIP6_FMT,
462 NIP6(sin6->sin6_addr));
463 break;
464 }
465 default:
466 if (showdefaults)
467 seq_printf(m, ",mountaddr=unspecified");
468 }
469
470 if (nfss->mountd_version || showdefaults)
471 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
472 if (nfss->mountd_port || showdefaults)
473 seq_printf(m, ",mountport=%u", nfss->mountd_port);
474
475 switch (nfss->mountd_protocol) {
476 case IPPROTO_UDP:
477 seq_printf(m, ",mountproto=udp");
478 break;
479 case IPPROTO_TCP:
480 seq_printf(m, ",mountproto=tcp");
481 break;
482 default:
483 if (showdefaults)
484 seq_printf(m, ",mountproto=auto");
485 }
486}
487
David Howellsf7b422b2006-06-09 09:34:33 -0400488/*
489 * Describe the mount options in force on this server representation
490 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400491static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
492 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400493{
David Howells509de812006-08-22 20:06:11 -0400494 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400495 int flag;
David Howells509de812006-08-22 20:06:11 -0400496 const char *str;
497 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400498 } nfs_info[] = {
499 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400500 { NFS_MOUNT_INTR, ",intr", ",nointr" },
501 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400502 { NFS_MOUNT_NOCTO, ",nocto", "" },
503 { NFS_MOUNT_NOAC, ",noac", "" },
504 { NFS_MOUNT_NONLM, ",nolock", "" },
505 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400506 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400507 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400508 { 0, NULL, NULL }
509 };
David Howells509de812006-08-22 20:06:11 -0400510 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400511 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400512 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400513
Chuck Lever82d101d2008-03-14 14:10:37 -0400514 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400515 seq_printf(m, ",rsize=%u", nfss->rsize);
516 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400517 if (nfss->bsize != 0)
518 seq_printf(m, ",bsize=%u", nfss->bsize);
519 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400520 if (nfss->acregmin != 3*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400521 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400522 if (nfss->acregmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400523 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400524 if (nfss->acdirmin != 30*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400525 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400526 if (nfss->acdirmax != 60*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400527 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400528 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
529 if (nfss->flags & nfs_infop->flag)
530 seq_puts(m, nfs_infop->str);
531 else
532 seq_puts(m, nfs_infop->nostr);
533 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400534 seq_printf(m, ",proto=%s",
535 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400536 if (version == 4) {
537 if (nfss->port != NFS_PORT)
538 seq_printf(m, ",port=%u", nfss->port);
539 } else
540 if (nfss->port)
541 seq_printf(m, ",port=%u", nfss->port);
542
Trond Myklebust33170232007-12-20 16:03:59 -0500543 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
544 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400545 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400546
547 if (version != 4)
548 nfs_show_mountd_options(m, nfss, showdefaults);
549
550#ifdef CONFIG_NFS_V4
551 if (clp->rpc_ops->version == 4)
552 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
553#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400554}
555
556/*
557 * Describe the mount options on this VFS mountpoint
558 */
559static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
560{
561 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
562
563 nfs_show_mount_options(m, nfss, 0);
564
Chuck Lever5d8515c2007-12-10 14:57:16 -0500565 seq_printf(m, ",addr=%s",
566 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
567 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400568
569 return 0;
570}
571
572/*
573 * Present statistical information for this VFS mountpoint
574 */
575static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
576{
577 int i, cpu;
578 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
579 struct rpc_auth *auth = nfss->client->cl_auth;
580 struct nfs_iostats totals = { };
581
582 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
583
584 /*
585 * Display all mount option settings
586 */
587 seq_printf(m, "\n\topts:\t");
588 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
589 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
590 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
591 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
592 nfs_show_mount_options(m, nfss, 1);
593
594 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
595
596 seq_printf(m, "\n\tcaps:\t");
597 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400598 seq_printf(m, ",wtmult=%u", nfss->wtmult);
599 seq_printf(m, ",dtsize=%u", nfss->dtsize);
600 seq_printf(m, ",bsize=%u", nfss->bsize);
601 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400602
603#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500604 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400605 seq_printf(m, "\n\tnfsv4:\t");
606 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
607 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
608 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
609 }
610#endif
611
612 /*
613 * Display security flavor in effect for this mount
614 */
Chuck Lever2d767432008-03-14 14:10:08 -0400615 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400616 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400617 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400618
619 /*
620 * Display superblock I/O counters
621 */
622 for_each_possible_cpu(cpu) {
623 struct nfs_iostats *stats;
624
625 preempt_disable();
626 stats = per_cpu_ptr(nfss->io_stats, cpu);
627
628 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
629 totals.events[i] += stats->events[i];
630 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
631 totals.bytes[i] += stats->bytes[i];
632
633 preempt_enable();
634 }
635
636 seq_printf(m, "\n\tevents:\t");
637 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
638 seq_printf(m, "%lu ", totals.events[i]);
639 seq_printf(m, "\n\tbytes:\t");
640 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
641 seq_printf(m, "%Lu ", totals.bytes[i]);
642 seq_printf(m, "\n");
643
644 rpc_print_iostats(m, nfss->client);
645
646 return 0;
647}
648
649/*
650 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400651 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400652 */
Al Viro42faad92008-04-24 07:21:56 -0400653static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400654{
Al Viro42faad92008-04-24 07:21:56 -0400655 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400656 struct rpc_clnt *rpc;
657
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400658 /* -EIO all pending I/O */
659 rpc = server->client_acl;
660 if (!IS_ERR(rpc))
661 rpc_killall_tasks(rpc);
662 rpc = server->client;
663 if (!IS_ERR(rpc))
664 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400665}
666
667/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500668 * Set the port number in an address. Be agnostic about the address family.
669 */
670static void nfs_set_port(struct sockaddr *sap, unsigned short port)
671{
672 switch (sap->sa_family) {
673 case AF_INET: {
674 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
675 ap->sin_port = htons(port);
676 break;
677 }
678 case AF_INET6: {
679 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
680 ap->sin6_port = htons(port);
681 break;
682 }
683 }
684}
685
686/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500687 * Sanity-check a server address provided by the mount command.
688 *
689 * Address family must be initialized, and address must not be
690 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400691 */
692static int nfs_verify_server_address(struct sockaddr *addr)
693{
694 switch (addr->sa_family) {
695 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500696 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700697 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500698 }
699 case AF_INET6: {
700 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
701 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400702 }
703 }
704
705 return 0;
706}
707
708/*
Chuck Lever9412b922007-12-10 14:59:21 -0500709 * Parse string addresses passed in via a mount option,
710 * and construct a sockaddr based on the result.
711 *
712 * If address parsing fails, set the sockaddr's address
713 * family to AF_UNSPEC to force nfs_verify_server_address()
714 * to punt the mount.
715 */
716static void nfs_parse_server_address(char *value,
Chuck Lever4c568012007-12-10 14:59:28 -0500717 struct sockaddr *sap,
718 size_t *len)
Chuck Lever9412b922007-12-10 14:59:21 -0500719{
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500720 if (strchr(value, ':')) {
721 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
722 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
Chuck Lever9412b922007-12-10 14:59:21 -0500723
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500724 ap->sin6_family = AF_INET6;
725 *len = sizeof(*ap);
726 if (in6_pton(value, -1, addr, '\0', NULL))
727 return;
728 } else {
729 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
730 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
731
732 ap->sin_family = AF_INET;
733 *len = sizeof(*ap);
734 if (in4_pton(value, -1, addr, '\0', NULL))
735 return;
736 }
Chuck Lever9412b922007-12-10 14:59:21 -0500737
738 sap->sa_family = AF_UNSPEC;
Chuck Lever4c568012007-12-10 14:59:28 -0500739 *len = 0;
Chuck Lever9412b922007-12-10 14:59:21 -0500740}
741
742/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400743 * Error-check and convert a string of mount options from user space into
744 * a data structure
745 */
746static int nfs_parse_mount_options(char *raw,
747 struct nfs_parsed_mount_data *mnt)
748{
Eric Parisf9c3a382008-03-05 14:20:18 -0500749 char *p, *string, *secdata;
Eric Parisf9c3a382008-03-05 14:20:18 -0500750 int rc;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400751
752 if (!raw) {
753 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
754 return 1;
755 }
756 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
757
Eric Parisf9c3a382008-03-05 14:20:18 -0500758 secdata = alloc_secdata();
759 if (!secdata)
760 goto out_nomem;
761
762 rc = security_sb_copy_data(raw, secdata);
763 if (rc)
764 goto out_security_failure;
765
766 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
767 if (rc)
768 goto out_security_failure;
769
770 free_secdata(secdata);
771
Chuck Leverbf0fd762007-07-01 12:13:44 -0400772 while ((p = strsep(&raw, ",")) != NULL) {
773 substring_t args[MAX_OPT_ARGS];
774 int option, token;
775
776 if (!*p)
777 continue;
778
779 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
780
781 token = match_token(p, nfs_mount_option_tokens, args);
782 switch (token) {
783 case Opt_soft:
784 mnt->flags |= NFS_MOUNT_SOFT;
785 break;
786 case Opt_hard:
787 mnt->flags &= ~NFS_MOUNT_SOFT;
788 break;
789 case Opt_intr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400790 case Opt_nointr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400791 break;
792 case Opt_posix:
793 mnt->flags |= NFS_MOUNT_POSIX;
794 break;
795 case Opt_noposix:
796 mnt->flags &= ~NFS_MOUNT_POSIX;
797 break;
798 case Opt_cto:
799 mnt->flags &= ~NFS_MOUNT_NOCTO;
800 break;
801 case Opt_nocto:
802 mnt->flags |= NFS_MOUNT_NOCTO;
803 break;
804 case Opt_ac:
805 mnt->flags &= ~NFS_MOUNT_NOAC;
806 break;
807 case Opt_noac:
808 mnt->flags |= NFS_MOUNT_NOAC;
809 break;
810 case Opt_lock:
811 mnt->flags &= ~NFS_MOUNT_NONLM;
812 break;
813 case Opt_nolock:
814 mnt->flags |= NFS_MOUNT_NONLM;
815 break;
816 case Opt_v2:
817 mnt->flags &= ~NFS_MOUNT_VER3;
818 break;
819 case Opt_v3:
820 mnt->flags |= NFS_MOUNT_VER3;
821 break;
822 case Opt_udp:
823 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400824 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400825 mnt->timeo = 7;
826 mnt->retrans = 5;
827 break;
828 case Opt_tcp:
829 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400830 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400831 mnt->timeo = 600;
832 mnt->retrans = 2;
833 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400834 case Opt_rdma:
835 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
836 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
837 mnt->timeo = 600;
838 mnt->retrans = 2;
839 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400840 case Opt_acl:
841 mnt->flags &= ~NFS_MOUNT_NOACL;
842 break;
843 case Opt_noacl:
844 mnt->flags |= NFS_MOUNT_NOACL;
845 break;
846 case Opt_rdirplus:
847 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
848 break;
849 case Opt_nordirplus:
850 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
851 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400852 case Opt_sharecache:
853 mnt->flags &= ~NFS_MOUNT_UNSHARED;
854 break;
855 case Opt_nosharecache:
856 mnt->flags |= NFS_MOUNT_UNSHARED;
857 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400858
859 case Opt_port:
860 if (match_int(args, &option))
861 return 0;
862 if (option < 0 || option > 65535)
863 return 0;
Chuck Leverf22d6d72008-03-14 14:10:22 -0400864 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400865 break;
866 case Opt_rsize:
867 if (match_int(args, &mnt->rsize))
868 return 0;
869 break;
870 case Opt_wsize:
871 if (match_int(args, &mnt->wsize))
872 return 0;
873 break;
874 case Opt_bsize:
875 if (match_int(args, &option))
876 return 0;
877 if (option < 0)
878 return 0;
879 mnt->bsize = option;
880 break;
881 case Opt_timeo:
882 if (match_int(args, &mnt->timeo))
883 return 0;
884 break;
885 case Opt_retrans:
886 if (match_int(args, &mnt->retrans))
887 return 0;
888 break;
889 case Opt_acregmin:
890 if (match_int(args, &mnt->acregmin))
891 return 0;
892 break;
893 case Opt_acregmax:
894 if (match_int(args, &mnt->acregmax))
895 return 0;
896 break;
897 case Opt_acdirmin:
898 if (match_int(args, &mnt->acdirmin))
899 return 0;
900 break;
901 case Opt_acdirmax:
902 if (match_int(args, &mnt->acdirmax))
903 return 0;
904 break;
905 case Opt_actimeo:
906 if (match_int(args, &option))
907 return 0;
908 if (option < 0)
909 return 0;
910 mnt->acregmin =
911 mnt->acregmax =
912 mnt->acdirmin =
913 mnt->acdirmax = option;
914 break;
915 case Opt_namelen:
916 if (match_int(args, &mnt->namlen))
917 return 0;
918 break;
919 case Opt_mountport:
920 if (match_int(args, &option))
921 return 0;
922 if (option < 0 || option > 65535)
923 return 0;
924 mnt->mount_server.port = option;
925 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400926 case Opt_mountvers:
927 if (match_int(args, &option))
928 return 0;
929 if (option < 0)
930 return 0;
931 mnt->mount_server.version = option;
932 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400933 case Opt_nfsvers:
934 if (match_int(args, &option))
935 return 0;
936 switch (option) {
937 case 2:
938 mnt->flags &= ~NFS_MOUNT_VER3;
939 break;
940 case 3:
941 mnt->flags |= NFS_MOUNT_VER3;
942 break;
943 default:
944 goto out_unrec_vers;
945 }
946 break;
947
948 case Opt_sec:
949 string = match_strdup(args);
950 if (string == NULL)
951 goto out_nomem;
952 token = match_token(string, nfs_secflavor_tokens, args);
953 kfree(string);
954
955 /*
956 * The flags setting is for v2/v3. The flavor_len
957 * setting is for v4. v2/v3 also need to know the
958 * difference between NULL and UNIX.
959 */
960 switch (token) {
961 case Opt_sec_none:
962 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
963 mnt->auth_flavor_len = 0;
964 mnt->auth_flavors[0] = RPC_AUTH_NULL;
965 break;
966 case Opt_sec_sys:
967 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
968 mnt->auth_flavor_len = 0;
969 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
970 break;
971 case Opt_sec_krb5:
972 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
973 mnt->auth_flavor_len = 1;
974 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
975 break;
976 case Opt_sec_krb5i:
977 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
978 mnt->auth_flavor_len = 1;
979 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
980 break;
981 case Opt_sec_krb5p:
982 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
983 mnt->auth_flavor_len = 1;
984 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
985 break;
986 case Opt_sec_lkey:
987 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
988 mnt->auth_flavor_len = 1;
989 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
990 break;
991 case Opt_sec_lkeyi:
992 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
993 mnt->auth_flavor_len = 1;
994 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
995 break;
996 case Opt_sec_lkeyp:
997 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
998 mnt->auth_flavor_len = 1;
999 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
1000 break;
1001 case Opt_sec_spkm:
1002 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1003 mnt->auth_flavor_len = 1;
1004 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
1005 break;
1006 case Opt_sec_spkmi:
1007 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1008 mnt->auth_flavor_len = 1;
1009 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
1010 break;
1011 case Opt_sec_spkmp:
1012 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
1013 mnt->auth_flavor_len = 1;
1014 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
1015 break;
1016 default:
1017 goto out_unrec_sec;
1018 }
1019 break;
1020 case Opt_proto:
1021 string = match_strdup(args);
1022 if (string == NULL)
1023 goto out_nomem;
1024 token = match_token(string,
1025 nfs_xprt_protocol_tokens, args);
1026 kfree(string);
1027
1028 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001029 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001030 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001031 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001032 mnt->timeo = 7;
1033 mnt->retrans = 5;
1034 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001035 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001036 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001037 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001038 mnt->timeo = 600;
1039 mnt->retrans = 2;
1040 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001041 case Opt_xprt_rdma:
1042 /* vector side protocols to TCP */
1043 mnt->flags |= NFS_MOUNT_TCP;
1044 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1045 mnt->timeo = 600;
1046 mnt->retrans = 2;
1047 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001048 default:
1049 goto out_unrec_xprt;
1050 }
1051 break;
1052 case Opt_mountproto:
1053 string = match_strdup(args);
1054 if (string == NULL)
1055 goto out_nomem;
1056 token = match_token(string,
1057 nfs_xprt_protocol_tokens, args);
1058 kfree(string);
1059
1060 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001061 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001062 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001063 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001064 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001065 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001066 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001067 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001068 default:
1069 goto out_unrec_xprt;
1070 }
1071 break;
1072 case Opt_addr:
1073 string = match_strdup(args);
1074 if (string == NULL)
1075 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001076 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001077 &mnt->nfs_server.address,
1078 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001079 kfree(string);
1080 break;
1081 case Opt_clientaddr:
1082 string = match_strdup(args);
1083 if (string == NULL)
1084 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001085 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001086 mnt->client_address = string;
1087 break;
Chuck Lever33832032007-12-10 14:59:13 -05001088 case Opt_mounthost:
1089 string = match_strdup(args);
1090 if (string == NULL)
1091 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001092 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001093 mnt->mount_server.hostname = string;
1094 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001095 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001096 string = match_strdup(args);
1097 if (string == NULL)
1098 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001099 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001100 &mnt->mount_server.address,
1101 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001102 kfree(string);
1103 break;
1104
1105 case Opt_userspace:
1106 case Opt_deprecated:
1107 break;
1108
1109 default:
1110 goto out_unknown;
1111 }
1112 }
1113
Chuck Leverf22d6d72008-03-14 14:10:22 -04001114 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1115 mnt->nfs_server.port);
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001116
Chuck Leverbf0fd762007-07-01 12:13:44 -04001117 return 1;
1118
1119out_nomem:
1120 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1121 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001122out_security_failure:
1123 free_secdata(secdata);
1124 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1125 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001126out_unrec_vers:
1127 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1128 return 0;
1129
1130out_unrec_xprt:
1131 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1132 return 0;
1133
1134out_unrec_sec:
1135 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1136 return 0;
1137
1138out_unknown:
1139 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1140 return 0;
1141}
1142
1143/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001144 * Use the remote server's MOUNT service to request the NFS file handle
1145 * corresponding to the provided path.
1146 */
1147static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1148 struct nfs_fh *root_fh)
1149{
Chuck Lever4c568012007-12-10 14:59:28 -05001150 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001151 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001152 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001153
1154 if (args->mount_server.version == 0) {
1155 if (args->flags & NFS_MOUNT_VER3)
1156 args->mount_server.version = NFS_MNT3_VERSION;
1157 else
1158 args->mount_server.version = NFS_MNT_VERSION;
1159 }
1160
Chuck Lever33832032007-12-10 14:59:13 -05001161 if (args->mount_server.hostname)
1162 hostname = args->mount_server.hostname;
1163 else
1164 hostname = args->nfs_server.hostname;
1165
Chuck Lever0076d7b2007-07-01 12:13:49 -04001166 /*
1167 * Construct the mount server's address.
1168 */
Chuck Lever4c568012007-12-10 14:59:28 -05001169 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1170 memcpy(sap, &args->nfs_server.address,
1171 args->nfs_server.addrlen);
1172 args->mount_server.addrlen = args->nfs_server.addrlen;
1173 }
1174
James Lentiniaad70002007-09-24 17:32:49 -04001175 /*
1176 * autobind will be used if mount_server.port == 0
1177 */
Chuck Lever4c568012007-12-10 14:59:28 -05001178 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001179
1180 /*
1181 * Now ask the mount server to map our export path
1182 * to a file handle.
1183 */
Chuck Lever4c568012007-12-10 14:59:28 -05001184 status = nfs_mount(sap,
1185 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001186 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001187 args->nfs_server.export_path,
1188 args->mount_server.version,
1189 args->mount_server.protocol,
1190 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001191 if (status == 0)
1192 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001193
Chuck Lever33832032007-12-10 14:59:13 -05001194 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1195 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001196 return status;
1197}
1198
1199/*
David Howells54ceac42006-08-22 20:06:13 -04001200 * Validate the NFS2/NFS3 mount data
1201 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001202 *
1203 * For option strings, user space handles the following behaviors:
1204 *
1205 * + DNS: mapping server host name to IP address ("addr=" option)
1206 *
1207 * + failure mode: how to behave if a mount request can't be handled
1208 * immediately ("fg/bg" option)
1209 *
1210 * + retry: how often to retry a mount request ("retry=" option)
1211 *
1212 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1213 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001214 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001215static int nfs_validate_mount_data(void *options,
1216 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001217 struct nfs_fh *mntfh,
1218 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001219{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001220 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001221
Chuck Lever5df36e72007-07-01 12:12:56 -04001222 if (data == NULL)
1223 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001224
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001225 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1226 args->rsize = NFS_MAX_FILE_IO_SIZE;
1227 args->wsize = NFS_MAX_FILE_IO_SIZE;
1228 args->timeo = 600;
1229 args->retrans = 2;
1230 args->acregmin = 3;
1231 args->acregmax = 60;
1232 args->acdirmin = 30;
1233 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001234 args->mount_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001235 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001236 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001237 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001238
David Howellsf7b422b2006-06-09 09:34:33 -04001239 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001240 case 1:
1241 data->namlen = 0;
1242 case 2:
1243 data->bsize = 0;
1244 case 3:
1245 if (data->flags & NFS_MOUNT_VER3)
1246 goto out_no_v3;
1247 data->root.size = NFS2_FHSIZE;
1248 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1249 case 4:
1250 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1251 goto out_no_sec;
1252 case 5:
1253 memset(data->context, 0, sizeof(data->context));
1254 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001255 if (data->flags & NFS_MOUNT_VER3) {
1256 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1257 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001258 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001259 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001260 mntfh->size = NFS2_FHSIZE;
1261
Chuck Lever5df36e72007-07-01 12:12:56 -04001262
1263 memcpy(mntfh->data, data->root.data, mntfh->size);
1264 if (mntfh->size < sizeof(mntfh->data))
1265 memset(mntfh->data + mntfh->size, 0,
1266 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001267
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001268 /*
1269 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1270 * can deal with.
1271 */
1272 args->flags = data->flags;
1273 args->rsize = data->rsize;
1274 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001275 args->timeo = data->timeo;
1276 args->retrans = data->retrans;
1277 args->acregmin = data->acregmin;
1278 args->acregmax = data->acregmax;
1279 args->acdirmin = data->acdirmin;
1280 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001281
1282 memcpy(&args->nfs_server.address, &data->addr,
1283 sizeof(data->addr));
1284 args->nfs_server.addrlen = sizeof(data->addr);
1285 if (!nfs_verify_server_address((struct sockaddr *)
1286 &args->nfs_server.address))
1287 goto out_no_address;
1288
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001289 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001290 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001291 /* N.B. caller will free nfs_server.hostname in all cases */
1292 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1293 args->namlen = data->namlen;
1294 args->bsize = data->bsize;
1295 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001296 if (!args->nfs_server.hostname)
1297 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001298
1299 /*
1300 * The legacy version 6 binary mount data from userspace has a
1301 * field used only to transport selinux information into the
1302 * the kernel. To continue to support that functionality we
1303 * have a touch of selinux knowledge here in the NFS code. The
1304 * userspace code converted context=blah to just blah so we are
1305 * converting back to the full string selinux understands.
1306 */
1307 if (data->context[0]){
1308#ifdef CONFIG_SECURITY_SELINUX
1309 int rc;
1310 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1311 if (!opts_str)
1312 return -ENOMEM;
1313 strcpy(opts_str, "context=");
1314 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1315 strcat(opts_str, &data->context[0]);
1316 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1317 kfree(opts_str);
1318 if (rc)
1319 return rc;
1320#else
1321 return -EINVAL;
1322#endif
1323 }
1324
Chuck Lever5df36e72007-07-01 12:12:56 -04001325 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001326 default: {
1327 unsigned int len;
1328 char *c;
1329 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001330
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001331 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001332 return -EINVAL;
1333
Chuck Lever6e88e062007-09-24 15:39:50 -04001334 if (!nfs_verify_server_address((struct sockaddr *)
1335 &args->nfs_server.address))
1336 goto out_no_address;
1337
Chuck Lever136d5582007-07-01 12:13:54 -04001338 c = strchr(dev_name, ':');
1339 if (c == NULL)
1340 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001341 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001342 /* N.B. caller will free nfs_server.hostname in all cases */
1343 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001344 if (!args->nfs_server.hostname)
1345 goto out_nomem;
Chuck Lever136d5582007-07-01 12:13:54 -04001346
1347 c++;
1348 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001349 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001350 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001351
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001352 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001353 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001354 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001355
Chuck Lever136d5582007-07-01 12:13:54 -04001356 break;
1357 }
David Howellsf7b422b2006-06-09 09:34:33 -04001358 }
David Howells54ceac42006-08-22 20:06:13 -04001359
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001360 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1361 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001362
David Howellsf7b422b2006-06-09 09:34:33 -04001363#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001364 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001365 goto out_v3_not_compiled;
1366#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001367
David Howells54ceac42006-08-22 20:06:13 -04001368 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001369
1370out_no_data:
1371 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1372 return -EINVAL;
1373
1374out_no_v3:
1375 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1376 data->version);
1377 return -EINVAL;
1378
1379out_no_sec:
1380 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1381 return -EINVAL;
1382
Chuck Lever5df36e72007-07-01 12:12:56 -04001383#ifndef CONFIG_NFS_V3
1384out_v3_not_compiled:
1385 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1386 return -EPROTONOSUPPORT;
1387#endif /* !CONFIG_NFS_V3 */
1388
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001389out_nomem:
1390 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1391 return -ENOMEM;
1392
Chuck Lever5df36e72007-07-01 12:12:56 -04001393out_no_address:
1394 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1395 return -EINVAL;
1396
1397out_invalid_fh:
1398 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1399 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001400}
1401
Jeff Layton48b605f2008-06-10 15:38:39 -04001402static int
1403nfs_compare_remount_data(struct nfs_server *nfss,
1404 struct nfs_parsed_mount_data *data)
1405{
1406 if (data->flags != nfss->flags ||
1407 data->rsize != nfss->rsize ||
1408 data->wsize != nfss->wsize ||
1409 data->retrans != nfss->client->cl_timeout->to_retries ||
1410 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1411 data->acregmin != nfss->acregmin / HZ ||
1412 data->acregmax != nfss->acregmax / HZ ||
1413 data->acdirmin != nfss->acdirmin / HZ ||
1414 data->acdirmax != nfss->acdirmax / HZ ||
1415 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1416 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1417 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1418 data->nfs_server.addrlen) != 0)
1419 return -EINVAL;
1420
1421 return 0;
1422}
1423
1424static int
1425nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1426{
1427 int error;
1428 struct nfs_server *nfss = sb->s_fs_info;
1429 struct nfs_parsed_mount_data *data;
1430 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1431 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1432
1433 /*
1434 * Userspace mount programs that send binary options generally send
1435 * them populated with default values. We have no way to know which
1436 * ones were explicitly specified. Fall back to legacy behavior and
1437 * just return success.
1438 */
1439 if ((sb->s_type == &nfs4_fs_type && options4->version == 1) ||
1440 (sb->s_type == &nfs_fs_type && options->version >= 1 &&
1441 options->version <= 6))
1442 return 0;
1443
1444 data = kzalloc(sizeof(*data), GFP_KERNEL);
1445 if (data == NULL)
1446 return -ENOMEM;
1447
1448 /* fill out struct with values from existing mount */
1449 data->flags = nfss->flags;
1450 data->rsize = nfss->rsize;
1451 data->wsize = nfss->wsize;
1452 data->retrans = nfss->client->cl_timeout->to_retries;
1453 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1454 data->acregmin = nfss->acregmin / HZ;
1455 data->acregmax = nfss->acregmax / HZ;
1456 data->acdirmin = nfss->acdirmin / HZ;
1457 data->acdirmax = nfss->acdirmax / HZ;
1458 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1459 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1460 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1461 data->nfs_server.addrlen);
1462
1463 /* overwrite those values with any that were specified */
1464 error = nfs_parse_mount_options((char *)options, data);
1465 if (error < 0)
1466 goto out;
1467
1468 /* compare new mount options with old ones */
1469 error = nfs_compare_remount_data(nfss, data);
1470out:
1471 kfree(data);
1472 return error;
1473}
1474
David Howells54ceac42006-08-22 20:06:13 -04001475/*
1476 * Initialise the common bits of the superblock
1477 */
1478static inline void nfs_initialise_sb(struct super_block *sb)
1479{
1480 struct nfs_server *server = NFS_SB(sb);
1481
1482 sb->s_magic = NFS_SUPER_MAGIC;
1483
1484 /* We probably want something more informative here */
1485 snprintf(sb->s_id, sizeof(sb->s_id),
1486 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1487
1488 if (sb->s_blocksize == 0)
1489 sb->s_blocksize = nfs_block_bits(server->wsize,
1490 &sb->s_blocksize_bits);
1491
1492 if (server->flags & NFS_MOUNT_NOAC)
1493 sb->s_flags |= MS_SYNCHRONOUS;
1494
1495 nfs_super_set_maxbytes(sb, server->maxfilesize);
1496}
1497
1498/*
1499 * Finish setting up an NFS2/3 superblock
1500 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001501static void nfs_fill_super(struct super_block *sb,
1502 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001503{
1504 struct nfs_server *server = NFS_SB(sb);
1505
1506 sb->s_blocksize_bits = 0;
1507 sb->s_blocksize = 0;
1508 if (data->bsize)
1509 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1510
1511 if (server->flags & NFS_MOUNT_VER3) {
1512 /* The VFS shouldn't apply the umask to mode bits. We will do
1513 * so ourselves when necessary.
1514 */
1515 sb->s_flags |= MS_POSIXACL;
1516 sb->s_time_gran = 1;
1517 }
1518
1519 sb->s_op = &nfs_sops;
1520 nfs_initialise_sb(sb);
1521}
1522
1523/*
1524 * Finish setting up a cloned NFS2/3 superblock
1525 */
1526static void nfs_clone_super(struct super_block *sb,
1527 const struct super_block *old_sb)
1528{
1529 struct nfs_server *server = NFS_SB(sb);
1530
1531 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1532 sb->s_blocksize = old_sb->s_blocksize;
1533 sb->s_maxbytes = old_sb->s_maxbytes;
1534
1535 if (server->flags & NFS_MOUNT_VER3) {
1536 /* The VFS shouldn't apply the umask to mode bits. We will do
1537 * so ourselves when necessary.
1538 */
1539 sb->s_flags |= MS_POSIXACL;
1540 sb->s_time_gran = 1;
1541 }
1542
1543 sb->s_op = old_sb->s_op;
1544 nfs_initialise_sb(sb);
1545}
1546
Trond Myklebust275a5d22007-05-16 16:53:28 -04001547#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1548
1549static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1550{
1551 const struct nfs_server *a = s->s_fs_info;
1552 const struct rpc_clnt *clnt_a = a->client;
1553 const struct rpc_clnt *clnt_b = b->client;
1554
1555 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1556 goto Ebusy;
1557 if (a->nfs_client != b->nfs_client)
1558 goto Ebusy;
1559 if (a->flags != b->flags)
1560 goto Ebusy;
1561 if (a->wsize != b->wsize)
1562 goto Ebusy;
1563 if (a->rsize != b->rsize)
1564 goto Ebusy;
1565 if (a->acregmin != b->acregmin)
1566 goto Ebusy;
1567 if (a->acregmax != b->acregmax)
1568 goto Ebusy;
1569 if (a->acdirmin != b->acdirmin)
1570 goto Ebusy;
1571 if (a->acdirmax != b->acdirmax)
1572 goto Ebusy;
1573 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1574 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001575 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001576Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001577 return 0;
1578}
1579
1580struct nfs_sb_mountdata {
1581 struct nfs_server *server;
1582 int mntflags;
1583};
1584
1585static int nfs_set_super(struct super_block *s, void *data)
1586{
1587 struct nfs_sb_mountdata *sb_mntdata = data;
1588 struct nfs_server *server = sb_mntdata->server;
1589 int ret;
1590
1591 s->s_flags = sb_mntdata->mntflags;
1592 s->s_fs_info = server;
1593 ret = set_anon_super(s, server);
1594 if (ret == 0)
1595 server->s_dev = s->s_dev;
1596 return ret;
1597}
1598
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001599static int nfs_compare_super_address(struct nfs_server *server1,
1600 struct nfs_server *server2)
1601{
1602 struct sockaddr *sap1, *sap2;
1603
1604 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1605 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1606
1607 if (sap1->sa_family != sap2->sa_family)
1608 return 0;
1609
1610 switch (sap1->sa_family) {
1611 case AF_INET: {
1612 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1613 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1614 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1615 return 0;
1616 if (sin1->sin_port != sin2->sin_port)
1617 return 0;
1618 break;
1619 }
1620 case AF_INET6: {
1621 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1622 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1623 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1624 return 0;
1625 if (sin1->sin6_port != sin2->sin6_port)
1626 return 0;
1627 break;
1628 }
1629 default:
1630 return 0;
1631 }
1632
1633 return 1;
1634}
1635
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001636static int nfs_compare_super(struct super_block *sb, void *data)
1637{
1638 struct nfs_sb_mountdata *sb_mntdata = data;
1639 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1640 int mntflags = sb_mntdata->mntflags;
1641
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001642 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001643 return 0;
1644 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1645 if (old->flags & NFS_MOUNT_UNSHARED)
1646 return 0;
1647 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1648 return 0;
1649 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001650}
1651
Miklos Szeredifa799752008-04-30 00:54:33 -07001652static int nfs_bdi_register(struct nfs_server *server)
1653{
1654 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1655}
1656
David Howells54ceac42006-08-22 20:06:13 -04001657static int nfs_get_sb(struct file_system_type *fs_type,
1658 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1659{
1660 struct nfs_server *server = NULL;
1661 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001662 struct nfs_parsed_mount_data *data;
1663 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001664 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001665 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001666 struct nfs_sb_mountdata sb_mntdata = {
1667 .mntflags = flags,
1668 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001669 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001670
Trond Myklebust33852a12008-06-19 14:20:11 -04001671 data = kzalloc(sizeof(*data), GFP_KERNEL);
1672 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1673 if (data == NULL || mntfh == NULL)
1674 goto out_free_fh;
1675
1676 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001677
David Howells54ceac42006-08-22 20:06:13 -04001678 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04001679 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001680 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001681 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001682
1683 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001684 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001685 if (IS_ERR(server)) {
1686 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001687 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001688 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001689 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001690
Trond Myklebust75180df2007-05-16 16:53:28 -04001691 if (server->flags & NFS_MOUNT_UNSHARED)
1692 compare_super = NULL;
1693
David Howells54ceac42006-08-22 20:06:13 -04001694 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001695 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001696 if (IS_ERR(s)) {
1697 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001698 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001699 }
1700
David Howells54ceac42006-08-22 20:06:13 -04001701 if (s->s_fs_info != server) {
1702 nfs_free_server(server);
1703 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07001704 } else {
1705 error = nfs_bdi_register(server);
1706 if (error)
1707 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001708 }
David Howells54ceac42006-08-22 20:06:13 -04001709
1710 if (!s->s_root) {
1711 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001712 nfs_fill_super(s, data);
David Howells54ceac42006-08-22 20:06:13 -04001713 }
1714
Trond Myklebust33852a12008-06-19 14:20:11 -04001715 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001716 if (IS_ERR(mntroot)) {
1717 error = PTR_ERR(mntroot);
1718 goto error_splat_super;
1719 }
1720
Trond Myklebust33852a12008-06-19 14:20:11 -04001721 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001722 if (error)
1723 goto error_splat_root;
1724
David Howellsf7b422b2006-06-09 09:34:33 -04001725 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001726 mnt->mnt_sb = s;
1727 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001728 error = 0;
1729
1730out:
Trond Myklebust33852a12008-06-19 14:20:11 -04001731 kfree(data->nfs_server.hostname);
1732 kfree(data->mount_server.hostname);
1733 security_free_mnt_opts(&data->lsm_opts);
1734out_free_fh:
1735 kfree(mntfh);
1736 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04001737 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001738
David Howells54ceac42006-08-22 20:06:13 -04001739out_err_nosb:
1740 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001741 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001742
Eric Parisf9c3a382008-03-05 14:20:18 -05001743error_splat_root:
1744 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04001745error_splat_super:
1746 up_write(&s->s_umount);
1747 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001748 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001749}
1750
David Howells54ceac42006-08-22 20:06:13 -04001751/*
1752 * Destroy an NFS2/3 superblock
1753 */
David Howellsf7b422b2006-06-09 09:34:33 -04001754static void nfs_kill_super(struct super_block *s)
1755{
1756 struct nfs_server *server = NFS_SB(s);
1757
Miklos Szeredifa799752008-04-30 00:54:33 -07001758 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04001759 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001760 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001761}
1762
David Howells54ceac42006-08-22 20:06:13 -04001763/*
1764 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1765 */
1766static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1767 const char *dev_name, void *raw_data,
1768 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001769{
1770 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001771 struct super_block *s;
1772 struct nfs_server *server;
1773 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001774 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001775 struct nfs_sb_mountdata sb_mntdata = {
1776 .mntflags = flags,
1777 };
David Howells54ceac42006-08-22 20:06:13 -04001778 int error;
1779
1780 dprintk("--> nfs_xdev_get_sb()\n");
1781
1782 /* create a new volume representation */
1783 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1784 if (IS_ERR(server)) {
1785 error = PTR_ERR(server);
1786 goto out_err_noserver;
1787 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001788 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001789
Trond Myklebust75180df2007-05-16 16:53:28 -04001790 if (server->flags & NFS_MOUNT_UNSHARED)
1791 compare_super = NULL;
1792
David Howells54ceac42006-08-22 20:06:13 -04001793 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001794 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001795 if (IS_ERR(s)) {
1796 error = PTR_ERR(s);
1797 goto out_err_nosb;
1798 }
1799
1800 if (s->s_fs_info != server) {
1801 nfs_free_server(server);
1802 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07001803 } else {
1804 error = nfs_bdi_register(server);
1805 if (error)
1806 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04001807 }
1808
1809 if (!s->s_root) {
1810 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001811 nfs_clone_super(s, data->sb);
1812 }
1813
1814 mntroot = nfs_get_root(s, data->fh);
1815 if (IS_ERR(mntroot)) {
1816 error = PTR_ERR(mntroot);
1817 goto error_splat_super;
1818 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001819 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001820 dput(mntroot);
1821 error = -ESTALE;
1822 goto error_splat_super;
1823 }
David Howells54ceac42006-08-22 20:06:13 -04001824
1825 s->s_flags |= MS_ACTIVE;
1826 mnt->mnt_sb = s;
1827 mnt->mnt_root = mntroot;
1828
Eric Parisf9c3a382008-03-05 14:20:18 -05001829 /* clone any lsm security options from the parent to the new sb */
1830 security_sb_clone_mnt_opts(data->sb, s);
1831
David Howells54ceac42006-08-22 20:06:13 -04001832 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1833 return 0;
1834
1835out_err_nosb:
1836 nfs_free_server(server);
1837out_err_noserver:
1838 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1839 return error;
1840
1841error_splat_super:
1842 up_write(&s->s_umount);
1843 deactivate_super(s);
1844 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1845 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001846}
1847
1848#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001849
1850/*
1851 * Finish setting up a cloned NFS4 superblock
1852 */
1853static void nfs4_clone_super(struct super_block *sb,
1854 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001855{
David Howells54ceac42006-08-22 20:06:13 -04001856 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1857 sb->s_blocksize = old_sb->s_blocksize;
1858 sb->s_maxbytes = old_sb->s_maxbytes;
1859 sb->s_time_gran = 1;
1860 sb->s_op = old_sb->s_op;
1861 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001862}
1863
1864/*
1865 * Set up an NFS4 superblock
1866 */
David Howells54ceac42006-08-22 20:06:13 -04001867static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001868{
David Howellsf7b422b2006-06-09 09:34:33 -04001869 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001870 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001871 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001872}
1873
David Howells54ceac42006-08-22 20:06:13 -04001874/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001875 * Validate NFSv4 mount options
1876 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001877static int nfs4_validate_mount_data(void *options,
1878 struct nfs_parsed_mount_data *args,
1879 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001880{
Chuck Lever4c568012007-12-10 14:59:28 -05001881 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001882 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001883 char *c;
1884
1885 if (data == NULL)
1886 goto out_no_data;
1887
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001888 args->rsize = NFS_MAX_FILE_IO_SIZE;
1889 args->wsize = NFS_MAX_FILE_IO_SIZE;
1890 args->timeo = 600;
1891 args->retrans = 2;
1892 args->acregmin = 3;
1893 args->acregmax = 60;
1894 args->acdirmin = 30;
1895 args->acdirmax = 60;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001896 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001897 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001898
Chuck Leverf0768eb2007-07-01 12:13:01 -04001899 switch (data->version) {
1900 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05001901 ap = (struct sockaddr_in *)&args->nfs_server.address;
1902 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001903 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05001904 if (data->host_addrlen == 0)
1905 goto out_no_address;
1906 args->nfs_server.addrlen = data->host_addrlen;
1907 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001908 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001909 if (!nfs_verify_server_address((struct sockaddr *)
1910 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001911 goto out_no_address;
1912
1913 switch (data->auth_flavourlen) {
1914 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001915 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001916 break;
1917 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001918 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001919 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001920 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001921 return -EFAULT;
1922 break;
1923 default:
1924 goto out_inval_auth;
1925 }
1926
1927 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1928 if (IS_ERR(c))
1929 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001930 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001931
1932 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1933 if (IS_ERR(c))
1934 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001935 args->nfs_server.export_path = c;
1936 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001937
1938 c = strndup_user(data->client_addr.data, 16);
1939 if (IS_ERR(c))
1940 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001941 args->client_address = c;
1942
1943 /*
1944 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1945 * can deal with.
1946 */
1947
1948 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1949 args->rsize = data->rsize;
1950 args->wsize = data->wsize;
1951 args->timeo = data->timeo;
1952 args->retrans = data->retrans;
1953 args->acregmin = data->acregmin;
1954 args->acregmax = data->acregmax;
1955 args->acdirmin = data->acdirmin;
1956 args->acdirmax = data->acdirmax;
1957 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001958
1959 break;
Chuck Lever80071222007-07-01 12:13:59 -04001960 default: {
1961 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001962
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001963 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001964 return -EINVAL;
1965
1966 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001967 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001968 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001969
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001970 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001971 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001972 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001973 break;
1974 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001975 break;
1976 default:
1977 goto out_inval_auth;
1978 }
1979
1980 /*
Chuck Lever80071222007-07-01 12:13:59 -04001981 * Split "dev_name" into "hostname:mntpath".
1982 */
1983 c = strchr(dev_name, ':');
1984 if (c == NULL)
1985 return -EINVAL;
1986 /* while calculating len, pretend ':' is '\0' */
1987 len = c - dev_name;
1988 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001989 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001990 /* N.B. caller will free nfs_server.hostname in all cases */
1991 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001992 if (!args->nfs_server.hostname)
1993 goto out_nomem;
Chuck Lever80071222007-07-01 12:13:59 -04001994
1995 c++; /* step over the ':' */
1996 len = strlen(c);
1997 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001998 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001999 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002000 if (!args->nfs_server.export_path)
2001 goto out_nomem;
Chuck Lever80071222007-07-01 12:13:59 -04002002
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04002003 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04002004
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002005 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002006 goto out_no_client_address;
2007
Chuck Lever80071222007-07-01 12:13:59 -04002008 break;
2009 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002010 }
2011
2012 return 0;
2013
2014out_no_data:
2015 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2016 return -EINVAL;
2017
2018out_inval_auth:
2019 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2020 data->auth_flavourlen);
2021 return -EINVAL;
2022
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04002023out_nomem:
2024 dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n");
2025 return -ENOMEM;
2026
Chuck Leverf0768eb2007-07-01 12:13:01 -04002027out_no_address:
2028 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2029 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002030
2031out_no_client_address:
2032 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2033 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002034}
2035
2036/*
David Howells54ceac42006-08-22 20:06:13 -04002037 * Get the superblock for an NFS4 mountpoint
2038 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002039static int nfs4_get_sb(struct file_system_type *fs_type,
2040 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002041{
Trond Myklebust33852a12008-06-19 14:20:11 -04002042 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002043 struct super_block *s;
2044 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002045 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002046 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002047 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002048 struct nfs_sb_mountdata sb_mntdata = {
2049 .mntflags = flags,
2050 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002051 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002052
Trond Myklebust33852a12008-06-19 14:20:11 -04002053 data = kzalloc(sizeof(*data), GFP_KERNEL);
2054 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2055 if (data == NULL || mntfh == NULL)
2056 goto out_free_fh;
2057
2058 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002059
Chuck Leverf0768eb2007-07-01 12:13:01 -04002060 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002061 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002062 if (error < 0)
2063 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002064
David Howells54ceac42006-08-22 20:06:13 -04002065 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002066 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002067 if (IS_ERR(server)) {
2068 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002069 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002070 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002071 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002072
Trond Myklebust75180df2007-05-16 16:53:28 -04002073 if (server->flags & NFS4_MOUNT_UNSHARED)
2074 compare_super = NULL;
2075
David Howells54ceac42006-08-22 20:06:13 -04002076 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002077 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002078 if (IS_ERR(s)) {
2079 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002080 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002081 }
2082
Trond Myklebust5dd31772006-08-24 01:03:05 -04002083 if (s->s_fs_info != server) {
2084 nfs_free_server(server);
2085 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002086 } else {
2087 error = nfs_bdi_register(server);
2088 if (error)
2089 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002090 }
2091
David Howells54ceac42006-08-22 20:06:13 -04002092 if (!s->s_root) {
2093 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002094 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04002095 }
David Howellsf7b422b2006-06-09 09:34:33 -04002096
Trond Myklebust33852a12008-06-19 14:20:11 -04002097 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002098 if (IS_ERR(mntroot)) {
2099 error = PTR_ERR(mntroot);
2100 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002101 }
David Howells54ceac42006-08-22 20:06:13 -04002102
Trond Myklebust33852a12008-06-19 14:20:11 -04002103 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002104 if (error)
2105 goto error_splat_root;
2106
David Howellsf7b422b2006-06-09 09:34:33 -04002107 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002108 mnt->mnt_sb = s;
2109 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002110 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002111
Chuck Lever29eb9812007-07-01 12:12:30 -04002112out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002113 kfree(data->client_address);
2114 kfree(data->nfs_server.export_path);
2115 kfree(data->nfs_server.hostname);
2116 security_free_mnt_opts(&data->lsm_opts);
2117out_free_fh:
2118 kfree(mntfh);
2119 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002120 return error;
David Howells54ceac42006-08-22 20:06:13 -04002121
Chuck Lever29eb9812007-07-01 12:12:30 -04002122out_free:
2123 nfs_free_server(server);
2124 goto out;
2125
Eric Paris46c8ac72008-05-02 13:42:42 -07002126error_splat_root:
2127 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002128error_splat_super:
2129 up_write(&s->s_umount);
2130 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002131 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002132}
2133
2134static void nfs4_kill_super(struct super_block *sb)
2135{
2136 struct nfs_server *server = NFS_SB(sb);
2137
2138 nfs_return_all_delegations(sb);
2139 kill_anon_super(sb);
2140
2141 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002142 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002143}
2144
2145/*
David Howells54ceac42006-08-22 20:06:13 -04002146 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002147 */
David Howells54ceac42006-08-22 20:06:13 -04002148static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2149 const char *dev_name, void *raw_data,
2150 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002151{
2152 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002153 struct super_block *s;
2154 struct nfs_server *server;
2155 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002156 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002157 struct nfs_sb_mountdata sb_mntdata = {
2158 .mntflags = flags,
2159 };
David Howells54ceac42006-08-22 20:06:13 -04002160 int error;
2161
2162 dprintk("--> nfs4_xdev_get_sb()\n");
2163
2164 /* create a new volume representation */
2165 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2166 if (IS_ERR(server)) {
2167 error = PTR_ERR(server);
2168 goto out_err_noserver;
2169 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002170 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002171
Trond Myklebust75180df2007-05-16 16:53:28 -04002172 if (server->flags & NFS4_MOUNT_UNSHARED)
2173 compare_super = NULL;
2174
David Howells54ceac42006-08-22 20:06:13 -04002175 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002176 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002177 if (IS_ERR(s)) {
2178 error = PTR_ERR(s);
2179 goto out_err_nosb;
2180 }
2181
2182 if (s->s_fs_info != server) {
2183 nfs_free_server(server);
2184 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002185 } else {
2186 error = nfs_bdi_register(server);
2187 if (error)
2188 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002189 }
2190
2191 if (!s->s_root) {
2192 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002193 nfs4_clone_super(s, data->sb);
2194 }
2195
2196 mntroot = nfs4_get_root(s, data->fh);
2197 if (IS_ERR(mntroot)) {
2198 error = PTR_ERR(mntroot);
2199 goto error_splat_super;
2200 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002201 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2202 dput(mntroot);
2203 error = -ESTALE;
2204 goto error_splat_super;
2205 }
David Howells54ceac42006-08-22 20:06:13 -04002206
2207 s->s_flags |= MS_ACTIVE;
2208 mnt->mnt_sb = s;
2209 mnt->mnt_root = mntroot;
2210
Eric Paris46c8ac72008-05-02 13:42:42 -07002211 security_sb_clone_mnt_opts(data->sb, s);
2212
David Howells54ceac42006-08-22 20:06:13 -04002213 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2214 return 0;
2215
2216out_err_nosb:
2217 nfs_free_server(server);
2218out_err_noserver:
2219 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2220 return error;
2221
2222error_splat_super:
2223 up_write(&s->s_umount);
2224 deactivate_super(s);
2225 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2226 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002227}
2228
David Howells54ceac42006-08-22 20:06:13 -04002229/*
2230 * Create an NFS4 server record on referral traversal
2231 */
2232static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2233 const char *dev_name, void *raw_data,
2234 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002235{
2236 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002237 struct super_block *s;
2238 struct nfs_server *server;
2239 struct dentry *mntroot;
2240 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002241 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002242 struct nfs_sb_mountdata sb_mntdata = {
2243 .mntflags = flags,
2244 };
David Howells54ceac42006-08-22 20:06:13 -04002245 int error;
2246
2247 dprintk("--> nfs4_referral_get_sb()\n");
2248
2249 /* create a new volume representation */
2250 server = nfs4_create_referral_server(data, &mntfh);
2251 if (IS_ERR(server)) {
2252 error = PTR_ERR(server);
2253 goto out_err_noserver;
2254 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002255 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002256
Trond Myklebust75180df2007-05-16 16:53:28 -04002257 if (server->flags & NFS4_MOUNT_UNSHARED)
2258 compare_super = NULL;
2259
David Howells54ceac42006-08-22 20:06:13 -04002260 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002261 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002262 if (IS_ERR(s)) {
2263 error = PTR_ERR(s);
2264 goto out_err_nosb;
2265 }
2266
2267 if (s->s_fs_info != server) {
2268 nfs_free_server(server);
2269 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002270 } else {
2271 error = nfs_bdi_register(server);
2272 if (error)
2273 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002274 }
2275
2276 if (!s->s_root) {
2277 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002278 nfs4_fill_super(s);
2279 }
2280
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002281 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002282 if (IS_ERR(mntroot)) {
2283 error = PTR_ERR(mntroot);
2284 goto error_splat_super;
2285 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002286 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2287 dput(mntroot);
2288 error = -ESTALE;
2289 goto error_splat_super;
2290 }
David Howells54ceac42006-08-22 20:06:13 -04002291
2292 s->s_flags |= MS_ACTIVE;
2293 mnt->mnt_sb = s;
2294 mnt->mnt_root = mntroot;
2295
Eric Paris46c8ac72008-05-02 13:42:42 -07002296 security_sb_clone_mnt_opts(data->sb, s);
2297
David Howells54ceac42006-08-22 20:06:13 -04002298 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2299 return 0;
2300
2301out_err_nosb:
2302 nfs_free_server(server);
2303out_err_noserver:
2304 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2305 return error;
2306
2307error_splat_super:
2308 up_write(&s->s_umount);
2309 deactivate_super(s);
2310 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2311 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002312}
2313
David Howells54ceac42006-08-22 20:06:13 -04002314#endif /* CONFIG_NFS_V4 */