blob: 1e3558697219fc8ad8544700736571449c3f164a [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,
Trond Myklebust7973c1f2008-07-15 17:58:14 -040094 Opt_lookupcache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040095
Chuck Leverf45663c2008-06-24 19:28:02 -040096 /* Special mount options */
97 Opt_userspace, Opt_deprecated, Opt_sloppy,
Chuck Leverbf0fd762007-07-01 12:13:44 -040098
99 Opt_err
100};
101
102static match_table_t nfs_mount_option_tokens = {
103 { Opt_userspace, "bg" },
104 { Opt_userspace, "fg" },
Chuck Leverecbb3842008-06-12 12:37:33 -0400105 { Opt_userspace, "retry=%s" },
106
Chuck Leverf45663c2008-06-24 19:28:02 -0400107 { Opt_sloppy, "sloppy" },
108
Chuck Leverbf0fd762007-07-01 12:13:44 -0400109 { Opt_soft, "soft" },
110 { Opt_hard, "hard" },
Chuck Leverd33e4df2008-06-12 12:37:41 -0400111 { Opt_deprecated, "intr" },
112 { Opt_deprecated, "nointr" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400113 { Opt_posix, "posix" },
114 { Opt_noposix, "noposix" },
115 { Opt_cto, "cto" },
116 { Opt_nocto, "nocto" },
117 { Opt_ac, "ac" },
118 { Opt_noac, "noac" },
119 { Opt_lock, "lock" },
120 { Opt_nolock, "nolock" },
121 { Opt_v2, "v2" },
122 { Opt_v3, "v3" },
123 { Opt_udp, "udp" },
124 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400125 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400126 { Opt_acl, "acl" },
127 { Opt_noacl, "noacl" },
128 { Opt_rdirplus, "rdirplus" },
129 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400130 { Opt_sharecache, "sharecache" },
131 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400132
133 { Opt_port, "port=%u" },
134 { Opt_rsize, "rsize=%u" },
135 { Opt_wsize, "wsize=%u" },
136 { Opt_bsize, "bsize=%u" },
137 { Opt_timeo, "timeo=%u" },
138 { Opt_retrans, "retrans=%u" },
139 { Opt_acregmin, "acregmin=%u" },
140 { Opt_acregmax, "acregmax=%u" },
141 { Opt_acdirmin, "acdirmin=%u" },
142 { Opt_acdirmax, "acdirmax=%u" },
143 { Opt_actimeo, "actimeo=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400144 { Opt_namelen, "namlen=%u" },
145 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400146 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400147 { Opt_nfsvers, "nfsvers=%u" },
148 { Opt_nfsvers, "vers=%u" },
149
150 { Opt_sec, "sec=%s" },
151 { Opt_proto, "proto=%s" },
152 { Opt_mountproto, "mountproto=%s" },
153 { Opt_addr, "addr=%s" },
154 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500155 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400156 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400157
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400158 { Opt_lookupcache, "lookupcache=%s" },
159
Chuck Leverbf0fd762007-07-01 12:13:44 -0400160 { Opt_err, NULL }
161};
162
163enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400164 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400165
166 Opt_xprt_err
167};
168
169static match_table_t nfs_xprt_protocol_tokens = {
170 { Opt_xprt_udp, "udp" },
171 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400172 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400173
174 { Opt_xprt_err, NULL }
175};
176
177enum {
178 Opt_sec_none, Opt_sec_sys,
179 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
180 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
181 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
182
183 Opt_sec_err
184};
185
186static match_table_t nfs_secflavor_tokens = {
187 { Opt_sec_none, "none" },
188 { Opt_sec_none, "null" },
189 { Opt_sec_sys, "sys" },
190
191 { Opt_sec_krb5, "krb5" },
192 { Opt_sec_krb5i, "krb5i" },
193 { Opt_sec_krb5p, "krb5p" },
194
195 { Opt_sec_lkey, "lkey" },
196 { Opt_sec_lkeyi, "lkeyi" },
197 { Opt_sec_lkeyp, "lkeyp" },
198
Olga Kornievskaia8d042212008-02-13 16:47:06 -0500199 { Opt_sec_spkm, "spkm3" },
200 { Opt_sec_spkmi, "spkm3i" },
201 { Opt_sec_spkmp, "spkm3p" },
202
Chuck Leverbf0fd762007-07-01 12:13:44 -0400203 { Opt_sec_err, NULL }
204};
205
Trond Myklebust7973c1f2008-07-15 17:58:14 -0400206enum {
207 Opt_lookupcache_all, Opt_lookupcache_positive,
208 Opt_lookupcache_none,
209
210 Opt_lookupcache_err
211};
212
213static match_table_t nfs_lookupcache_tokens = {
214 { Opt_lookupcache_all, "all" },
215 { Opt_lookupcache_positive, "pos" },
216 { Opt_lookupcache_positive, "positive" },
217 { Opt_lookupcache_none, "none" },
218
219 { Opt_lookupcache_err, NULL }
220};
221
Chuck Leverbf0fd762007-07-01 12:13:44 -0400222
Al Viro42faad92008-04-24 07:21:56 -0400223static void nfs_umount_begin(struct super_block *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400224static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400225static int nfs_show_options(struct seq_file *, struct vfsmount *);
226static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400227static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400228static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400229 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400230static void nfs_kill_super(struct super_block *);
Jeff Layton48b605f2008-06-10 15:38:39 -0400231static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
David Howellsf7b422b2006-06-09 09:34:33 -0400232
233static struct file_system_type nfs_fs_type = {
234 .owner = THIS_MODULE,
235 .name = "nfs",
236 .get_sb = nfs_get_sb,
237 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700238 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400239};
240
David Howells54ceac42006-08-22 20:06:13 -0400241struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400242 .owner = THIS_MODULE,
243 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400244 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400245 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700246 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400247};
248
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800249static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400250 .alloc_inode = nfs_alloc_inode,
251 .destroy_inode = nfs_destroy_inode,
252 .write_inode = nfs_write_inode,
253 .statfs = nfs_statfs,
254 .clear_inode = nfs_clear_inode,
255 .umount_begin = nfs_umount_begin,
256 .show_options = nfs_show_options,
257 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400258 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400259};
260
261#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400262static int nfs4_get_sb(struct file_system_type *fs_type,
263 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400264static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
265 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
266static int nfs4_referral_get_sb(struct file_system_type *fs_type,
267 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400268static void nfs4_kill_super(struct super_block *sb);
269
270static struct file_system_type nfs4_fs_type = {
271 .owner = THIS_MODULE,
272 .name = "nfs4",
273 .get_sb = nfs4_get_sb,
274 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700275 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400276};
277
David Howells54ceac42006-08-22 20:06:13 -0400278struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400279 .owner = THIS_MODULE,
280 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400281 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400282 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700283 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400284};
285
David Howells54ceac42006-08-22 20:06:13 -0400286struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400287 .owner = THIS_MODULE,
288 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400289 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400290 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700291 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400292};
293
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800294static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400295 .alloc_inode = nfs_alloc_inode,
296 .destroy_inode = nfs_destroy_inode,
297 .write_inode = nfs_write_inode,
298 .statfs = nfs_statfs,
299 .clear_inode = nfs4_clear_inode,
300 .umount_begin = nfs_umount_begin,
301 .show_options = nfs_show_options,
302 .show_stats = nfs_show_stats,
Jeff Layton48b605f2008-06-10 15:38:39 -0400303 .remount_fs = nfs_remount,
David Howellsf7b422b2006-06-09 09:34:33 -0400304};
305#endif
306
Rusty Russell8e1f9362007-07-17 04:03:17 -0700307static struct shrinker acl_shrinker = {
308 .shrink = nfs_access_cache_shrinker,
309 .seeks = DEFAULT_SEEKS,
310};
Trond Myklebust979df722006-07-25 11:28:19 -0400311
David Howellsf7b422b2006-06-09 09:34:33 -0400312/*
313 * Register the NFS filesystems
314 */
315int __init register_nfs_fs(void)
316{
317 int ret;
318
319 ret = register_filesystem(&nfs_fs_type);
320 if (ret < 0)
321 goto error_0;
322
David Howellsf7b422b2006-06-09 09:34:33 -0400323 ret = nfs_register_sysctl();
324 if (ret < 0)
325 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800326#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400327 ret = register_filesystem(&nfs4_fs_type);
328 if (ret < 0)
329 goto error_2;
330#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700331 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400332 return 0;
333
334#ifdef CONFIG_NFS_V4
335error_2:
336 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800337#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400338error_1:
339 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400340error_0:
341 return ret;
342}
343
344/*
345 * Unregister the NFS filesystems
346 */
347void __exit unregister_nfs_fs(void)
348{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700349 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400350#ifdef CONFIG_NFS_V4
351 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400352#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700353 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400354 unregister_filesystem(&nfs_fs_type);
355}
356
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400357void nfs_sb_active(struct super_block *sb)
Steve Dicksonef818a22007-11-08 04:05:04 -0500358{
359 struct nfs_server *server = NFS_SB(sb);
Trond Myklebust1daef0a2008-07-27 18:19:01 -0400360
361 if (atomic_inc_return(&server->active) == 1)
362 atomic_inc(&sb->s_active);
363}
364
365void nfs_sb_deactive(struct super_block *sb)
366{
367 struct nfs_server *server = NFS_SB(sb);
368
369 if (atomic_dec_and_test(&server->active))
370 deactivate_super(sb);
Steve Dicksonef818a22007-11-08 04:05:04 -0500371}
372
David Howellsf7b422b2006-06-09 09:34:33 -0400373/*
374 * Deliver file system statistics to userspace
375 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400376static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400377{
David Howells0c7d90c2006-08-22 20:06:10 -0400378 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400379 unsigned char blockbits;
380 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400381 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400382 struct nfs_fattr fattr;
383 struct nfs_fsstat res = {
384 .fattr = &fattr,
385 };
386 int error;
387
David Howells8fa5c002006-08-22 20:06:12 -0400388 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400389 if (error < 0)
390 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700391 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400392
393 /*
394 * Current versions of glibc do not correctly handle the
395 * case where f_frsize != f_bsize. Eventually we want to
396 * report the value of wtmult in this field.
397 */
David Howells0c7d90c2006-08-22 20:06:10 -0400398 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400399
400 /*
401 * On most *nix systems, f_blocks, f_bfree, and f_bavail
402 * are reported in units of f_frsize. Linux hasn't had
403 * an f_frsize field in its statfs struct until recently,
404 * thus historically Linux's sys_statfs reports these
405 * fields in units of f_bsize.
406 */
David Howells0c7d90c2006-08-22 20:06:10 -0400407 buf->f_bsize = dentry->d_sb->s_blocksize;
408 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400409 blockres = (1 << blockbits) - 1;
410 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
411 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
412 buf->f_bavail = (res.abytes + blockres) >> blockbits;
413
414 buf->f_files = res.tfiles;
415 buf->f_ffree = res.afiles;
416
417 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700418
David Howellsf7b422b2006-06-09 09:34:33 -0400419 return 0;
420
421 out_err:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700422 dprintk("%s: statfs error = %d\n", __func__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700423 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400424}
425
David Howells7d4e2742006-08-22 20:06:07 -0400426/*
427 * Map the security flavour number to a name
428 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400429static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
430{
David Howells7d4e2742006-08-22 20:06:07 -0400431 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400432 rpc_authflavor_t flavour;
433 const char *str;
434 } sec_flavours[] = {
435 { RPC_AUTH_NULL, "null" },
436 { RPC_AUTH_UNIX, "sys" },
437 { RPC_AUTH_GSS_KRB5, "krb5" },
438 { RPC_AUTH_GSS_KRB5I, "krb5i" },
439 { RPC_AUTH_GSS_KRB5P, "krb5p" },
440 { RPC_AUTH_GSS_LKEY, "lkey" },
441 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
442 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
443 { RPC_AUTH_GSS_SPKM, "spkm" },
444 { RPC_AUTH_GSS_SPKMI, "spkmi" },
445 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400446 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400447 };
448 int i;
449
Chuck Lever4d81cd12007-07-01 12:12:40 -0400450 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400451 if (sec_flavours[i].flavour == flavour)
452 break;
453 }
454 return sec_flavours[i].str;
455}
456
Chuck Lever82d101d2008-03-14 14:10:37 -0400457static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
458 int showdefaults)
459{
460 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
461
462 switch (sap->sa_family) {
463 case AF_INET: {
464 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
465 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
466 NIPQUAD(sin->sin_addr.s_addr));
467 break;
468 }
469 case AF_INET6: {
470 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
471 seq_printf(m, ",mountaddr=" NIP6_FMT,
472 NIP6(sin6->sin6_addr));
473 break;
474 }
475 default:
476 if (showdefaults)
477 seq_printf(m, ",mountaddr=unspecified");
478 }
479
480 if (nfss->mountd_version || showdefaults)
481 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
482 if (nfss->mountd_port || showdefaults)
483 seq_printf(m, ",mountport=%u", nfss->mountd_port);
484
485 switch (nfss->mountd_protocol) {
486 case IPPROTO_UDP:
487 seq_printf(m, ",mountproto=udp");
488 break;
489 case IPPROTO_TCP:
490 seq_printf(m, ",mountproto=tcp");
491 break;
492 default:
493 if (showdefaults)
494 seq_printf(m, ",mountproto=auto");
495 }
496}
497
David Howellsf7b422b2006-06-09 09:34:33 -0400498/*
499 * Describe the mount options in force on this server representation
500 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400501static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
502 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400503{
David Howells509de812006-08-22 20:06:11 -0400504 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400505 int flag;
David Howells509de812006-08-22 20:06:11 -0400506 const char *str;
507 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400508 } nfs_info[] = {
509 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400510 { NFS_MOUNT_INTR, ",intr", ",nointr" },
511 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400512 { NFS_MOUNT_NOCTO, ",nocto", "" },
513 { NFS_MOUNT_NOAC, ",noac", "" },
514 { NFS_MOUNT_NONLM, ",nolock", "" },
515 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400516 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400517 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400518 { 0, NULL, NULL }
519 };
David Howells509de812006-08-22 20:06:11 -0400520 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400521 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400522 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400523
Chuck Lever82d101d2008-03-14 14:10:37 -0400524 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400525 seq_printf(m, ",rsize=%u", nfss->rsize);
526 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400527 if (nfss->bsize != 0)
528 seq_printf(m, ",bsize=%u", nfss->bsize);
529 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400530 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400531 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400532 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400533 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400534 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400535 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400536 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400537 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400538 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
539 if (nfss->flags & nfs_infop->flag)
540 seq_puts(m, nfs_infop->str);
541 else
542 seq_puts(m, nfs_infop->nostr);
543 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400544 seq_printf(m, ",proto=%s",
545 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400546 if (version == 4) {
547 if (nfss->port != NFS_PORT)
548 seq_printf(m, ",port=%u", nfss->port);
549 } else
550 if (nfss->port)
551 seq_printf(m, ",port=%u", nfss->port);
552
Trond Myklebust33170232007-12-20 16:03:59 -0500553 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
554 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400555 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400556
557 if (version != 4)
558 nfs_show_mountd_options(m, nfss, showdefaults);
559
560#ifdef CONFIG_NFS_V4
561 if (clp->rpc_ops->version == 4)
562 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
563#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400564}
565
566/*
567 * Describe the mount options on this VFS mountpoint
568 */
569static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
570{
571 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
572
573 nfs_show_mount_options(m, nfss, 0);
574
Chuck Lever5d8515c2007-12-10 14:57:16 -0500575 seq_printf(m, ",addr=%s",
576 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
577 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400578
579 return 0;
580}
581
582/*
583 * Present statistical information for this VFS mountpoint
584 */
585static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
586{
587 int i, cpu;
588 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
589 struct rpc_auth *auth = nfss->client->cl_auth;
590 struct nfs_iostats totals = { };
591
592 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
593
594 /*
595 * Display all mount option settings
596 */
597 seq_printf(m, "\n\topts:\t");
598 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
599 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
600 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
601 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
602 nfs_show_mount_options(m, nfss, 1);
603
604 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
605
606 seq_printf(m, "\n\tcaps:\t");
607 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400608 seq_printf(m, ",wtmult=%u", nfss->wtmult);
609 seq_printf(m, ",dtsize=%u", nfss->dtsize);
610 seq_printf(m, ",bsize=%u", nfss->bsize);
611 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400612
613#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500614 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400615 seq_printf(m, "\n\tnfsv4:\t");
616 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
617 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
618 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
619 }
620#endif
621
622 /*
623 * Display security flavor in effect for this mount
624 */
Chuck Lever2d767432008-03-14 14:10:08 -0400625 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400626 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400627 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400628
629 /*
630 * Display superblock I/O counters
631 */
632 for_each_possible_cpu(cpu) {
633 struct nfs_iostats *stats;
634
635 preempt_disable();
636 stats = per_cpu_ptr(nfss->io_stats, cpu);
637
638 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
639 totals.events[i] += stats->events[i];
640 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
641 totals.bytes[i] += stats->bytes[i];
642
643 preempt_enable();
644 }
645
646 seq_printf(m, "\n\tevents:\t");
647 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
648 seq_printf(m, "%lu ", totals.events[i]);
649 seq_printf(m, "\n\tbytes:\t");
650 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
651 seq_printf(m, "%Lu ", totals.bytes[i]);
652 seq_printf(m, "\n");
653
654 rpc_print_iostats(m, nfss->client);
655
656 return 0;
657}
658
659/*
660 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400661 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400662 */
Al Viro42faad92008-04-24 07:21:56 -0400663static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400664{
Al Viro42faad92008-04-24 07:21:56 -0400665 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400666 struct rpc_clnt *rpc;
667
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400668 /* -EIO all pending I/O */
669 rpc = server->client_acl;
670 if (!IS_ERR(rpc))
671 rpc_killall_tasks(rpc);
672 rpc = server->client;
673 if (!IS_ERR(rpc))
674 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400675}
676
677/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500678 * Set the port number in an address. Be agnostic about the address family.
679 */
680static void nfs_set_port(struct sockaddr *sap, unsigned short port)
681{
682 switch (sap->sa_family) {
683 case AF_INET: {
684 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
685 ap->sin_port = htons(port);
686 break;
687 }
688 case AF_INET6: {
689 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
690 ap->sin6_port = htons(port);
691 break;
692 }
693 }
694}
695
696/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500697 * Sanity-check a server address provided by the mount command.
698 *
699 * Address family must be initialized, and address must not be
700 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400701 */
702static int nfs_verify_server_address(struct sockaddr *addr)
703{
704 switch (addr->sa_family) {
705 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500706 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700707 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500708 }
709 case AF_INET6: {
710 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
711 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400712 }
713 }
714
715 return 0;
716}
717
Chuck Leverce3b7e12008-06-23 12:36:53 -0400718static void nfs_parse_ipv4_address(char *string, size_t str_len,
719 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500720{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400721 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
722 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500723
Chuck Leverce3b7e12008-06-23 12:36:53 -0400724 if (str_len <= INET_ADDRSTRLEN) {
725 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
726 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500727
Chuck Leverce3b7e12008-06-23 12:36:53 -0400728 sin->sin_family = AF_INET;
729 *addr_len = sizeof(*sin);
730 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500731 return;
732 }
Chuck Lever9412b922007-12-10 14:59:21 -0500733
734 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400735 *addr_len = 0;
736}
737
Chuck Leverd8e77482008-06-23 12:37:01 -0400738#define IPV6_SCOPE_DELIMITER '%'
739
Chuck Leverce3b7e12008-06-23 12:36:53 -0400740#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Leverd8e77482008-06-23 12:37:01 -0400741static void nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
742 const char *delim,
743 struct sockaddr_in6 *sin6)
744{
745 char *p;
746 size_t len;
747
748 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
749 return ;
750 if (*delim != IPV6_SCOPE_DELIMITER)
751 return;
752
753 len = (string + str_len) - delim - 1;
754 p = kstrndup(delim + 1, len, GFP_KERNEL);
755 if (p) {
756 unsigned long scope_id = 0;
757 struct net_device *dev;
758
759 dev = dev_get_by_name(&init_net, p);
760 if (dev != NULL) {
761 scope_id = dev->ifindex;
762 dev_put(dev);
763 } else {
764 /* scope_id is set to zero on error */
765 strict_strtoul(p, 10, &scope_id);
766 }
767
768 kfree(p);
769 sin6->sin6_scope_id = scope_id;
770 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
771 }
772}
773
Chuck Leverce3b7e12008-06-23 12:36:53 -0400774static void nfs_parse_ipv6_address(char *string, size_t str_len,
775 struct sockaddr *sap, size_t *addr_len)
776{
777 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
778 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400779 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400780
781 if (str_len <= INET6_ADDRSTRLEN) {
782 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
783 (int)str_len, string);
784
785 sin6->sin6_family = AF_INET6;
786 *addr_len = sizeof(*sin6);
Chuck Leverd8e77482008-06-23 12:37:01 -0400787 if (in6_pton(string, str_len, addr, IPV6_SCOPE_DELIMITER, &delim)) {
788 nfs_parse_ipv6_scope_id(string, str_len, delim, sin6);
Chuck Leverce3b7e12008-06-23 12:36:53 -0400789 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400790 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400791 }
792
793 sap->sa_family = AF_UNSPEC;
794 *addr_len = 0;
795}
796#else
797static void nfs_parse_ipv6_address(char *string, size_t str_len,
798 struct sockaddr *sap, size_t *addr_len)
799{
800 sap->sa_family = AF_UNSPEC;
801 *addr_len = 0;
802}
803#endif
804
805/*
806 * Construct a sockaddr based on the contents of a string that contains
807 * an IP address in presentation format.
808 *
809 * If there is a problem constructing the new sockaddr, set the address
810 * family to AF_UNSPEC.
811 */
812static void nfs_parse_ip_address(char *string, size_t str_len,
813 struct sockaddr *sap, size_t *addr_len)
814{
815 unsigned int i, colons;
816
817 colons = 0;
818 for (i = 0; i < str_len; i++)
819 if (string[i] == ':')
820 colons++;
821
822 if (colons >= 2)
823 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
824 else
825 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500826}
827
828/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400829 * Sanity check the NFS transport protocol.
830 *
831 */
832static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
833{
834 switch (mnt->nfs_server.protocol) {
835 case XPRT_TRANSPORT_UDP:
836 case XPRT_TRANSPORT_TCP:
837 case XPRT_TRANSPORT_RDMA:
838 break;
839 default:
840 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
841 }
842}
843
844/*
845 * For text based NFSv2/v3 mounts, the mount protocol transport default
846 * settings should depend upon the specified NFS transport.
847 */
848static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
849{
850 nfs_validate_transport_protocol(mnt);
851
852 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
853 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
854 return;
855 switch (mnt->nfs_server.protocol) {
856 case XPRT_TRANSPORT_UDP:
857 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
858 break;
859 case XPRT_TRANSPORT_TCP:
860 case XPRT_TRANSPORT_RDMA:
861 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
862 }
863}
864
865/*
Chuck Lever01060c82008-06-24 16:33:38 -0400866 * Parse the value of the 'sec=' option.
867 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400868 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400869 */
870static int nfs_parse_security_flavors(char *value,
871 struct nfs_parsed_mount_data *mnt)
872{
873 substring_t args[MAX_OPT_ARGS];
874
875 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
876
877 switch (match_token(value, nfs_secflavor_tokens, args)) {
878 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400879 mnt->auth_flavor_len = 0;
880 mnt->auth_flavors[0] = RPC_AUTH_NULL;
881 break;
882 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400883 mnt->auth_flavor_len = 0;
884 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
885 break;
886 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400887 mnt->auth_flavor_len = 1;
888 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
889 break;
890 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400891 mnt->auth_flavor_len = 1;
892 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
893 break;
894 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400895 mnt->auth_flavor_len = 1;
896 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
897 break;
898 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400899 mnt->auth_flavor_len = 1;
900 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
901 break;
902 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
905 break;
906 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400907 mnt->auth_flavor_len = 1;
908 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
909 break;
910 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400911 mnt->auth_flavor_len = 1;
912 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
913 break;
914 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400915 mnt->auth_flavor_len = 1;
916 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
917 break;
918 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400919 mnt->auth_flavor_len = 1;
920 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
921 break;
922 default:
923 return 0;
924 }
925
926 return 1;
927}
928
Chuck Leverf45663c2008-06-24 19:28:02 -0400929static void nfs_parse_invalid_value(const char *option)
930{
931 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
932}
933
Chuck Lever01060c82008-06-24 16:33:38 -0400934/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400935 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400936 * a data structure. The whole mount string is processed; bad options are
937 * skipped as they are encountered. If there were no errors, return 1;
938 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400939 */
940static int nfs_parse_mount_options(char *raw,
941 struct nfs_parsed_mount_data *mnt)
942{
Eric Parisf9c3a382008-03-05 14:20:18 -0500943 char *p, *string, *secdata;
Chuck Leverf45663c2008-06-24 19:28:02 -0400944 int rc, sloppy = 0, errors = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400945
946 if (!raw) {
947 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
948 return 1;
949 }
950 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
951
Eric Parisf9c3a382008-03-05 14:20:18 -0500952 secdata = alloc_secdata();
953 if (!secdata)
954 goto out_nomem;
955
956 rc = security_sb_copy_data(raw, secdata);
957 if (rc)
958 goto out_security_failure;
959
960 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
961 if (rc)
962 goto out_security_failure;
963
964 free_secdata(secdata);
965
Chuck Leverbf0fd762007-07-01 12:13:44 -0400966 while ((p = strsep(&raw, ",")) != NULL) {
967 substring_t args[MAX_OPT_ARGS];
968 int option, token;
969
970 if (!*p)
971 continue;
972
973 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
974
975 token = match_token(p, nfs_mount_option_tokens, args);
976 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400977
978 /*
979 * boolean options: foo/nofoo
980 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400981 case Opt_soft:
982 mnt->flags |= NFS_MOUNT_SOFT;
983 break;
984 case Opt_hard:
985 mnt->flags &= ~NFS_MOUNT_SOFT;
986 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400987 case Opt_posix:
988 mnt->flags |= NFS_MOUNT_POSIX;
989 break;
990 case Opt_noposix:
991 mnt->flags &= ~NFS_MOUNT_POSIX;
992 break;
993 case Opt_cto:
994 mnt->flags &= ~NFS_MOUNT_NOCTO;
995 break;
996 case Opt_nocto:
997 mnt->flags |= NFS_MOUNT_NOCTO;
998 break;
999 case Opt_ac:
1000 mnt->flags &= ~NFS_MOUNT_NOAC;
1001 break;
1002 case Opt_noac:
1003 mnt->flags |= NFS_MOUNT_NOAC;
1004 break;
1005 case Opt_lock:
1006 mnt->flags &= ~NFS_MOUNT_NONLM;
1007 break;
1008 case Opt_nolock:
1009 mnt->flags |= NFS_MOUNT_NONLM;
1010 break;
1011 case Opt_v2:
1012 mnt->flags &= ~NFS_MOUNT_VER3;
1013 break;
1014 case Opt_v3:
1015 mnt->flags |= NFS_MOUNT_VER3;
1016 break;
1017 case Opt_udp:
1018 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001019 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001020 break;
1021 case Opt_tcp:
1022 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001023 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001024 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001025 case Opt_rdma:
1026 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1027 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001028 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001029 case Opt_acl:
1030 mnt->flags &= ~NFS_MOUNT_NOACL;
1031 break;
1032 case Opt_noacl:
1033 mnt->flags |= NFS_MOUNT_NOACL;
1034 break;
1035 case Opt_rdirplus:
1036 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1037 break;
1038 case Opt_nordirplus:
1039 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1040 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001041 case Opt_sharecache:
1042 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1043 break;
1044 case Opt_nosharecache:
1045 mnt->flags |= NFS_MOUNT_UNSHARED;
1046 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001047
Chuck Leverf45663c2008-06-24 19:28:02 -04001048 /*
1049 * options that take numeric values
1050 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001051 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001052 if (match_int(args, &option) ||
1053 option < 0 || option > USHORT_MAX) {
1054 errors++;
1055 nfs_parse_invalid_value("port");
1056 } else
1057 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001058 break;
1059 case Opt_rsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001060 if (match_int(args, &option) || option < 0) {
1061 errors++;
1062 nfs_parse_invalid_value("rsize");
1063 } else
1064 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001065 break;
1066 case Opt_wsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001067 if (match_int(args, &option) || option < 0) {
1068 errors++;
1069 nfs_parse_invalid_value("wsize");
1070 } else
1071 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001072 break;
1073 case Opt_bsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001074 if (match_int(args, &option) || option < 0) {
1075 errors++;
1076 nfs_parse_invalid_value("bsize");
1077 } else
1078 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001079 break;
1080 case Opt_timeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001081 if (match_int(args, &option) || option <= 0) {
1082 errors++;
1083 nfs_parse_invalid_value("timeo");
1084 } else
1085 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001086 break;
1087 case Opt_retrans:
Chuck Leverf45663c2008-06-24 19:28:02 -04001088 if (match_int(args, &option) || option <= 0) {
1089 errors++;
1090 nfs_parse_invalid_value("retrans");
1091 } else
1092 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001093 break;
1094 case Opt_acregmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001095 if (match_int(args, &option) || option < 0) {
1096 errors++;
1097 nfs_parse_invalid_value("acregmin");
1098 } else
1099 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001100 break;
1101 case Opt_acregmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001102 if (match_int(args, &option) || option < 0) {
1103 errors++;
1104 nfs_parse_invalid_value("acregmax");
1105 } else
1106 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001107 break;
1108 case Opt_acdirmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001109 if (match_int(args, &option) || option < 0) {
1110 errors++;
1111 nfs_parse_invalid_value("acdirmin");
1112 } else
1113 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001114 break;
1115 case Opt_acdirmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001116 if (match_int(args, &option) || option < 0) {
1117 errors++;
1118 nfs_parse_invalid_value("acdirmax");
1119 } else
1120 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001121 break;
1122 case Opt_actimeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001123 if (match_int(args, &option) || option < 0) {
1124 errors++;
1125 nfs_parse_invalid_value("actimeo");
1126 } else
1127 mnt->acregmin = mnt->acregmax =
1128 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001129 break;
1130 case Opt_namelen:
Chuck Leverf45663c2008-06-24 19:28:02 -04001131 if (match_int(args, &option) || option < 0) {
1132 errors++;
1133 nfs_parse_invalid_value("namlen");
1134 } else
1135 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001136 break;
1137 case Opt_mountport:
Chuck Leverf45663c2008-06-24 19:28:02 -04001138 if (match_int(args, &option) ||
1139 option < 0 || option > USHORT_MAX) {
1140 errors++;
1141 nfs_parse_invalid_value("mountport");
1142 } else
1143 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001144 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001145 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001146 if (match_int(args, &option) ||
1147 option < NFS_MNT_VERSION ||
1148 option > NFS_MNT3_VERSION) {
1149 errors++;
1150 nfs_parse_invalid_value("mountvers");
1151 } else
1152 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001153 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001154 case Opt_nfsvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001155 if (match_int(args, &option)) {
1156 errors++;
1157 nfs_parse_invalid_value("nfsvers");
1158 break;
1159 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001160 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001161 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001162 mnt->flags &= ~NFS_MOUNT_VER3;
1163 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001164 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 mnt->flags |= NFS_MOUNT_VER3;
1166 break;
1167 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001168 errors++;
1169 nfs_parse_invalid_value("nfsvers");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 }
1171 break;
1172
Chuck Leverf45663c2008-06-24 19:28:02 -04001173 /*
1174 * options that take text values
1175 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176 case Opt_sec:
1177 string = match_strdup(args);
1178 if (string == NULL)
1179 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001180 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001181 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001182 if (!rc) {
1183 errors++;
1184 dfprintk(MOUNT, "NFS: unrecognized "
1185 "security flavor\n");
1186 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001187 break;
1188 case Opt_proto:
1189 string = match_strdup(args);
1190 if (string == NULL)
1191 goto out_nomem;
1192 token = match_token(string,
1193 nfs_xprt_protocol_tokens, args);
1194 kfree(string);
1195
1196 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001197 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001198 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001199 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001200 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001201 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001202 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001203 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001204 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001205 case Opt_xprt_rdma:
1206 /* vector side protocols to TCP */
1207 mnt->flags |= NFS_MOUNT_TCP;
1208 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001209 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001210 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001211 errors++;
1212 dfprintk(MOUNT, "NFS: unrecognized "
1213 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001214 }
1215 break;
1216 case Opt_mountproto:
1217 string = match_strdup(args);
1218 if (string == NULL)
1219 goto out_nomem;
1220 token = match_token(string,
1221 nfs_xprt_protocol_tokens, args);
1222 kfree(string);
1223
1224 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001225 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001226 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001227 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001228 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001229 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001230 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001231 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001232 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001233 errors++;
1234 dfprintk(MOUNT, "NFS: unrecognized "
1235 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001236 }
1237 break;
1238 case Opt_addr:
1239 string = match_strdup(args);
1240 if (string == NULL)
1241 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001242 nfs_parse_ip_address(string, strlen(string),
1243 (struct sockaddr *)
1244 &mnt->nfs_server.address,
1245 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001246 kfree(string);
1247 break;
1248 case Opt_clientaddr:
1249 string = match_strdup(args);
1250 if (string == NULL)
1251 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001252 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001253 mnt->client_address = string;
1254 break;
Chuck Lever33832032007-12-10 14:59:13 -05001255 case Opt_mounthost:
1256 string = match_strdup(args);
1257 if (string == NULL)
1258 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001259 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001260 mnt->mount_server.hostname = string;
1261 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001262 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001263 string = match_strdup(args);
1264 if (string == NULL)
1265 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001266 nfs_parse_ip_address(string, strlen(string),
1267 (struct sockaddr *)
1268 &mnt->mount_server.address,
1269 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001270 kfree(string);
1271 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001272 case Opt_lookupcache:
1273 string = match_strdup(args);
1274 if (string == NULL)
1275 goto out_nomem;
1276 token = match_token(string,
1277 nfs_lookupcache_tokens, args);
1278 kfree(string);
1279 switch (token) {
1280 case Opt_lookupcache_all:
1281 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1282 break;
1283 case Opt_lookupcache_positive:
1284 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1285 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1286 break;
1287 case Opt_lookupcache_none:
1288 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1289 break;
1290 default:
1291 errors++;
1292 dfprintk(MOUNT, "NFS: invalid "
1293 "lookupcache argument\n");
1294 };
1295 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001296
Chuck Leverf45663c2008-06-24 19:28:02 -04001297 /*
1298 * Special options
1299 */
1300 case Opt_sloppy:
1301 sloppy = 1;
1302 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1303 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001304 case Opt_userspace:
1305 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001306 dfprintk(MOUNT, "NFS: ignoring mount option "
1307 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001308 break;
1309
1310 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001311 errors++;
1312 dfprintk(MOUNT, "NFS: unrecognized mount option "
1313 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001314 }
1315 }
1316
Chuck Leveraf904de2008-09-08 11:58:13 -04001317 if (errors > 0) {
1318 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1319 errors, (errors == 1 ? "" : "s"));
1320 if (!sloppy)
1321 return 0;
1322 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001323 return 1;
1324
1325out_nomem:
1326 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1327 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001328out_security_failure:
1329 free_secdata(secdata);
1330 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1331 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001332}
1333
1334/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001335 * Use the remote server's MOUNT service to request the NFS file handle
1336 * corresponding to the provided path.
1337 */
1338static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1339 struct nfs_fh *root_fh)
1340{
Chuck Lever4c568012007-12-10 14:59:28 -05001341 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001342 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001343 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001344
1345 if (args->mount_server.version == 0) {
1346 if (args->flags & NFS_MOUNT_VER3)
1347 args->mount_server.version = NFS_MNT3_VERSION;
1348 else
1349 args->mount_server.version = NFS_MNT_VERSION;
1350 }
1351
Chuck Lever33832032007-12-10 14:59:13 -05001352 if (args->mount_server.hostname)
1353 hostname = args->mount_server.hostname;
1354 else
1355 hostname = args->nfs_server.hostname;
1356
Chuck Lever0076d7b2007-07-01 12:13:49 -04001357 /*
1358 * Construct the mount server's address.
1359 */
Chuck Lever4c568012007-12-10 14:59:28 -05001360 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1361 memcpy(sap, &args->nfs_server.address,
1362 args->nfs_server.addrlen);
1363 args->mount_server.addrlen = args->nfs_server.addrlen;
1364 }
1365
James Lentiniaad70002007-09-24 17:32:49 -04001366 /*
1367 * autobind will be used if mount_server.port == 0
1368 */
Chuck Lever4c568012007-12-10 14:59:28 -05001369 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001370
1371 /*
1372 * Now ask the mount server to map our export path
1373 * to a file handle.
1374 */
Chuck Lever4c568012007-12-10 14:59:28 -05001375 status = nfs_mount(sap,
1376 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001377 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001378 args->nfs_server.export_path,
1379 args->mount_server.version,
1380 args->mount_server.protocol,
1381 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001382 if (status == 0)
1383 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001384
Chuck Lever396cee972008-06-12 12:37:49 -04001385 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Lever33832032007-12-10 14:59:13 -05001386 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001387 return status;
1388}
1389
Chuck Leverd1aa0822008-06-23 12:36:45 -04001390static int nfs_parse_simple_hostname(const char *dev_name,
1391 char **hostname, size_t maxnamlen,
1392 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001393{
1394 size_t len;
1395 char *colon, *comma;
1396
1397 colon = strchr(dev_name, ':');
1398 if (colon == NULL)
1399 goto out_bad_devname;
1400
1401 len = colon - dev_name;
1402 if (len > maxnamlen)
1403 goto out_hostname;
1404
1405 /* N.B. caller will free nfs_server.hostname in all cases */
1406 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1407 if (!*hostname)
1408 goto out_nomem;
1409
1410 /* kill possible hostname list: not supported */
1411 comma = strchr(*hostname, ',');
1412 if (comma != NULL) {
1413 if (comma == *hostname)
1414 goto out_bad_devname;
1415 *comma = '\0';
1416 }
1417
1418 colon++;
1419 len = strlen(colon);
1420 if (len > maxpathlen)
1421 goto out_path;
1422 *export_path = kstrndup(colon, len, GFP_KERNEL);
1423 if (!*export_path)
1424 goto out_nomem;
1425
1426 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1427 return 0;
1428
1429out_bad_devname:
1430 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1431 return -EINVAL;
1432
1433out_nomem:
1434 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1435 return -ENOMEM;
1436
1437out_hostname:
1438 dfprintk(MOUNT, "NFS: server hostname too long\n");
1439 return -ENAMETOOLONG;
1440
1441out_path:
1442 dfprintk(MOUNT, "NFS: export pathname too long\n");
1443 return -ENAMETOOLONG;
1444}
1445
1446/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001447 * Hostname has square brackets around it because it contains one or
1448 * more colons. We look for the first closing square bracket, and a
1449 * colon must follow it.
1450 */
1451static int nfs_parse_protected_hostname(const char *dev_name,
1452 char **hostname, size_t maxnamlen,
1453 char **export_path, size_t maxpathlen)
1454{
1455 size_t len;
1456 char *start, *end;
1457
1458 start = (char *)(dev_name + 1);
1459
1460 end = strchr(start, ']');
1461 if (end == NULL)
1462 goto out_bad_devname;
1463 if (*(end + 1) != ':')
1464 goto out_bad_devname;
1465
1466 len = end - start;
1467 if (len > maxnamlen)
1468 goto out_hostname;
1469
1470 /* N.B. caller will free nfs_server.hostname in all cases */
1471 *hostname = kstrndup(start, len, GFP_KERNEL);
1472 if (*hostname == NULL)
1473 goto out_nomem;
1474
1475 end += 2;
1476 len = strlen(end);
1477 if (len > maxpathlen)
1478 goto out_path;
1479 *export_path = kstrndup(end, len, GFP_KERNEL);
1480 if (!*export_path)
1481 goto out_nomem;
1482
1483 return 0;
1484
1485out_bad_devname:
1486 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1487 return -EINVAL;
1488
1489out_nomem:
1490 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1491 return -ENOMEM;
1492
1493out_hostname:
1494 dfprintk(MOUNT, "NFS: server hostname too long\n");
1495 return -ENAMETOOLONG;
1496
1497out_path:
1498 dfprintk(MOUNT, "NFS: export pathname too long\n");
1499 return -ENAMETOOLONG;
1500}
1501
1502/*
1503 * Split "dev_name" into "hostname:export_path".
1504 *
1505 * The leftmost colon demarks the split between the server's hostname
1506 * and the export path. If the hostname starts with a left square
1507 * bracket, then it may contain colons.
1508 *
1509 * Note: caller frees hostname and export path, even on error.
1510 */
1511static int nfs_parse_devname(const char *dev_name,
1512 char **hostname, size_t maxnamlen,
1513 char **export_path, size_t maxpathlen)
1514{
1515 if (*dev_name == '[')
1516 return nfs_parse_protected_hostname(dev_name,
1517 hostname, maxnamlen,
1518 export_path, maxpathlen);
1519
1520 return nfs_parse_simple_hostname(dev_name,
1521 hostname, maxnamlen,
1522 export_path, maxpathlen);
1523}
1524
1525/*
David Howells54ceac42006-08-22 20:06:13 -04001526 * Validate the NFS2/NFS3 mount data
1527 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001528 *
1529 * For option strings, user space handles the following behaviors:
1530 *
1531 * + DNS: mapping server host name to IP address ("addr=" option)
1532 *
1533 * + failure mode: how to behave if a mount request can't be handled
1534 * immediately ("fg/bg" option)
1535 *
1536 * + retry: how often to retry a mount request ("retry=" option)
1537 *
1538 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1539 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001540 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001541static int nfs_validate_mount_data(void *options,
1542 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001543 struct nfs_fh *mntfh,
1544 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001545{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001546 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001547
Chuck Lever5df36e72007-07-01 12:12:56 -04001548 if (data == NULL)
1549 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001550
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001551 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1552 args->rsize = NFS_MAX_FILE_IO_SIZE;
1553 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001554 args->acregmin = NFS_DEF_ACREGMIN;
1555 args->acregmax = NFS_DEF_ACREGMAX;
1556 args->acdirmin = NFS_DEF_ACDIRMIN;
1557 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001558 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001559 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001560 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001561 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001562
David Howellsf7b422b2006-06-09 09:34:33 -04001563 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001564 case 1:
1565 data->namlen = 0;
1566 case 2:
1567 data->bsize = 0;
1568 case 3:
1569 if (data->flags & NFS_MOUNT_VER3)
1570 goto out_no_v3;
1571 data->root.size = NFS2_FHSIZE;
1572 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1573 case 4:
1574 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1575 goto out_no_sec;
1576 case 5:
1577 memset(data->context, 0, sizeof(data->context));
1578 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001579 if (data->flags & NFS_MOUNT_VER3) {
1580 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1581 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001582 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001583 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001584 mntfh->size = NFS2_FHSIZE;
1585
Chuck Lever5df36e72007-07-01 12:12:56 -04001586
1587 memcpy(mntfh->data, data->root.data, mntfh->size);
1588 if (mntfh->size < sizeof(mntfh->data))
1589 memset(mntfh->data + mntfh->size, 0,
1590 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001591
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001592 /*
1593 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1594 * can deal with.
1595 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001596 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001597 args->rsize = data->rsize;
1598 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001599 args->timeo = data->timeo;
1600 args->retrans = data->retrans;
1601 args->acregmin = data->acregmin;
1602 args->acregmax = data->acregmax;
1603 args->acdirmin = data->acdirmin;
1604 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001605
1606 memcpy(&args->nfs_server.address, &data->addr,
1607 sizeof(data->addr));
1608 args->nfs_server.addrlen = sizeof(data->addr);
1609 if (!nfs_verify_server_address((struct sockaddr *)
1610 &args->nfs_server.address))
1611 goto out_no_address;
1612
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001613 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001614 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001615 /* N.B. caller will free nfs_server.hostname in all cases */
1616 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1617 args->namlen = data->namlen;
1618 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001619
1620 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1621 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001622 if (!args->nfs_server.hostname)
1623 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001624
1625 /*
1626 * The legacy version 6 binary mount data from userspace has a
1627 * field used only to transport selinux information into the
1628 * the kernel. To continue to support that functionality we
1629 * have a touch of selinux knowledge here in the NFS code. The
1630 * userspace code converted context=blah to just blah so we are
1631 * converting back to the full string selinux understands.
1632 */
1633 if (data->context[0]){
1634#ifdef CONFIG_SECURITY_SELINUX
1635 int rc;
1636 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1637 if (!opts_str)
1638 return -ENOMEM;
1639 strcpy(opts_str, "context=");
1640 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1641 strcat(opts_str, &data->context[0]);
1642 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1643 kfree(opts_str);
1644 if (rc)
1645 return rc;
1646#else
1647 return -EINVAL;
1648#endif
1649 }
1650
Chuck Lever5df36e72007-07-01 12:12:56 -04001651 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001652 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001653 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001654
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001655 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001656 return -EINVAL;
1657
Chuck Lever6e88e062007-09-24 15:39:50 -04001658 if (!nfs_verify_server_address((struct sockaddr *)
1659 &args->nfs_server.address))
1660 goto out_no_address;
1661
Chuck Levered596a82008-06-26 17:47:05 -04001662 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1663 args->nfs_server.port);
1664
Trond Myklebust259875e2008-07-02 14:43:47 -04001665 nfs_set_mount_transport_protocol(args);
1666
Chuck Leverdc045892008-06-23 12:36:37 -04001667 status = nfs_parse_devname(dev_name,
1668 &args->nfs_server.hostname,
1669 PAGE_SIZE,
1670 &args->nfs_server.export_path,
1671 NFS_MAXPATHLEN);
1672 if (!status)
1673 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001674
Chuck Leverdc045892008-06-23 12:36:37 -04001675 kfree(args->nfs_server.export_path);
1676 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001677
Chuck Lever136d5582007-07-01 12:13:54 -04001678 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001679 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001680
Chuck Lever136d5582007-07-01 12:13:54 -04001681 break;
1682 }
David Howellsf7b422b2006-06-09 09:34:33 -04001683 }
David Howells54ceac42006-08-22 20:06:13 -04001684
David Howellsf7b422b2006-06-09 09:34:33 -04001685#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001686 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001687 goto out_v3_not_compiled;
1688#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001689
David Howells54ceac42006-08-22 20:06:13 -04001690 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001691
1692out_no_data:
1693 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1694 return -EINVAL;
1695
1696out_no_v3:
1697 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1698 data->version);
1699 return -EINVAL;
1700
1701out_no_sec:
1702 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1703 return -EINVAL;
1704
Chuck Lever5df36e72007-07-01 12:12:56 -04001705#ifndef CONFIG_NFS_V3
1706out_v3_not_compiled:
1707 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1708 return -EPROTONOSUPPORT;
1709#endif /* !CONFIG_NFS_V3 */
1710
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001711out_nomem:
1712 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1713 return -ENOMEM;
1714
Chuck Lever5df36e72007-07-01 12:12:56 -04001715out_no_address:
1716 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1717 return -EINVAL;
1718
1719out_invalid_fh:
1720 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1721 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001722}
1723
Jeff Layton48b605f2008-06-10 15:38:39 -04001724static int
1725nfs_compare_remount_data(struct nfs_server *nfss,
1726 struct nfs_parsed_mount_data *data)
1727{
1728 if (data->flags != nfss->flags ||
1729 data->rsize != nfss->rsize ||
1730 data->wsize != nfss->wsize ||
1731 data->retrans != nfss->client->cl_timeout->to_retries ||
1732 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1733 data->acregmin != nfss->acregmin / HZ ||
1734 data->acregmax != nfss->acregmax / HZ ||
1735 data->acdirmin != nfss->acdirmin / HZ ||
1736 data->acdirmax != nfss->acdirmax / HZ ||
1737 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1738 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1739 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1740 data->nfs_server.addrlen) != 0)
1741 return -EINVAL;
1742
1743 return 0;
1744}
1745
1746static int
1747nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1748{
1749 int error;
1750 struct nfs_server *nfss = sb->s_fs_info;
1751 struct nfs_parsed_mount_data *data;
1752 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1753 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001754 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001755
1756 /*
1757 * Userspace mount programs that send binary options generally send
1758 * them populated with default values. We have no way to know which
1759 * ones were explicitly specified. Fall back to legacy behavior and
1760 * just return success.
1761 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001762 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1763 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1764 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001765 return 0;
1766
1767 data = kzalloc(sizeof(*data), GFP_KERNEL);
1768 if (data == NULL)
1769 return -ENOMEM;
1770
1771 /* fill out struct with values from existing mount */
1772 data->flags = nfss->flags;
1773 data->rsize = nfss->rsize;
1774 data->wsize = nfss->wsize;
1775 data->retrans = nfss->client->cl_timeout->to_retries;
1776 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1777 data->acregmin = nfss->acregmin / HZ;
1778 data->acregmax = nfss->acregmax / HZ;
1779 data->acdirmin = nfss->acdirmin / HZ;
1780 data->acdirmax = nfss->acdirmax / HZ;
1781 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1782 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1783 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1784 data->nfs_server.addrlen);
1785
1786 /* overwrite those values with any that were specified */
1787 error = nfs_parse_mount_options((char *)options, data);
1788 if (error < 0)
1789 goto out;
1790
1791 /* compare new mount options with old ones */
1792 error = nfs_compare_remount_data(nfss, data);
1793out:
1794 kfree(data);
1795 return error;
1796}
1797
David Howells54ceac42006-08-22 20:06:13 -04001798/*
1799 * Initialise the common bits of the superblock
1800 */
1801static inline void nfs_initialise_sb(struct super_block *sb)
1802{
1803 struct nfs_server *server = NFS_SB(sb);
1804
1805 sb->s_magic = NFS_SUPER_MAGIC;
1806
1807 /* We probably want something more informative here */
1808 snprintf(sb->s_id, sizeof(sb->s_id),
1809 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1810
1811 if (sb->s_blocksize == 0)
1812 sb->s_blocksize = nfs_block_bits(server->wsize,
1813 &sb->s_blocksize_bits);
1814
1815 if (server->flags & NFS_MOUNT_NOAC)
1816 sb->s_flags |= MS_SYNCHRONOUS;
1817
1818 nfs_super_set_maxbytes(sb, server->maxfilesize);
1819}
1820
1821/*
1822 * Finish setting up an NFS2/3 superblock
1823 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001824static void nfs_fill_super(struct super_block *sb,
1825 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001826{
1827 struct nfs_server *server = NFS_SB(sb);
1828
1829 sb->s_blocksize_bits = 0;
1830 sb->s_blocksize = 0;
1831 if (data->bsize)
1832 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1833
1834 if (server->flags & NFS_MOUNT_VER3) {
1835 /* The VFS shouldn't apply the umask to mode bits. We will do
1836 * so ourselves when necessary.
1837 */
1838 sb->s_flags |= MS_POSIXACL;
1839 sb->s_time_gran = 1;
1840 }
1841
1842 sb->s_op = &nfs_sops;
1843 nfs_initialise_sb(sb);
1844}
1845
1846/*
1847 * Finish setting up a cloned NFS2/3 superblock
1848 */
1849static void nfs_clone_super(struct super_block *sb,
1850 const struct super_block *old_sb)
1851{
1852 struct nfs_server *server = NFS_SB(sb);
1853
1854 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1855 sb->s_blocksize = old_sb->s_blocksize;
1856 sb->s_maxbytes = old_sb->s_maxbytes;
1857
1858 if (server->flags & NFS_MOUNT_VER3) {
1859 /* The VFS shouldn't apply the umask to mode bits. We will do
1860 * so ourselves when necessary.
1861 */
1862 sb->s_flags |= MS_POSIXACL;
1863 sb->s_time_gran = 1;
1864 }
1865
1866 sb->s_op = old_sb->s_op;
1867 nfs_initialise_sb(sb);
1868}
1869
Trond Myklebust275a5d22007-05-16 16:53:28 -04001870#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1871
1872static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1873{
1874 const struct nfs_server *a = s->s_fs_info;
1875 const struct rpc_clnt *clnt_a = a->client;
1876 const struct rpc_clnt *clnt_b = b->client;
1877
1878 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1879 goto Ebusy;
1880 if (a->nfs_client != b->nfs_client)
1881 goto Ebusy;
1882 if (a->flags != b->flags)
1883 goto Ebusy;
1884 if (a->wsize != b->wsize)
1885 goto Ebusy;
1886 if (a->rsize != b->rsize)
1887 goto Ebusy;
1888 if (a->acregmin != b->acregmin)
1889 goto Ebusy;
1890 if (a->acregmax != b->acregmax)
1891 goto Ebusy;
1892 if (a->acdirmin != b->acdirmin)
1893 goto Ebusy;
1894 if (a->acdirmax != b->acdirmax)
1895 goto Ebusy;
1896 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1897 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001898 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001899Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001900 return 0;
1901}
1902
1903struct nfs_sb_mountdata {
1904 struct nfs_server *server;
1905 int mntflags;
1906};
1907
1908static int nfs_set_super(struct super_block *s, void *data)
1909{
1910 struct nfs_sb_mountdata *sb_mntdata = data;
1911 struct nfs_server *server = sb_mntdata->server;
1912 int ret;
1913
1914 s->s_flags = sb_mntdata->mntflags;
1915 s->s_fs_info = server;
1916 ret = set_anon_super(s, server);
1917 if (ret == 0)
1918 server->s_dev = s->s_dev;
1919 return ret;
1920}
1921
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001922static int nfs_compare_super_address(struct nfs_server *server1,
1923 struct nfs_server *server2)
1924{
1925 struct sockaddr *sap1, *sap2;
1926
1927 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1928 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1929
1930 if (sap1->sa_family != sap2->sa_family)
1931 return 0;
1932
1933 switch (sap1->sa_family) {
1934 case AF_INET: {
1935 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1936 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1937 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1938 return 0;
1939 if (sin1->sin_port != sin2->sin_port)
1940 return 0;
1941 break;
1942 }
1943 case AF_INET6: {
1944 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1945 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1946 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1947 return 0;
1948 if (sin1->sin6_port != sin2->sin6_port)
1949 return 0;
1950 break;
1951 }
1952 default:
1953 return 0;
1954 }
1955
1956 return 1;
1957}
1958
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001959static int nfs_compare_super(struct super_block *sb, void *data)
1960{
1961 struct nfs_sb_mountdata *sb_mntdata = data;
1962 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1963 int mntflags = sb_mntdata->mntflags;
1964
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001965 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001966 return 0;
1967 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1968 if (old->flags & NFS_MOUNT_UNSHARED)
1969 return 0;
1970 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1971 return 0;
1972 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001973}
1974
Miklos Szeredifa799752008-04-30 00:54:33 -07001975static int nfs_bdi_register(struct nfs_server *server)
1976{
1977 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1978}
1979
David Howells54ceac42006-08-22 20:06:13 -04001980static int nfs_get_sb(struct file_system_type *fs_type,
1981 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1982{
1983 struct nfs_server *server = NULL;
1984 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001985 struct nfs_parsed_mount_data *data;
1986 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001987 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001988 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001989 struct nfs_sb_mountdata sb_mntdata = {
1990 .mntflags = flags,
1991 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001992 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001993
Trond Myklebust33852a12008-06-19 14:20:11 -04001994 data = kzalloc(sizeof(*data), GFP_KERNEL);
1995 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1996 if (data == NULL || mntfh == NULL)
1997 goto out_free_fh;
1998
1999 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002000
David Howells54ceac42006-08-22 20:06:13 -04002001 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002002 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04002003 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04002004 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002005
2006 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002007 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002008 if (IS_ERR(server)) {
2009 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04002010 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002011 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002012 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002013
Trond Myklebust75180df2007-05-16 16:53:28 -04002014 if (server->flags & NFS_MOUNT_UNSHARED)
2015 compare_super = NULL;
2016
David Howells54ceac42006-08-22 20:06:13 -04002017 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002018 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002019 if (IS_ERR(s)) {
2020 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002021 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002022 }
2023
David Howells54ceac42006-08-22 20:06:13 -04002024 if (s->s_fs_info != server) {
2025 nfs_free_server(server);
2026 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002027 } else {
2028 error = nfs_bdi_register(server);
2029 if (error)
2030 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002031 }
David Howells54ceac42006-08-22 20:06:13 -04002032
2033 if (!s->s_root) {
2034 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002035 nfs_fill_super(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002036 }
2037
Trond Myklebust33852a12008-06-19 14:20:11 -04002038 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002039 if (IS_ERR(mntroot)) {
2040 error = PTR_ERR(mntroot);
2041 goto error_splat_super;
2042 }
2043
Trond Myklebust33852a12008-06-19 14:20:11 -04002044 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002045 if (error)
2046 goto error_splat_root;
2047
David Howellsf7b422b2006-06-09 09:34:33 -04002048 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002049 mnt->mnt_sb = s;
2050 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002051 error = 0;
2052
2053out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002054 kfree(data->nfs_server.hostname);
2055 kfree(data->mount_server.hostname);
2056 security_free_mnt_opts(&data->lsm_opts);
2057out_free_fh:
2058 kfree(mntfh);
2059 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002060 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002061
David Howells54ceac42006-08-22 20:06:13 -04002062out_err_nosb:
2063 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002064 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002065
Eric Parisf9c3a382008-03-05 14:20:18 -05002066error_splat_root:
2067 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002068error_splat_super:
2069 up_write(&s->s_umount);
2070 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002071 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002072}
2073
David Howells54ceac42006-08-22 20:06:13 -04002074/*
2075 * Destroy an NFS2/3 superblock
2076 */
David Howellsf7b422b2006-06-09 09:34:33 -04002077static void nfs_kill_super(struct super_block *s)
2078{
2079 struct nfs_server *server = NFS_SB(s);
2080
Miklos Szeredifa799752008-04-30 00:54:33 -07002081 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002082 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002083 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002084}
2085
David Howells54ceac42006-08-22 20:06:13 -04002086/*
2087 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2088 */
2089static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2090 const char *dev_name, void *raw_data,
2091 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002092{
2093 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002094 struct super_block *s;
2095 struct nfs_server *server;
2096 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002097 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002098 struct nfs_sb_mountdata sb_mntdata = {
2099 .mntflags = flags,
2100 };
David Howells54ceac42006-08-22 20:06:13 -04002101 int error;
2102
2103 dprintk("--> nfs_xdev_get_sb()\n");
2104
2105 /* create a new volume representation */
2106 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2107 if (IS_ERR(server)) {
2108 error = PTR_ERR(server);
2109 goto out_err_noserver;
2110 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002111 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002112
Trond Myklebust75180df2007-05-16 16:53:28 -04002113 if (server->flags & NFS_MOUNT_UNSHARED)
2114 compare_super = NULL;
2115
David Howells54ceac42006-08-22 20:06:13 -04002116 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002117 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002118 if (IS_ERR(s)) {
2119 error = PTR_ERR(s);
2120 goto out_err_nosb;
2121 }
2122
2123 if (s->s_fs_info != server) {
2124 nfs_free_server(server);
2125 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002126 } else {
2127 error = nfs_bdi_register(server);
2128 if (error)
2129 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002130 }
2131
2132 if (!s->s_root) {
2133 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002134 nfs_clone_super(s, data->sb);
2135 }
2136
2137 mntroot = nfs_get_root(s, data->fh);
2138 if (IS_ERR(mntroot)) {
2139 error = PTR_ERR(mntroot);
2140 goto error_splat_super;
2141 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002142 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002143 dput(mntroot);
2144 error = -ESTALE;
2145 goto error_splat_super;
2146 }
David Howells54ceac42006-08-22 20:06:13 -04002147
2148 s->s_flags |= MS_ACTIVE;
2149 mnt->mnt_sb = s;
2150 mnt->mnt_root = mntroot;
2151
Eric Parisf9c3a382008-03-05 14:20:18 -05002152 /* clone any lsm security options from the parent to the new sb */
2153 security_sb_clone_mnt_opts(data->sb, s);
2154
David Howells54ceac42006-08-22 20:06:13 -04002155 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2156 return 0;
2157
2158out_err_nosb:
2159 nfs_free_server(server);
2160out_err_noserver:
2161 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2162 return error;
2163
2164error_splat_super:
2165 up_write(&s->s_umount);
2166 deactivate_super(s);
2167 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2168 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002169}
2170
2171#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002172
2173/*
2174 * Finish setting up a cloned NFS4 superblock
2175 */
2176static void nfs4_clone_super(struct super_block *sb,
2177 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002178{
David Howells54ceac42006-08-22 20:06:13 -04002179 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2180 sb->s_blocksize = old_sb->s_blocksize;
2181 sb->s_maxbytes = old_sb->s_maxbytes;
2182 sb->s_time_gran = 1;
2183 sb->s_op = old_sb->s_op;
2184 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002185}
2186
2187/*
2188 * Set up an NFS4 superblock
2189 */
David Howells54ceac42006-08-22 20:06:13 -04002190static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002191{
David Howellsf7b422b2006-06-09 09:34:33 -04002192 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002193 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002194 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002195}
2196
David Howells54ceac42006-08-22 20:06:13 -04002197/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002198 * Validate NFSv4 mount options
2199 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002200static int nfs4_validate_mount_data(void *options,
2201 struct nfs_parsed_mount_data *args,
2202 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002203{
Chuck Lever4c568012007-12-10 14:59:28 -05002204 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002205 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002206 char *c;
2207
2208 if (data == NULL)
2209 goto out_no_data;
2210
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002211 args->rsize = NFS_MAX_FILE_IO_SIZE;
2212 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002213 args->acregmin = NFS_DEF_ACREGMIN;
2214 args->acregmax = NFS_DEF_ACREGMAX;
2215 args->acdirmin = NFS_DEF_ACDIRMIN;
2216 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002217 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002218 args->auth_flavors[0] = RPC_AUTH_UNIX;
2219 args->auth_flavor_len = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002220
Chuck Leverf0768eb2007-07-01 12:13:01 -04002221 switch (data->version) {
2222 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002223 ap = (struct sockaddr_in *)&args->nfs_server.address;
2224 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002225 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002226 if (data->host_addrlen == 0)
2227 goto out_no_address;
2228 args->nfs_server.addrlen = data->host_addrlen;
2229 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002230 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002231 if (!nfs_verify_server_address((struct sockaddr *)
2232 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002233 goto out_no_address;
2234
Chuck Lever6738b252008-06-24 16:33:54 -04002235 if (data->auth_flavourlen) {
2236 if (data->auth_flavourlen > 1)
2237 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002238 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002239 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002240 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002241 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002242 }
2243
2244 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2245 if (IS_ERR(c))
2246 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002247 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002248
2249 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2250 if (IS_ERR(c))
2251 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002252 args->nfs_server.export_path = c;
2253 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002254
2255 c = strndup_user(data->client_addr.data, 16);
2256 if (IS_ERR(c))
2257 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002258 args->client_address = c;
2259
2260 /*
2261 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2262 * can deal with.
2263 */
2264
2265 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2266 args->rsize = data->rsize;
2267 args->wsize = data->wsize;
2268 args->timeo = data->timeo;
2269 args->retrans = data->retrans;
2270 args->acregmin = data->acregmin;
2271 args->acregmax = data->acregmax;
2272 args->acdirmin = data->acdirmin;
2273 args->acdirmax = data->acdirmax;
2274 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002275 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002276
2277 break;
Chuck Lever80071222007-07-01 12:13:59 -04002278 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002279 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002280
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002281 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002282 return -EINVAL;
2283
2284 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002285 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002286 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002287
Chuck Levered596a82008-06-26 17:47:05 -04002288 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2289 args->nfs_server.port);
2290
Trond Myklebust259875e2008-07-02 14:43:47 -04002291 nfs_validate_transport_protocol(args);
2292
Chuck Lever6738b252008-06-24 16:33:54 -04002293 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002294 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002295
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002296 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002297 goto out_no_client_address;
2298
Chuck Leverdc045892008-06-23 12:36:37 -04002299 status = nfs_parse_devname(dev_name,
2300 &args->nfs_server.hostname,
2301 NFS4_MAXNAMLEN,
2302 &args->nfs_server.export_path,
2303 NFS4_MAXPATHLEN);
2304 if (status < 0)
2305 return status;
2306
Chuck Lever80071222007-07-01 12:13:59 -04002307 break;
2308 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002309 }
2310
2311 return 0;
2312
2313out_no_data:
2314 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2315 return -EINVAL;
2316
2317out_inval_auth:
2318 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2319 data->auth_flavourlen);
2320 return -EINVAL;
2321
2322out_no_address:
2323 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2324 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002325
2326out_no_client_address:
2327 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2328 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002329}
2330
2331/*
David Howells54ceac42006-08-22 20:06:13 -04002332 * Get the superblock for an NFS4 mountpoint
2333 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002334static int nfs4_get_sb(struct file_system_type *fs_type,
2335 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002336{
Trond Myklebust33852a12008-06-19 14:20:11 -04002337 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002338 struct super_block *s;
2339 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002340 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002341 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002342 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002343 struct nfs_sb_mountdata sb_mntdata = {
2344 .mntflags = flags,
2345 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002346 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002347
Trond Myklebust33852a12008-06-19 14:20:11 -04002348 data = kzalloc(sizeof(*data), GFP_KERNEL);
2349 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2350 if (data == NULL || mntfh == NULL)
2351 goto out_free_fh;
2352
2353 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002354
Chuck Leverf0768eb2007-07-01 12:13:01 -04002355 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002356 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002357 if (error < 0)
2358 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002359
David Howells54ceac42006-08-22 20:06:13 -04002360 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002361 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002362 if (IS_ERR(server)) {
2363 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002364 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002365 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002366 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002367
Trond Myklebust75180df2007-05-16 16:53:28 -04002368 if (server->flags & NFS4_MOUNT_UNSHARED)
2369 compare_super = NULL;
2370
David Howells54ceac42006-08-22 20:06:13 -04002371 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002372 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002373 if (IS_ERR(s)) {
2374 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002375 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002376 }
2377
Trond Myklebust5dd31772006-08-24 01:03:05 -04002378 if (s->s_fs_info != server) {
2379 nfs_free_server(server);
2380 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002381 } else {
2382 error = nfs_bdi_register(server);
2383 if (error)
2384 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002385 }
2386
David Howells54ceac42006-08-22 20:06:13 -04002387 if (!s->s_root) {
2388 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002389 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04002390 }
David Howellsf7b422b2006-06-09 09:34:33 -04002391
Trond Myklebust33852a12008-06-19 14:20:11 -04002392 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002393 if (IS_ERR(mntroot)) {
2394 error = PTR_ERR(mntroot);
2395 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002396 }
David Howells54ceac42006-08-22 20:06:13 -04002397
Trond Myklebust33852a12008-06-19 14:20:11 -04002398 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002399 if (error)
2400 goto error_splat_root;
2401
David Howellsf7b422b2006-06-09 09:34:33 -04002402 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002403 mnt->mnt_sb = s;
2404 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002405 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002406
Chuck Lever29eb9812007-07-01 12:12:30 -04002407out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002408 kfree(data->client_address);
2409 kfree(data->nfs_server.export_path);
2410 kfree(data->nfs_server.hostname);
2411 security_free_mnt_opts(&data->lsm_opts);
2412out_free_fh:
2413 kfree(mntfh);
2414 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002415 return error;
David Howells54ceac42006-08-22 20:06:13 -04002416
Chuck Lever29eb9812007-07-01 12:12:30 -04002417out_free:
2418 nfs_free_server(server);
2419 goto out;
2420
Eric Paris46c8ac72008-05-02 13:42:42 -07002421error_splat_root:
2422 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002423error_splat_super:
2424 up_write(&s->s_umount);
2425 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002426 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002427}
2428
2429static void nfs4_kill_super(struct super_block *sb)
2430{
2431 struct nfs_server *server = NFS_SB(sb);
2432
2433 nfs_return_all_delegations(sb);
2434 kill_anon_super(sb);
2435
2436 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002437 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002438}
2439
2440/*
David Howells54ceac42006-08-22 20:06:13 -04002441 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002442 */
David Howells54ceac42006-08-22 20:06:13 -04002443static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2444 const char *dev_name, void *raw_data,
2445 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002446{
2447 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002448 struct super_block *s;
2449 struct nfs_server *server;
2450 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002451 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002452 struct nfs_sb_mountdata sb_mntdata = {
2453 .mntflags = flags,
2454 };
David Howells54ceac42006-08-22 20:06:13 -04002455 int error;
2456
2457 dprintk("--> nfs4_xdev_get_sb()\n");
2458
2459 /* create a new volume representation */
2460 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2461 if (IS_ERR(server)) {
2462 error = PTR_ERR(server);
2463 goto out_err_noserver;
2464 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002465 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002466
Trond Myklebust75180df2007-05-16 16:53:28 -04002467 if (server->flags & NFS4_MOUNT_UNSHARED)
2468 compare_super = NULL;
2469
David Howells54ceac42006-08-22 20:06:13 -04002470 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002471 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002472 if (IS_ERR(s)) {
2473 error = PTR_ERR(s);
2474 goto out_err_nosb;
2475 }
2476
2477 if (s->s_fs_info != server) {
2478 nfs_free_server(server);
2479 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002480 } else {
2481 error = nfs_bdi_register(server);
2482 if (error)
2483 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002484 }
2485
2486 if (!s->s_root) {
2487 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002488 nfs4_clone_super(s, data->sb);
2489 }
2490
2491 mntroot = nfs4_get_root(s, data->fh);
2492 if (IS_ERR(mntroot)) {
2493 error = PTR_ERR(mntroot);
2494 goto error_splat_super;
2495 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002496 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2497 dput(mntroot);
2498 error = -ESTALE;
2499 goto error_splat_super;
2500 }
David Howells54ceac42006-08-22 20:06:13 -04002501
2502 s->s_flags |= MS_ACTIVE;
2503 mnt->mnt_sb = s;
2504 mnt->mnt_root = mntroot;
2505
Eric Paris46c8ac72008-05-02 13:42:42 -07002506 security_sb_clone_mnt_opts(data->sb, s);
2507
David Howells54ceac42006-08-22 20:06:13 -04002508 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2509 return 0;
2510
2511out_err_nosb:
2512 nfs_free_server(server);
2513out_err_noserver:
2514 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2515 return error;
2516
2517error_splat_super:
2518 up_write(&s->s_umount);
2519 deactivate_super(s);
2520 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2521 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002522}
2523
David Howells54ceac42006-08-22 20:06:13 -04002524/*
2525 * Create an NFS4 server record on referral traversal
2526 */
2527static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2528 const char *dev_name, void *raw_data,
2529 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002530{
2531 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002532 struct super_block *s;
2533 struct nfs_server *server;
2534 struct dentry *mntroot;
2535 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002536 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002537 struct nfs_sb_mountdata sb_mntdata = {
2538 .mntflags = flags,
2539 };
David Howells54ceac42006-08-22 20:06:13 -04002540 int error;
2541
2542 dprintk("--> nfs4_referral_get_sb()\n");
2543
2544 /* create a new volume representation */
2545 server = nfs4_create_referral_server(data, &mntfh);
2546 if (IS_ERR(server)) {
2547 error = PTR_ERR(server);
2548 goto out_err_noserver;
2549 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002550 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002551
Trond Myklebust75180df2007-05-16 16:53:28 -04002552 if (server->flags & NFS4_MOUNT_UNSHARED)
2553 compare_super = NULL;
2554
David Howells54ceac42006-08-22 20:06:13 -04002555 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002556 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002557 if (IS_ERR(s)) {
2558 error = PTR_ERR(s);
2559 goto out_err_nosb;
2560 }
2561
2562 if (s->s_fs_info != server) {
2563 nfs_free_server(server);
2564 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002565 } else {
2566 error = nfs_bdi_register(server);
2567 if (error)
2568 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002569 }
2570
2571 if (!s->s_root) {
2572 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002573 nfs4_fill_super(s);
2574 }
2575
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002576 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002577 if (IS_ERR(mntroot)) {
2578 error = PTR_ERR(mntroot);
2579 goto error_splat_super;
2580 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002581 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2582 dput(mntroot);
2583 error = -ESTALE;
2584 goto error_splat_super;
2585 }
David Howells54ceac42006-08-22 20:06:13 -04002586
2587 s->s_flags |= MS_ACTIVE;
2588 mnt->mnt_sb = s;
2589 mnt->mnt_root = mntroot;
2590
Eric Paris46c8ac72008-05-02 13:42:42 -07002591 security_sb_clone_mnt_opts(data->sb, s);
2592
David Howells54ceac42006-08-22 20:06:13 -04002593 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2594 return 0;
2595
2596out_err_nosb:
2597 nfs_free_server(server);
2598out_err_noserver:
2599 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2600 return error;
2601
2602error_splat_super:
2603 up_write(&s->s_umount);
2604 deactivate_super(s);
2605 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2606 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002607}
2608
David Howells54ceac42006-08-22 20:06:13 -04002609#endif /* CONFIG_NFS_V4 */