blob: bb0313ac9e1fa1a6b94ddb51229298e88b955bfd [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 *
Alan Cox526719b2008-10-27 15:19:48 +00008 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
David Howellsf7b422b2006-06-09 09:34:33 -04009 * 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
Steven Whitehousea447c092008-10-13 10:46:57 +0100102static const match_table_t nfs_mount_option_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400103 { 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
Steven Whitehousea447c092008-10-13 10:46:57 +0100169static const match_table_t nfs_xprt_protocol_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400170 { 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
Steven Whitehousea447c092008-10-13 10:46:57 +0100186static const match_table_t nfs_secflavor_tokens = {
Chuck Leverbf0fd762007-07-01 12:13:44 -0400187 { 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;
Harvey Harrisonbe859402008-10-31 00:56:28 -0700465 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400466 break;
467 }
468 case AF_INET6: {
469 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
Harvey Harrison5b095d9892008-10-29 12:52:50 -0700470 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
Chuck Lever82d101d2008-03-14 14:10:37 -0400471 break;
472 }
473 default:
474 if (showdefaults)
475 seq_printf(m, ",mountaddr=unspecified");
476 }
477
478 if (nfss->mountd_version || showdefaults)
479 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
480 if (nfss->mountd_port || showdefaults)
481 seq_printf(m, ",mountport=%u", nfss->mountd_port);
482
483 switch (nfss->mountd_protocol) {
484 case IPPROTO_UDP:
485 seq_printf(m, ",mountproto=udp");
486 break;
487 case IPPROTO_TCP:
488 seq_printf(m, ",mountproto=tcp");
489 break;
490 default:
491 if (showdefaults)
492 seq_printf(m, ",mountproto=auto");
493 }
494}
495
David Howellsf7b422b2006-06-09 09:34:33 -0400496/*
497 * Describe the mount options in force on this server representation
498 */
Chuck Lever82d101d2008-03-14 14:10:37 -0400499static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
500 int showdefaults)
David Howellsf7b422b2006-06-09 09:34:33 -0400501{
David Howells509de812006-08-22 20:06:11 -0400502 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400503 int flag;
David Howells509de812006-08-22 20:06:11 -0400504 const char *str;
505 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400506 } nfs_info[] = {
507 { NFS_MOUNT_SOFT, ",soft", ",hard" },
Chuck Lever82d101d2008-03-14 14:10:37 -0400508 { NFS_MOUNT_INTR, ",intr", ",nointr" },
509 { NFS_MOUNT_POSIX, ",posix", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400510 { NFS_MOUNT_NOCTO, ",nocto", "" },
511 { NFS_MOUNT_NOAC, ",noac", "" },
512 { NFS_MOUNT_NONLM, ",nolock", "" },
513 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400514 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400515 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400516 { 0, NULL, NULL }
517 };
David Howells509de812006-08-22 20:06:11 -0400518 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400519 struct nfs_client *clp = nfss->nfs_client;
Chuck Lever82d101d2008-03-14 14:10:37 -0400520 u32 version = clp->rpc_ops->version;
David Howellsf7b422b2006-06-09 09:34:33 -0400521
Chuck Lever82d101d2008-03-14 14:10:37 -0400522 seq_printf(m, ",vers=%u", version);
Chuck Lever2d767432008-03-14 14:10:08 -0400523 seq_printf(m, ",rsize=%u", nfss->rsize);
524 seq_printf(m, ",wsize=%u", nfss->wsize);
Chuck Lever82d101d2008-03-14 14:10:37 -0400525 if (nfss->bsize != 0)
526 seq_printf(m, ",bsize=%u", nfss->bsize);
527 seq_printf(m, ",namlen=%u", nfss->namelen);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400528 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400529 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400530 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400531 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400532 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400533 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
Chuck Lever0e0cab72008-06-26 17:47:12 -0400534 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
Chuck Lever2d767432008-03-14 14:10:08 -0400535 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
David Howellsf7b422b2006-06-09 09:34:33 -0400536 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
537 if (nfss->flags & nfs_infop->flag)
538 seq_puts(m, nfs_infop->str);
539 else
540 seq_puts(m, nfs_infop->nostr);
541 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400542 seq_printf(m, ",proto=%s",
543 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Chuck Lever82d101d2008-03-14 14:10:37 -0400544 if (version == 4) {
545 if (nfss->port != NFS_PORT)
546 seq_printf(m, ",port=%u", nfss->port);
547 } else
548 if (nfss->port)
549 seq_printf(m, ",port=%u", nfss->port);
550
Trond Myklebust33170232007-12-20 16:03:59 -0500551 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
552 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400553 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
Chuck Lever82d101d2008-03-14 14:10:37 -0400554
555 if (version != 4)
556 nfs_show_mountd_options(m, nfss, showdefaults);
557
558#ifdef CONFIG_NFS_V4
559 if (clp->rpc_ops->version == 4)
560 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
561#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400562}
563
564/*
565 * Describe the mount options on this VFS mountpoint
566 */
567static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
568{
569 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
570
571 nfs_show_mount_options(m, nfss, 0);
572
Chuck Lever5d8515c2007-12-10 14:57:16 -0500573 seq_printf(m, ",addr=%s",
574 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
575 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400576
577 return 0;
578}
579
580/*
581 * Present statistical information for this VFS mountpoint
582 */
583static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
584{
585 int i, cpu;
586 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
587 struct rpc_auth *auth = nfss->client->cl_auth;
588 struct nfs_iostats totals = { };
589
590 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
591
592 /*
593 * Display all mount option settings
594 */
595 seq_printf(m, "\n\topts:\t");
596 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
597 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
598 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
599 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
600 nfs_show_mount_options(m, nfss, 1);
601
602 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
603
604 seq_printf(m, "\n\tcaps:\t");
605 seq_printf(m, "caps=0x%x", nfss->caps);
Chuck Lever2d767432008-03-14 14:10:08 -0400606 seq_printf(m, ",wtmult=%u", nfss->wtmult);
607 seq_printf(m, ",dtsize=%u", nfss->dtsize);
608 seq_printf(m, ",bsize=%u", nfss->bsize);
609 seq_printf(m, ",namlen=%u", nfss->namelen);
David Howellsf7b422b2006-06-09 09:34:33 -0400610
611#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500612 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400613 seq_printf(m, "\n\tnfsv4:\t");
614 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
615 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
616 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
617 }
618#endif
619
620 /*
621 * Display security flavor in effect for this mount
622 */
Chuck Lever2d767432008-03-14 14:10:08 -0400623 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400624 if (auth->au_flavor)
Chuck Lever2d767432008-03-14 14:10:08 -0400625 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
David Howellsf7b422b2006-06-09 09:34:33 -0400626
627 /*
628 * Display superblock I/O counters
629 */
630 for_each_possible_cpu(cpu) {
631 struct nfs_iostats *stats;
632
633 preempt_disable();
634 stats = per_cpu_ptr(nfss->io_stats, cpu);
635
636 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
637 totals.events[i] += stats->events[i];
638 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
639 totals.bytes[i] += stats->bytes[i];
640
641 preempt_enable();
642 }
643
644 seq_printf(m, "\n\tevents:\t");
645 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
646 seq_printf(m, "%lu ", totals.events[i]);
647 seq_printf(m, "\n\tbytes:\t");
648 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
649 seq_printf(m, "%Lu ", totals.bytes[i]);
650 seq_printf(m, "\n");
651
652 rpc_print_iostats(m, nfss->client);
653
654 return 0;
655}
656
657/*
658 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400659 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400660 */
Al Viro42faad92008-04-24 07:21:56 -0400661static void nfs_umount_begin(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400662{
Al Viro42faad92008-04-24 07:21:56 -0400663 struct nfs_server *server = NFS_SB(sb);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400664 struct rpc_clnt *rpc;
665
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400666 /* -EIO all pending I/O */
667 rpc = server->client_acl;
668 if (!IS_ERR(rpc))
669 rpc_killall_tasks(rpc);
670 rpc = server->client;
671 if (!IS_ERR(rpc))
672 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400673}
674
675/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500676 * Sanity-check a server address provided by the mount command.
677 *
678 * Address family must be initialized, and address must not be
679 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400680 */
681static int nfs_verify_server_address(struct sockaddr *addr)
682{
683 switch (addr->sa_family) {
684 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500685 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Al Viroe6f1ceb2008-03-17 22:44:53 -0700686 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
Chuck Levercdcd7f92007-12-10 14:57:45 -0500687 }
688 case AF_INET6: {
689 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
690 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400691 }
692 }
693
694 return 0;
695}
696
Chuck Leverce3b7e12008-06-23 12:36:53 -0400697static void nfs_parse_ipv4_address(char *string, size_t str_len,
698 struct sockaddr *sap, size_t *addr_len)
Chuck Lever9412b922007-12-10 14:59:21 -0500699{
Chuck Leverce3b7e12008-06-23 12:36:53 -0400700 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
701 u8 *addr = (u8 *)&sin->sin_addr.s_addr;
Chuck Lever9412b922007-12-10 14:59:21 -0500702
Chuck Leverce3b7e12008-06-23 12:36:53 -0400703 if (str_len <= INET_ADDRSTRLEN) {
704 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
705 (int)str_len, string);
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500706
Chuck Leverce3b7e12008-06-23 12:36:53 -0400707 sin->sin_family = AF_INET;
708 *addr_len = sizeof(*sin);
709 if (in4_pton(string, str_len, addr, '\0', NULL))
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500710 return;
711 }
Chuck Lever9412b922007-12-10 14:59:21 -0500712
713 sap->sa_family = AF_UNSPEC;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400714 *addr_len = 0;
715}
716
717#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400718static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
719 const char *delim,
720 struct sockaddr_in6 *sin6)
Chuck Leverd8e77482008-06-23 12:37:01 -0400721{
722 char *p;
723 size_t len;
724
Chuck Lever5e2e7722008-10-08 15:38:10 -0400725 if ((string + str_len) == delim)
726 return 1;
727
Chuck Leverd8e77482008-06-23 12:37:01 -0400728 if (*delim != IPV6_SCOPE_DELIMITER)
Chuck Lever5e2e7722008-10-08 15:38:10 -0400729 return 0;
730
731 if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
732 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400733
734 len = (string + str_len) - delim - 1;
735 p = kstrndup(delim + 1, len, GFP_KERNEL);
736 if (p) {
737 unsigned long scope_id = 0;
738 struct net_device *dev;
739
740 dev = dev_get_by_name(&init_net, p);
741 if (dev != NULL) {
742 scope_id = dev->ifindex;
743 dev_put(dev);
744 } else {
Chuck Lever5e2e7722008-10-08 15:38:10 -0400745 if (strict_strtoul(p, 10, &scope_id) == 0) {
746 kfree(p);
747 return 0;
748 }
Chuck Leverd8e77482008-06-23 12:37:01 -0400749 }
750
751 kfree(p);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400752
Chuck Leverd8e77482008-06-23 12:37:01 -0400753 sin6->sin6_scope_id = scope_id;
754 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400755 return 1;
Chuck Leverd8e77482008-06-23 12:37:01 -0400756 }
Chuck Lever5e2e7722008-10-08 15:38:10 -0400757
758 return 0;
Chuck Leverd8e77482008-06-23 12:37:01 -0400759}
760
Chuck Leverce3b7e12008-06-23 12:36:53 -0400761static void nfs_parse_ipv6_address(char *string, size_t str_len,
762 struct sockaddr *sap, size_t *addr_len)
763{
764 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
765 u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
Chuck Leverd8e77482008-06-23 12:37:01 -0400766 const char *delim;
Chuck Leverce3b7e12008-06-23 12:36:53 -0400767
768 if (str_len <= INET6_ADDRSTRLEN) {
769 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
770 (int)str_len, string);
771
772 sin6->sin6_family = AF_INET6;
773 *addr_len = sizeof(*sin6);
Chuck Lever5e2e7722008-10-08 15:38:10 -0400774 if (in6_pton(string, str_len, addr,
775 IPV6_SCOPE_DELIMITER, &delim) != 0) {
776 if (nfs_parse_ipv6_scope_id(string, str_len,
777 delim, sin6) != 0)
778 return;
Chuck Leverd8e77482008-06-23 12:37:01 -0400779 }
Chuck Leverce3b7e12008-06-23 12:36:53 -0400780 }
781
782 sap->sa_family = AF_UNSPEC;
783 *addr_len = 0;
784}
785#else
786static void nfs_parse_ipv6_address(char *string, size_t str_len,
787 struct sockaddr *sap, size_t *addr_len)
788{
789 sap->sa_family = AF_UNSPEC;
790 *addr_len = 0;
791}
792#endif
793
794/*
795 * Construct a sockaddr based on the contents of a string that contains
796 * an IP address in presentation format.
797 *
798 * If there is a problem constructing the new sockaddr, set the address
799 * family to AF_UNSPEC.
800 */
J. Bruce Fieldsea31a4432008-08-20 16:10:23 -0400801void nfs_parse_ip_address(char *string, size_t str_len,
Chuck Leverce3b7e12008-06-23 12:36:53 -0400802 struct sockaddr *sap, size_t *addr_len)
803{
804 unsigned int i, colons;
805
806 colons = 0;
807 for (i = 0; i < str_len; i++)
808 if (string[i] == ':')
809 colons++;
810
811 if (colons >= 2)
812 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
813 else
814 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
Chuck Lever9412b922007-12-10 14:59:21 -0500815}
816
817/*
Trond Myklebust259875e2008-07-02 14:43:47 -0400818 * Sanity check the NFS transport protocol.
819 *
820 */
821static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
822{
823 switch (mnt->nfs_server.protocol) {
824 case XPRT_TRANSPORT_UDP:
825 case XPRT_TRANSPORT_TCP:
826 case XPRT_TRANSPORT_RDMA:
827 break;
828 default:
829 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
830 }
831}
832
833/*
834 * For text based NFSv2/v3 mounts, the mount protocol transport default
835 * settings should depend upon the specified NFS transport.
836 */
837static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
838{
839 nfs_validate_transport_protocol(mnt);
840
841 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
842 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
843 return;
844 switch (mnt->nfs_server.protocol) {
845 case XPRT_TRANSPORT_UDP:
846 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
847 break;
848 case XPRT_TRANSPORT_TCP:
849 case XPRT_TRANSPORT_RDMA:
850 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
851 }
852}
853
854/*
Chuck Lever01060c82008-06-24 16:33:38 -0400855 * Parse the value of the 'sec=' option.
856 *
Chuck Leverdd07c942008-06-24 16:33:46 -0400857 * The flavor_len setting is for v4 mounts.
Chuck Lever01060c82008-06-24 16:33:38 -0400858 */
859static int nfs_parse_security_flavors(char *value,
860 struct nfs_parsed_mount_data *mnt)
861{
862 substring_t args[MAX_OPT_ARGS];
863
864 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
865
866 switch (match_token(value, nfs_secflavor_tokens, args)) {
867 case Opt_sec_none:
Chuck Lever01060c82008-06-24 16:33:38 -0400868 mnt->auth_flavor_len = 0;
869 mnt->auth_flavors[0] = RPC_AUTH_NULL;
870 break;
871 case Opt_sec_sys:
Chuck Lever01060c82008-06-24 16:33:38 -0400872 mnt->auth_flavor_len = 0;
873 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
874 break;
875 case Opt_sec_krb5:
Chuck Lever01060c82008-06-24 16:33:38 -0400876 mnt->auth_flavor_len = 1;
877 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
878 break;
879 case Opt_sec_krb5i:
Chuck Lever01060c82008-06-24 16:33:38 -0400880 mnt->auth_flavor_len = 1;
881 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
882 break;
883 case Opt_sec_krb5p:
Chuck Lever01060c82008-06-24 16:33:38 -0400884 mnt->auth_flavor_len = 1;
885 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
886 break;
887 case Opt_sec_lkey:
Chuck Lever01060c82008-06-24 16:33:38 -0400888 mnt->auth_flavor_len = 1;
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
890 break;
891 case Opt_sec_lkeyi:
Chuck Lever01060c82008-06-24 16:33:38 -0400892 mnt->auth_flavor_len = 1;
893 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
894 break;
895 case Opt_sec_lkeyp:
Chuck Lever01060c82008-06-24 16:33:38 -0400896 mnt->auth_flavor_len = 1;
897 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
898 break;
899 case Opt_sec_spkm:
Chuck Lever01060c82008-06-24 16:33:38 -0400900 mnt->auth_flavor_len = 1;
901 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
902 break;
903 case Opt_sec_spkmi:
Chuck Lever01060c82008-06-24 16:33:38 -0400904 mnt->auth_flavor_len = 1;
905 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
906 break;
907 case Opt_sec_spkmp:
Chuck Lever01060c82008-06-24 16:33:38 -0400908 mnt->auth_flavor_len = 1;
909 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
910 break;
911 default:
912 return 0;
913 }
914
915 return 1;
916}
917
Chuck Leverf45663c2008-06-24 19:28:02 -0400918static void nfs_parse_invalid_value(const char *option)
919{
920 dfprintk(MOUNT, "NFS: bad value specified for %s option\n", option);
921}
922
Chuck Lever01060c82008-06-24 16:33:38 -0400923/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400924 * Error-check and convert a string of mount options from user space into
Chuck Leverf45663c2008-06-24 19:28:02 -0400925 * a data structure. The whole mount string is processed; bad options are
926 * skipped as they are encountered. If there were no errors, return 1;
927 * otherwise return 0 (zero).
Chuck Leverbf0fd762007-07-01 12:13:44 -0400928 */
929static int nfs_parse_mount_options(char *raw,
930 struct nfs_parsed_mount_data *mnt)
931{
Eric Parisf9c3a382008-03-05 14:20:18 -0500932 char *p, *string, *secdata;
Chuck Leverf45663c2008-06-24 19:28:02 -0400933 int rc, sloppy = 0, errors = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400934
935 if (!raw) {
936 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
937 return 1;
938 }
939 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
940
Eric Parisf9c3a382008-03-05 14:20:18 -0500941 secdata = alloc_secdata();
942 if (!secdata)
943 goto out_nomem;
944
945 rc = security_sb_copy_data(raw, secdata);
946 if (rc)
947 goto out_security_failure;
948
949 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
950 if (rc)
951 goto out_security_failure;
952
953 free_secdata(secdata);
954
Chuck Leverbf0fd762007-07-01 12:13:44 -0400955 while ((p = strsep(&raw, ",")) != NULL) {
956 substring_t args[MAX_OPT_ARGS];
957 int option, token;
958
959 if (!*p)
960 continue;
961
962 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
963
964 token = match_token(p, nfs_mount_option_tokens, args);
965 switch (token) {
Chuck Leverf45663c2008-06-24 19:28:02 -0400966
967 /*
968 * boolean options: foo/nofoo
969 */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400970 case Opt_soft:
971 mnt->flags |= NFS_MOUNT_SOFT;
972 break;
973 case Opt_hard:
974 mnt->flags &= ~NFS_MOUNT_SOFT;
975 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400976 case Opt_posix:
977 mnt->flags |= NFS_MOUNT_POSIX;
978 break;
979 case Opt_noposix:
980 mnt->flags &= ~NFS_MOUNT_POSIX;
981 break;
982 case Opt_cto:
983 mnt->flags &= ~NFS_MOUNT_NOCTO;
984 break;
985 case Opt_nocto:
986 mnt->flags |= NFS_MOUNT_NOCTO;
987 break;
988 case Opt_ac:
989 mnt->flags &= ~NFS_MOUNT_NOAC;
990 break;
991 case Opt_noac:
992 mnt->flags |= NFS_MOUNT_NOAC;
993 break;
994 case Opt_lock:
995 mnt->flags &= ~NFS_MOUNT_NONLM;
996 break;
997 case Opt_nolock:
998 mnt->flags |= NFS_MOUNT_NONLM;
999 break;
1000 case Opt_v2:
1001 mnt->flags &= ~NFS_MOUNT_VER3;
1002 break;
1003 case Opt_v3:
1004 mnt->flags |= NFS_MOUNT_VER3;
1005 break;
1006 case Opt_udp:
1007 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001008 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001009 break;
1010 case Opt_tcp:
1011 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001012 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001013 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001014 case Opt_rdma:
1015 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1016 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001017 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001018 case Opt_acl:
1019 mnt->flags &= ~NFS_MOUNT_NOACL;
1020 break;
1021 case Opt_noacl:
1022 mnt->flags |= NFS_MOUNT_NOACL;
1023 break;
1024 case Opt_rdirplus:
1025 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1026 break;
1027 case Opt_nordirplus:
1028 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1029 break;
Trond Myklebust75180df2007-05-16 16:53:28 -04001030 case Opt_sharecache:
1031 mnt->flags &= ~NFS_MOUNT_UNSHARED;
1032 break;
1033 case Opt_nosharecache:
1034 mnt->flags |= NFS_MOUNT_UNSHARED;
1035 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001036
Chuck Leverf45663c2008-06-24 19:28:02 -04001037 /*
1038 * options that take numeric values
1039 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001040 case Opt_port:
Chuck Leverf45663c2008-06-24 19:28:02 -04001041 if (match_int(args, &option) ||
1042 option < 0 || option > USHORT_MAX) {
1043 errors++;
1044 nfs_parse_invalid_value("port");
1045 } else
1046 mnt->nfs_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001047 break;
1048 case Opt_rsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001049 if (match_int(args, &option) || option < 0) {
1050 errors++;
1051 nfs_parse_invalid_value("rsize");
1052 } else
1053 mnt->rsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001054 break;
1055 case Opt_wsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001056 if (match_int(args, &option) || option < 0) {
1057 errors++;
1058 nfs_parse_invalid_value("wsize");
1059 } else
1060 mnt->wsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001061 break;
1062 case Opt_bsize:
Chuck Leverf45663c2008-06-24 19:28:02 -04001063 if (match_int(args, &option) || option < 0) {
1064 errors++;
1065 nfs_parse_invalid_value("bsize");
1066 } else
1067 mnt->bsize = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001068 break;
1069 case Opt_timeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001070 if (match_int(args, &option) || option <= 0) {
1071 errors++;
1072 nfs_parse_invalid_value("timeo");
1073 } else
1074 mnt->timeo = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001075 break;
1076 case Opt_retrans:
Chuck Leverf45663c2008-06-24 19:28:02 -04001077 if (match_int(args, &option) || option <= 0) {
1078 errors++;
1079 nfs_parse_invalid_value("retrans");
1080 } else
1081 mnt->retrans = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001082 break;
1083 case Opt_acregmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001084 if (match_int(args, &option) || option < 0) {
1085 errors++;
1086 nfs_parse_invalid_value("acregmin");
1087 } else
1088 mnt->acregmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001089 break;
1090 case Opt_acregmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001091 if (match_int(args, &option) || option < 0) {
1092 errors++;
1093 nfs_parse_invalid_value("acregmax");
1094 } else
1095 mnt->acregmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001096 break;
1097 case Opt_acdirmin:
Chuck Leverf45663c2008-06-24 19:28:02 -04001098 if (match_int(args, &option) || option < 0) {
1099 errors++;
1100 nfs_parse_invalid_value("acdirmin");
1101 } else
1102 mnt->acdirmin = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001103 break;
1104 case Opt_acdirmax:
Chuck Leverf45663c2008-06-24 19:28:02 -04001105 if (match_int(args, &option) || option < 0) {
1106 errors++;
1107 nfs_parse_invalid_value("acdirmax");
1108 } else
1109 mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001110 break;
1111 case Opt_actimeo:
Chuck Leverf45663c2008-06-24 19:28:02 -04001112 if (match_int(args, &option) || option < 0) {
1113 errors++;
1114 nfs_parse_invalid_value("actimeo");
1115 } else
1116 mnt->acregmin = mnt->acregmax =
1117 mnt->acdirmin = mnt->acdirmax = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001118 break;
1119 case Opt_namelen:
Chuck Leverf45663c2008-06-24 19:28:02 -04001120 if (match_int(args, &option) || option < 0) {
1121 errors++;
1122 nfs_parse_invalid_value("namlen");
1123 } else
1124 mnt->namlen = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001125 break;
1126 case Opt_mountport:
Chuck Leverf45663c2008-06-24 19:28:02 -04001127 if (match_int(args, &option) ||
1128 option < 0 || option > USHORT_MAX) {
1129 errors++;
1130 nfs_parse_invalid_value("mountport");
1131 } else
1132 mnt->mount_server.port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001133 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001134 case Opt_mountvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001135 if (match_int(args, &option) ||
1136 option < NFS_MNT_VERSION ||
1137 option > NFS_MNT3_VERSION) {
1138 errors++;
1139 nfs_parse_invalid_value("mountvers");
1140 } else
1141 mnt->mount_server.version = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001142 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001143 case Opt_nfsvers:
Chuck Leverf45663c2008-06-24 19:28:02 -04001144 if (match_int(args, &option)) {
1145 errors++;
1146 nfs_parse_invalid_value("nfsvers");
1147 break;
1148 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001149 switch (option) {
Chuck Leverf45663c2008-06-24 19:28:02 -04001150 case NFS2_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001151 mnt->flags &= ~NFS_MOUNT_VER3;
1152 break;
Chuck Leverf45663c2008-06-24 19:28:02 -04001153 case NFS3_VERSION:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001154 mnt->flags |= NFS_MOUNT_VER3;
1155 break;
1156 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001157 errors++;
1158 nfs_parse_invalid_value("nfsvers");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001159 }
1160 break;
1161
Chuck Leverf45663c2008-06-24 19:28:02 -04001162 /*
1163 * options that take text values
1164 */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001165 case Opt_sec:
1166 string = match_strdup(args);
1167 if (string == NULL)
1168 goto out_nomem;
Chuck Lever01060c82008-06-24 16:33:38 -04001169 rc = nfs_parse_security_flavors(string, mnt);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001170 kfree(string);
Chuck Leverf45663c2008-06-24 19:28:02 -04001171 if (!rc) {
1172 errors++;
1173 dfprintk(MOUNT, "NFS: unrecognized "
1174 "security flavor\n");
1175 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001176 break;
1177 case Opt_proto:
1178 string = match_strdup(args);
1179 if (string == NULL)
1180 goto out_nomem;
1181 token = match_token(string,
1182 nfs_xprt_protocol_tokens, args);
1183 kfree(string);
1184
1185 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001186 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001187 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001188 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001189 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001190 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001191 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001192 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001193 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001194 case Opt_xprt_rdma:
1195 /* vector side protocols to TCP */
1196 mnt->flags |= NFS_MOUNT_TCP;
1197 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001198 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001199 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001200 errors++;
1201 dfprintk(MOUNT, "NFS: unrecognized "
1202 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001203 }
1204 break;
1205 case Opt_mountproto:
1206 string = match_strdup(args);
1207 if (string == NULL)
1208 goto out_nomem;
1209 token = match_token(string,
1210 nfs_xprt_protocol_tokens, args);
1211 kfree(string);
1212
1213 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001214 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001215 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001216 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -04001217 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001218 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001219 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -04001220 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -04001221 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001222 errors++;
1223 dfprintk(MOUNT, "NFS: unrecognized "
1224 "transport protocol\n");
Chuck Leverbf0fd762007-07-01 12:13:44 -04001225 }
1226 break;
1227 case Opt_addr:
1228 string = match_strdup(args);
1229 if (string == NULL)
1230 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001231 nfs_parse_ip_address(string, strlen(string),
1232 (struct sockaddr *)
1233 &mnt->nfs_server.address,
1234 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001235 kfree(string);
1236 break;
1237 case Opt_clientaddr:
1238 string = match_strdup(args);
1239 if (string == NULL)
1240 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001241 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001242 mnt->client_address = string;
1243 break;
Chuck Lever33832032007-12-10 14:59:13 -05001244 case Opt_mounthost:
1245 string = match_strdup(args);
1246 if (string == NULL)
1247 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001248 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001249 mnt->mount_server.hostname = string;
1250 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001251 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001252 string = match_strdup(args);
1253 if (string == NULL)
1254 goto out_nomem;
Chuck Leverce3b7e12008-06-23 12:36:53 -04001255 nfs_parse_ip_address(string, strlen(string),
1256 (struct sockaddr *)
1257 &mnt->mount_server.address,
1258 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001259 kfree(string);
1260 break;
Trond Myklebust7973c1f2008-07-15 17:58:14 -04001261 case Opt_lookupcache:
1262 string = match_strdup(args);
1263 if (string == NULL)
1264 goto out_nomem;
1265 token = match_token(string,
1266 nfs_lookupcache_tokens, args);
1267 kfree(string);
1268 switch (token) {
1269 case Opt_lookupcache_all:
1270 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1271 break;
1272 case Opt_lookupcache_positive:
1273 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1274 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1275 break;
1276 case Opt_lookupcache_none:
1277 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1278 break;
1279 default:
1280 errors++;
1281 dfprintk(MOUNT, "NFS: invalid "
1282 "lookupcache argument\n");
1283 };
1284 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001285
Chuck Leverf45663c2008-06-24 19:28:02 -04001286 /*
1287 * Special options
1288 */
1289 case Opt_sloppy:
1290 sloppy = 1;
1291 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1292 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001293 case Opt_userspace:
1294 case Opt_deprecated:
Chuck Leverd33e4df2008-06-12 12:37:41 -04001295 dfprintk(MOUNT, "NFS: ignoring mount option "
1296 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001297 break;
1298
1299 default:
Chuck Leverf45663c2008-06-24 19:28:02 -04001300 errors++;
1301 dfprintk(MOUNT, "NFS: unrecognized mount option "
1302 "'%s'\n", p);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001303 }
1304 }
1305
Chuck Leveraf904de2008-09-08 11:58:13 -04001306 if (errors > 0) {
1307 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1308 errors, (errors == 1 ? "" : "s"));
1309 if (!sloppy)
1310 return 0;
1311 }
Chuck Leverbf0fd762007-07-01 12:13:44 -04001312 return 1;
1313
1314out_nomem:
1315 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1316 return 0;
Eric Parisf9c3a382008-03-05 14:20:18 -05001317out_security_failure:
1318 free_secdata(secdata);
1319 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1320 return 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -04001321}
1322
1323/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001324 * Use the remote server's MOUNT service to request the NFS file handle
1325 * corresponding to the provided path.
1326 */
1327static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1328 struct nfs_fh *root_fh)
1329{
Chuck Lever4c568012007-12-10 14:59:28 -05001330 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001331 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001332 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001333
1334 if (args->mount_server.version == 0) {
1335 if (args->flags & NFS_MOUNT_VER3)
1336 args->mount_server.version = NFS_MNT3_VERSION;
1337 else
1338 args->mount_server.version = NFS_MNT_VERSION;
1339 }
1340
Chuck Lever33832032007-12-10 14:59:13 -05001341 if (args->mount_server.hostname)
1342 hostname = args->mount_server.hostname;
1343 else
1344 hostname = args->nfs_server.hostname;
1345
Chuck Lever0076d7b2007-07-01 12:13:49 -04001346 /*
1347 * Construct the mount server's address.
1348 */
Chuck Lever4c568012007-12-10 14:59:28 -05001349 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1350 memcpy(sap, &args->nfs_server.address,
1351 args->nfs_server.addrlen);
1352 args->mount_server.addrlen = args->nfs_server.addrlen;
1353 }
1354
James Lentiniaad70002007-09-24 17:32:49 -04001355 /*
1356 * autobind will be used if mount_server.port == 0
1357 */
Chuck Lever4c568012007-12-10 14:59:28 -05001358 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001359
1360 /*
1361 * Now ask the mount server to map our export path
1362 * to a file handle.
1363 */
Chuck Lever4c568012007-12-10 14:59:28 -05001364 status = nfs_mount(sap,
1365 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001366 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001367 args->nfs_server.export_path,
1368 args->mount_server.version,
1369 args->mount_server.protocol,
1370 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001371 if (status == 0)
1372 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001373
Chuck Lever396cee972008-06-12 12:37:49 -04001374 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
Chuck Lever33832032007-12-10 14:59:13 -05001375 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001376 return status;
1377}
1378
Chuck Leverd1aa0822008-06-23 12:36:45 -04001379static int nfs_parse_simple_hostname(const char *dev_name,
1380 char **hostname, size_t maxnamlen,
1381 char **export_path, size_t maxpathlen)
Chuck Leverdc045892008-06-23 12:36:37 -04001382{
1383 size_t len;
1384 char *colon, *comma;
1385
1386 colon = strchr(dev_name, ':');
1387 if (colon == NULL)
1388 goto out_bad_devname;
1389
1390 len = colon - dev_name;
1391 if (len > maxnamlen)
1392 goto out_hostname;
1393
1394 /* N.B. caller will free nfs_server.hostname in all cases */
1395 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1396 if (!*hostname)
1397 goto out_nomem;
1398
1399 /* kill possible hostname list: not supported */
1400 comma = strchr(*hostname, ',');
1401 if (comma != NULL) {
1402 if (comma == *hostname)
1403 goto out_bad_devname;
1404 *comma = '\0';
1405 }
1406
1407 colon++;
1408 len = strlen(colon);
1409 if (len > maxpathlen)
1410 goto out_path;
1411 *export_path = kstrndup(colon, len, GFP_KERNEL);
1412 if (!*export_path)
1413 goto out_nomem;
1414
1415 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1416 return 0;
1417
1418out_bad_devname:
1419 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1420 return -EINVAL;
1421
1422out_nomem:
1423 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1424 return -ENOMEM;
1425
1426out_hostname:
1427 dfprintk(MOUNT, "NFS: server hostname too long\n");
1428 return -ENAMETOOLONG;
1429
1430out_path:
1431 dfprintk(MOUNT, "NFS: export pathname too long\n");
1432 return -ENAMETOOLONG;
1433}
1434
1435/*
Chuck Leverd1aa0822008-06-23 12:36:45 -04001436 * Hostname has square brackets around it because it contains one or
1437 * more colons. We look for the first closing square bracket, and a
1438 * colon must follow it.
1439 */
1440static int nfs_parse_protected_hostname(const char *dev_name,
1441 char **hostname, size_t maxnamlen,
1442 char **export_path, size_t maxpathlen)
1443{
1444 size_t len;
1445 char *start, *end;
1446
1447 start = (char *)(dev_name + 1);
1448
1449 end = strchr(start, ']');
1450 if (end == NULL)
1451 goto out_bad_devname;
1452 if (*(end + 1) != ':')
1453 goto out_bad_devname;
1454
1455 len = end - start;
1456 if (len > maxnamlen)
1457 goto out_hostname;
1458
1459 /* N.B. caller will free nfs_server.hostname in all cases */
1460 *hostname = kstrndup(start, len, GFP_KERNEL);
1461 if (*hostname == NULL)
1462 goto out_nomem;
1463
1464 end += 2;
1465 len = strlen(end);
1466 if (len > maxpathlen)
1467 goto out_path;
1468 *export_path = kstrndup(end, len, GFP_KERNEL);
1469 if (!*export_path)
1470 goto out_nomem;
1471
1472 return 0;
1473
1474out_bad_devname:
1475 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1476 return -EINVAL;
1477
1478out_nomem:
1479 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1480 return -ENOMEM;
1481
1482out_hostname:
1483 dfprintk(MOUNT, "NFS: server hostname too long\n");
1484 return -ENAMETOOLONG;
1485
1486out_path:
1487 dfprintk(MOUNT, "NFS: export pathname too long\n");
1488 return -ENAMETOOLONG;
1489}
1490
1491/*
1492 * Split "dev_name" into "hostname:export_path".
1493 *
1494 * The leftmost colon demarks the split between the server's hostname
1495 * and the export path. If the hostname starts with a left square
1496 * bracket, then it may contain colons.
1497 *
1498 * Note: caller frees hostname and export path, even on error.
1499 */
1500static int nfs_parse_devname(const char *dev_name,
1501 char **hostname, size_t maxnamlen,
1502 char **export_path, size_t maxpathlen)
1503{
1504 if (*dev_name == '[')
1505 return nfs_parse_protected_hostname(dev_name,
1506 hostname, maxnamlen,
1507 export_path, maxpathlen);
1508
1509 return nfs_parse_simple_hostname(dev_name,
1510 hostname, maxnamlen,
1511 export_path, maxpathlen);
1512}
1513
1514/*
David Howells54ceac42006-08-22 20:06:13 -04001515 * Validate the NFS2/NFS3 mount data
1516 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001517 *
1518 * For option strings, user space handles the following behaviors:
1519 *
1520 * + DNS: mapping server host name to IP address ("addr=" option)
1521 *
1522 * + failure mode: how to behave if a mount request can't be handled
1523 * immediately ("fg/bg" option)
1524 *
1525 * + retry: how often to retry a mount request ("retry=" option)
1526 *
1527 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1528 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001529 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001530static int nfs_validate_mount_data(void *options,
1531 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001532 struct nfs_fh *mntfh,
1533 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001534{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001535 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001536
Chuck Lever5df36e72007-07-01 12:12:56 -04001537 if (data == NULL)
1538 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001539
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001540 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1541 args->rsize = NFS_MAX_FILE_IO_SIZE;
1542 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04001543 args->acregmin = NFS_DEF_ACREGMIN;
1544 args->acregmax = NFS_DEF_ACREGMAX;
1545 args->acdirmin = NFS_DEF_ACDIRMIN;
1546 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04001547 args->mount_server.port = 0; /* autobind unless user sets port */
Chuck Leverf22d6d72008-03-14 14:10:22 -04001548 args->nfs_server.port = 0; /* autobind unless user sets port */
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001549 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverdd07c942008-06-24 16:33:46 -04001550 args->auth_flavors[0] = RPC_AUTH_UNIX;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001551
David Howellsf7b422b2006-06-09 09:34:33 -04001552 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001553 case 1:
1554 data->namlen = 0;
1555 case 2:
1556 data->bsize = 0;
1557 case 3:
1558 if (data->flags & NFS_MOUNT_VER3)
1559 goto out_no_v3;
1560 data->root.size = NFS2_FHSIZE;
1561 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1562 case 4:
1563 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1564 goto out_no_sec;
1565 case 5:
1566 memset(data->context, 0, sizeof(data->context));
1567 case 6:
Trond Myklebustb7e24452008-06-19 15:21:11 -04001568 if (data->flags & NFS_MOUNT_VER3) {
1569 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1570 goto out_invalid_fh;
Chuck Lever5df36e72007-07-01 12:12:56 -04001571 mntfh->size = data->root.size;
Trond Myklebustb7e24452008-06-19 15:21:11 -04001572 } else
Chuck Lever5df36e72007-07-01 12:12:56 -04001573 mntfh->size = NFS2_FHSIZE;
1574
Chuck Lever5df36e72007-07-01 12:12:56 -04001575
1576 memcpy(mntfh->data, data->root.data, mntfh->size);
1577 if (mntfh->size < sizeof(mntfh->data))
1578 memset(mntfh->data + mntfh->size, 0,
1579 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001580
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001581 /*
1582 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1583 * can deal with.
1584 */
Trond Myklebustff3525a2008-08-15 16:59:14 -04001585 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001586 args->rsize = data->rsize;
1587 args->wsize = data->wsize;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001588 args->timeo = data->timeo;
1589 args->retrans = data->retrans;
1590 args->acregmin = data->acregmin;
1591 args->acregmax = data->acregmax;
1592 args->acdirmin = data->acdirmin;
1593 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001594
1595 memcpy(&args->nfs_server.address, &data->addr,
1596 sizeof(data->addr));
1597 args->nfs_server.addrlen = sizeof(data->addr);
1598 if (!nfs_verify_server_address((struct sockaddr *)
1599 &args->nfs_server.address))
1600 goto out_no_address;
1601
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001602 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001603 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001604 /* N.B. caller will free nfs_server.hostname in all cases */
1605 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1606 args->namlen = data->namlen;
1607 args->bsize = data->bsize;
Chuck Leverdd07c942008-06-24 16:33:46 -04001608
1609 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1610 args->auth_flavors[0] = data->pseudoflavor;
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001611 if (!args->nfs_server.hostname)
1612 goto out_nomem;
Eric Parisf9c3a382008-03-05 14:20:18 -05001613
1614 /*
1615 * The legacy version 6 binary mount data from userspace has a
1616 * field used only to transport selinux information into the
1617 * the kernel. To continue to support that functionality we
1618 * have a touch of selinux knowledge here in the NFS code. The
1619 * userspace code converted context=blah to just blah so we are
1620 * converting back to the full string selinux understands.
1621 */
1622 if (data->context[0]){
1623#ifdef CONFIG_SECURITY_SELINUX
1624 int rc;
1625 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1626 if (!opts_str)
1627 return -ENOMEM;
1628 strcpy(opts_str, "context=");
1629 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1630 strcat(opts_str, &data->context[0]);
1631 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1632 kfree(opts_str);
1633 if (rc)
1634 return rc;
1635#else
1636 return -EINVAL;
1637#endif
1638 }
1639
Chuck Lever5df36e72007-07-01 12:12:56 -04001640 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001641 default: {
Chuck Lever136d5582007-07-01 12:13:54 -04001642 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001643
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001644 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001645 return -EINVAL;
1646
Chuck Lever6e88e062007-09-24 15:39:50 -04001647 if (!nfs_verify_server_address((struct sockaddr *)
1648 &args->nfs_server.address))
1649 goto out_no_address;
1650
Chuck Levered596a82008-06-26 17:47:05 -04001651 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1652 args->nfs_server.port);
1653
Trond Myklebust259875e2008-07-02 14:43:47 -04001654 nfs_set_mount_transport_protocol(args);
1655
Chuck Leverdc045892008-06-23 12:36:37 -04001656 status = nfs_parse_devname(dev_name,
1657 &args->nfs_server.hostname,
1658 PAGE_SIZE,
1659 &args->nfs_server.export_path,
1660 NFS_MAXPATHLEN);
1661 if (!status)
1662 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001663
Chuck Leverdc045892008-06-23 12:36:37 -04001664 kfree(args->nfs_server.export_path);
1665 args->nfs_server.export_path = NULL;
Chuck Lever136d5582007-07-01 12:13:54 -04001666
Chuck Lever136d5582007-07-01 12:13:54 -04001667 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001668 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001669
Chuck Lever136d5582007-07-01 12:13:54 -04001670 break;
1671 }
David Howellsf7b422b2006-06-09 09:34:33 -04001672 }
David Howells54ceac42006-08-22 20:06:13 -04001673
David Howellsf7b422b2006-06-09 09:34:33 -04001674#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001675 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001676 goto out_v3_not_compiled;
1677#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001678
David Howells54ceac42006-08-22 20:06:13 -04001679 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001680
1681out_no_data:
1682 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1683 return -EINVAL;
1684
1685out_no_v3:
1686 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1687 data->version);
1688 return -EINVAL;
1689
1690out_no_sec:
1691 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1692 return -EINVAL;
1693
Chuck Lever5df36e72007-07-01 12:12:56 -04001694#ifndef CONFIG_NFS_V3
1695out_v3_not_compiled:
1696 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1697 return -EPROTONOSUPPORT;
1698#endif /* !CONFIG_NFS_V3 */
1699
Cyrill Gorcunov63649bd2008-04-17 20:42:09 +04001700out_nomem:
1701 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1702 return -ENOMEM;
1703
Chuck Lever5df36e72007-07-01 12:12:56 -04001704out_no_address:
1705 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1706 return -EINVAL;
1707
1708out_invalid_fh:
1709 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1710 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001711}
1712
Jeff Layton48b605f2008-06-10 15:38:39 -04001713static int
1714nfs_compare_remount_data(struct nfs_server *nfss,
1715 struct nfs_parsed_mount_data *data)
1716{
1717 if (data->flags != nfss->flags ||
1718 data->rsize != nfss->rsize ||
1719 data->wsize != nfss->wsize ||
1720 data->retrans != nfss->client->cl_timeout->to_retries ||
1721 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1722 data->acregmin != nfss->acregmin / HZ ||
1723 data->acregmax != nfss->acregmax / HZ ||
1724 data->acdirmin != nfss->acdirmin / HZ ||
1725 data->acdirmax != nfss->acdirmax / HZ ||
1726 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1727 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1728 memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1729 data->nfs_server.addrlen) != 0)
1730 return -EINVAL;
1731
1732 return 0;
1733}
1734
1735static int
1736nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1737{
1738 int error;
1739 struct nfs_server *nfss = sb->s_fs_info;
1740 struct nfs_parsed_mount_data *data;
1741 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1742 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
Trond Myklebustcd100722008-06-17 16:12:00 -04001743 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
Jeff Layton48b605f2008-06-10 15:38:39 -04001744
1745 /*
1746 * Userspace mount programs that send binary options generally send
1747 * them populated with default values. We have no way to know which
1748 * ones were explicitly specified. Fall back to legacy behavior and
1749 * just return success.
1750 */
Marc Zyngier31c94462008-07-17 13:21:55 +02001751 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1752 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1753 options->version <= 6))))
Jeff Layton48b605f2008-06-10 15:38:39 -04001754 return 0;
1755
1756 data = kzalloc(sizeof(*data), GFP_KERNEL);
1757 if (data == NULL)
1758 return -ENOMEM;
1759
1760 /* fill out struct with values from existing mount */
1761 data->flags = nfss->flags;
1762 data->rsize = nfss->rsize;
1763 data->wsize = nfss->wsize;
1764 data->retrans = nfss->client->cl_timeout->to_retries;
1765 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1766 data->acregmin = nfss->acregmin / HZ;
1767 data->acregmax = nfss->acregmax / HZ;
1768 data->acdirmin = nfss->acdirmin / HZ;
1769 data->acdirmax = nfss->acdirmax / HZ;
1770 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1771 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1772 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1773 data->nfs_server.addrlen);
1774
1775 /* overwrite those values with any that were specified */
1776 error = nfs_parse_mount_options((char *)options, data);
1777 if (error < 0)
1778 goto out;
1779
1780 /* compare new mount options with old ones */
1781 error = nfs_compare_remount_data(nfss, data);
1782out:
1783 kfree(data);
1784 return error;
1785}
1786
David Howells54ceac42006-08-22 20:06:13 -04001787/*
1788 * Initialise the common bits of the superblock
1789 */
1790static inline void nfs_initialise_sb(struct super_block *sb)
1791{
1792 struct nfs_server *server = NFS_SB(sb);
1793
1794 sb->s_magic = NFS_SUPER_MAGIC;
1795
1796 /* We probably want something more informative here */
1797 snprintf(sb->s_id, sizeof(sb->s_id),
1798 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1799
1800 if (sb->s_blocksize == 0)
1801 sb->s_blocksize = nfs_block_bits(server->wsize,
1802 &sb->s_blocksize_bits);
1803
1804 if (server->flags & NFS_MOUNT_NOAC)
1805 sb->s_flags |= MS_SYNCHRONOUS;
1806
1807 nfs_super_set_maxbytes(sb, server->maxfilesize);
1808}
1809
1810/*
1811 * Finish setting up an NFS2/3 superblock
1812 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001813static void nfs_fill_super(struct super_block *sb,
1814 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001815{
1816 struct nfs_server *server = NFS_SB(sb);
1817
1818 sb->s_blocksize_bits = 0;
1819 sb->s_blocksize = 0;
1820 if (data->bsize)
1821 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1822
1823 if (server->flags & NFS_MOUNT_VER3) {
1824 /* The VFS shouldn't apply the umask to mode bits. We will do
1825 * so ourselves when necessary.
1826 */
1827 sb->s_flags |= MS_POSIXACL;
1828 sb->s_time_gran = 1;
1829 }
1830
1831 sb->s_op = &nfs_sops;
1832 nfs_initialise_sb(sb);
1833}
1834
1835/*
1836 * Finish setting up a cloned NFS2/3 superblock
1837 */
1838static void nfs_clone_super(struct super_block *sb,
1839 const struct super_block *old_sb)
1840{
1841 struct nfs_server *server = NFS_SB(sb);
1842
1843 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1844 sb->s_blocksize = old_sb->s_blocksize;
1845 sb->s_maxbytes = old_sb->s_maxbytes;
1846
1847 if (server->flags & NFS_MOUNT_VER3) {
1848 /* The VFS shouldn't apply the umask to mode bits. We will do
1849 * so ourselves when necessary.
1850 */
1851 sb->s_flags |= MS_POSIXACL;
1852 sb->s_time_gran = 1;
1853 }
1854
1855 sb->s_op = old_sb->s_op;
1856 nfs_initialise_sb(sb);
1857}
1858
Trond Myklebust275a5d22007-05-16 16:53:28 -04001859#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1860
1861static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1862{
1863 const struct nfs_server *a = s->s_fs_info;
1864 const struct rpc_clnt *clnt_a = a->client;
1865 const struct rpc_clnt *clnt_b = b->client;
1866
1867 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1868 goto Ebusy;
1869 if (a->nfs_client != b->nfs_client)
1870 goto Ebusy;
1871 if (a->flags != b->flags)
1872 goto Ebusy;
1873 if (a->wsize != b->wsize)
1874 goto Ebusy;
1875 if (a->rsize != b->rsize)
1876 goto Ebusy;
1877 if (a->acregmin != b->acregmin)
1878 goto Ebusy;
1879 if (a->acregmax != b->acregmax)
1880 goto Ebusy;
1881 if (a->acdirmin != b->acdirmin)
1882 goto Ebusy;
1883 if (a->acdirmax != b->acdirmax)
1884 goto Ebusy;
1885 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1886 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001887 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001888Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001889 return 0;
1890}
1891
1892struct nfs_sb_mountdata {
1893 struct nfs_server *server;
1894 int mntflags;
1895};
1896
1897static int nfs_set_super(struct super_block *s, void *data)
1898{
1899 struct nfs_sb_mountdata *sb_mntdata = data;
1900 struct nfs_server *server = sb_mntdata->server;
1901 int ret;
1902
1903 s->s_flags = sb_mntdata->mntflags;
1904 s->s_fs_info = server;
1905 ret = set_anon_super(s, server);
1906 if (ret == 0)
1907 server->s_dev = s->s_dev;
1908 return ret;
1909}
1910
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001911static int nfs_compare_super_address(struct nfs_server *server1,
1912 struct nfs_server *server2)
1913{
1914 struct sockaddr *sap1, *sap2;
1915
1916 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1917 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1918
1919 if (sap1->sa_family != sap2->sa_family)
1920 return 0;
1921
1922 switch (sap1->sa_family) {
1923 case AF_INET: {
1924 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1925 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1926 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1927 return 0;
1928 if (sin1->sin_port != sin2->sin_port)
1929 return 0;
1930 break;
1931 }
1932 case AF_INET6: {
1933 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1934 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1935 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1936 return 0;
1937 if (sin1->sin6_port != sin2->sin6_port)
1938 return 0;
1939 break;
1940 }
1941 default:
1942 return 0;
1943 }
1944
1945 return 1;
1946}
1947
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001948static int nfs_compare_super(struct super_block *sb, void *data)
1949{
1950 struct nfs_sb_mountdata *sb_mntdata = data;
1951 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1952 int mntflags = sb_mntdata->mntflags;
1953
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001954 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001955 return 0;
1956 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1957 if (old->flags & NFS_MOUNT_UNSHARED)
1958 return 0;
1959 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1960 return 0;
1961 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001962}
1963
Miklos Szeredifa799752008-04-30 00:54:33 -07001964static int nfs_bdi_register(struct nfs_server *server)
1965{
1966 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1967}
1968
David Howells54ceac42006-08-22 20:06:13 -04001969static int nfs_get_sb(struct file_system_type *fs_type,
1970 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1971{
1972 struct nfs_server *server = NULL;
1973 struct super_block *s;
Trond Myklebust33852a12008-06-19 14:20:11 -04001974 struct nfs_parsed_mount_data *data;
1975 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04001976 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001977 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001978 struct nfs_sb_mountdata sb_mntdata = {
1979 .mntflags = flags,
1980 };
Trond Myklebust33852a12008-06-19 14:20:11 -04001981 int error = -ENOMEM;
David Howells54ceac42006-08-22 20:06:13 -04001982
Trond Myklebust33852a12008-06-19 14:20:11 -04001983 data = kzalloc(sizeof(*data), GFP_KERNEL);
1984 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1985 if (data == NULL || mntfh == NULL)
1986 goto out_free_fh;
1987
1988 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05001989
David Howells54ceac42006-08-22 20:06:13 -04001990 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04001991 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001992 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001993 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001994
1995 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04001996 server = nfs_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001997 if (IS_ERR(server)) {
1998 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001999 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002000 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002001 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002002
Trond Myklebust75180df2007-05-16 16:53:28 -04002003 if (server->flags & NFS_MOUNT_UNSHARED)
2004 compare_super = NULL;
2005
David Howells54ceac42006-08-22 20:06:13 -04002006 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002007 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002008 if (IS_ERR(s)) {
2009 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04002010 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04002011 }
2012
David Howells54ceac42006-08-22 20:06:13 -04002013 if (s->s_fs_info != server) {
2014 nfs_free_server(server);
2015 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002016 } else {
2017 error = nfs_bdi_register(server);
2018 if (error)
2019 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002020 }
David Howells54ceac42006-08-22 20:06:13 -04002021
2022 if (!s->s_root) {
2023 /* initial superblock/root creation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002024 nfs_fill_super(s, data);
David Howells54ceac42006-08-22 20:06:13 -04002025 }
2026
Trond Myklebust33852a12008-06-19 14:20:11 -04002027 mntroot = nfs_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002028 if (IS_ERR(mntroot)) {
2029 error = PTR_ERR(mntroot);
2030 goto error_splat_super;
2031 }
2032
Trond Myklebust33852a12008-06-19 14:20:11 -04002033 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002034 if (error)
2035 goto error_splat_root;
2036
David Howellsf7b422b2006-06-09 09:34:33 -04002037 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002038 mnt->mnt_sb = s;
2039 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04002040 error = 0;
2041
2042out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002043 kfree(data->nfs_server.hostname);
2044 kfree(data->mount_server.hostname);
2045 security_free_mnt_opts(&data->lsm_opts);
2046out_free_fh:
2047 kfree(mntfh);
2048 kfree(data);
Chuck Lever06559602007-07-01 12:12:35 -04002049 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04002050
David Howells54ceac42006-08-22 20:06:13 -04002051out_err_nosb:
2052 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04002053 goto out;
David Howells54ceac42006-08-22 20:06:13 -04002054
Eric Parisf9c3a382008-03-05 14:20:18 -05002055error_splat_root:
2056 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002057error_splat_super:
2058 up_write(&s->s_umount);
2059 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04002060 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002061}
2062
David Howells54ceac42006-08-22 20:06:13 -04002063/*
2064 * Destroy an NFS2/3 superblock
2065 */
David Howellsf7b422b2006-06-09 09:34:33 -04002066static void nfs_kill_super(struct super_block *s)
2067{
2068 struct nfs_server *server = NFS_SB(s);
2069
Miklos Szeredifa799752008-04-30 00:54:33 -07002070 bdi_unregister(&server->backing_dev_info);
David Howellsf7b422b2006-06-09 09:34:33 -04002071 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04002072 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002073}
2074
David Howells54ceac42006-08-22 20:06:13 -04002075/*
2076 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2077 */
2078static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2079 const char *dev_name, void *raw_data,
2080 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002081{
2082 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002083 struct super_block *s;
2084 struct nfs_server *server;
2085 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002086 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002087 struct nfs_sb_mountdata sb_mntdata = {
2088 .mntflags = flags,
2089 };
David Howells54ceac42006-08-22 20:06:13 -04002090 int error;
2091
2092 dprintk("--> nfs_xdev_get_sb()\n");
2093
2094 /* create a new volume representation */
2095 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2096 if (IS_ERR(server)) {
2097 error = PTR_ERR(server);
2098 goto out_err_noserver;
2099 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002100 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002101
Trond Myklebust75180df2007-05-16 16:53:28 -04002102 if (server->flags & NFS_MOUNT_UNSHARED)
2103 compare_super = NULL;
2104
David Howells54ceac42006-08-22 20:06:13 -04002105 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002106 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002107 if (IS_ERR(s)) {
2108 error = PTR_ERR(s);
2109 goto out_err_nosb;
2110 }
2111
2112 if (s->s_fs_info != server) {
2113 nfs_free_server(server);
2114 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002115 } else {
2116 error = nfs_bdi_register(server);
2117 if (error)
2118 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002119 }
2120
2121 if (!s->s_root) {
2122 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002123 nfs_clone_super(s, data->sb);
2124 }
2125
2126 mntroot = nfs_get_root(s, data->fh);
2127 if (IS_ERR(mntroot)) {
2128 error = PTR_ERR(mntroot);
2129 goto error_splat_super;
2130 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002131 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11002132 dput(mntroot);
2133 error = -ESTALE;
2134 goto error_splat_super;
2135 }
David Howells54ceac42006-08-22 20:06:13 -04002136
2137 s->s_flags |= MS_ACTIVE;
2138 mnt->mnt_sb = s;
2139 mnt->mnt_root = mntroot;
2140
Eric Parisf9c3a382008-03-05 14:20:18 -05002141 /* clone any lsm security options from the parent to the new sb */
2142 security_sb_clone_mnt_opts(data->sb, s);
2143
David Howells54ceac42006-08-22 20:06:13 -04002144 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2145 return 0;
2146
2147out_err_nosb:
2148 nfs_free_server(server);
2149out_err_noserver:
2150 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2151 return error;
2152
2153error_splat_super:
2154 up_write(&s->s_umount);
2155 deactivate_super(s);
2156 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2157 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002158}
2159
2160#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04002161
2162/*
2163 * Finish setting up a cloned NFS4 superblock
2164 */
2165static void nfs4_clone_super(struct super_block *sb,
2166 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002167{
David Howells54ceac42006-08-22 20:06:13 -04002168 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2169 sb->s_blocksize = old_sb->s_blocksize;
2170 sb->s_maxbytes = old_sb->s_maxbytes;
2171 sb->s_time_gran = 1;
2172 sb->s_op = old_sb->s_op;
2173 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002174}
2175
2176/*
2177 * Set up an NFS4 superblock
2178 */
David Howells54ceac42006-08-22 20:06:13 -04002179static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04002180{
David Howellsf7b422b2006-06-09 09:34:33 -04002181 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04002182 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04002183 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04002184}
2185
David Howells54ceac42006-08-22 20:06:13 -04002186/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04002187 * Validate NFSv4 mount options
2188 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002189static int nfs4_validate_mount_data(void *options,
2190 struct nfs_parsed_mount_data *args,
2191 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04002192{
Chuck Lever4c568012007-12-10 14:59:28 -05002193 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002194 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002195 char *c;
2196
2197 if (data == NULL)
2198 goto out_no_data;
2199
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002200 args->rsize = NFS_MAX_FILE_IO_SIZE;
2201 args->wsize = NFS_MAX_FILE_IO_SIZE;
Chuck Lever0e0cab72008-06-26 17:47:12 -04002202 args->acregmin = NFS_DEF_ACREGMIN;
2203 args->acregmax = NFS_DEF_ACREGMAX;
2204 args->acdirmin = NFS_DEF_ACDIRMIN;
2205 args->acdirmax = NFS_DEF_ACDIRMAX;
Chuck Leverf22d6d72008-03-14 14:10:22 -04002206 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
Chuck Lever6738b252008-06-24 16:33:54 -04002207 args->auth_flavors[0] = RPC_AUTH_UNIX;
2208 args->auth_flavor_len = 0;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002209
Chuck Leverf0768eb2007-07-01 12:13:01 -04002210 switch (data->version) {
2211 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05002212 ap = (struct sockaddr_in *)&args->nfs_server.address;
2213 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002214 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05002215 if (data->host_addrlen == 0)
2216 goto out_no_address;
2217 args->nfs_server.addrlen = data->host_addrlen;
2218 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002219 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002220 if (!nfs_verify_server_address((struct sockaddr *)
2221 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002222 goto out_no_address;
2223
Chuck Lever6738b252008-06-24 16:33:54 -04002224 if (data->auth_flavourlen) {
2225 if (data->auth_flavourlen > 1)
2226 goto out_inval_auth;
Trond Myklebust20c71f52007-09-20 20:23:51 -04002227 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002228 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04002229 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04002230 return -EFAULT;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002231 }
2232
2233 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2234 if (IS_ERR(c))
2235 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002236 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002237
2238 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2239 if (IS_ERR(c))
2240 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002241 args->nfs_server.export_path = c;
2242 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002243
2244 c = strndup_user(data->client_addr.data, 16);
2245 if (IS_ERR(c))
2246 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002247 args->client_address = c;
2248
2249 /*
2250 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2251 * can deal with.
2252 */
2253
2254 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2255 args->rsize = data->rsize;
2256 args->wsize = data->wsize;
2257 args->timeo = data->timeo;
2258 args->retrans = data->retrans;
2259 args->acregmin = data->acregmin;
2260 args->acregmax = data->acregmax;
2261 args->acdirmin = data->acdirmin;
2262 args->acdirmax = data->acdirmax;
2263 args->nfs_server.protocol = data->proto;
Trond Myklebust259875e2008-07-02 14:43:47 -04002264 nfs_validate_transport_protocol(args);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002265
2266 break;
Chuck Lever80071222007-07-01 12:13:59 -04002267 default: {
Chuck Leverdc045892008-06-23 12:36:37 -04002268 int status;
Chuck Lever80071222007-07-01 12:13:59 -04002269
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002270 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04002271 return -EINVAL;
2272
2273 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002274 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04002275 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04002276
Chuck Levered596a82008-06-26 17:47:05 -04002277 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2278 args->nfs_server.port);
2279
Trond Myklebust259875e2008-07-02 14:43:47 -04002280 nfs_validate_transport_protocol(args);
2281
Chuck Lever6738b252008-06-24 16:33:54 -04002282 if (args->auth_flavor_len > 1)
Chuck Lever80071222007-07-01 12:13:59 -04002283 goto out_inval_auth;
Chuck Lever80071222007-07-01 12:13:59 -04002284
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04002285 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04002286 goto out_no_client_address;
2287
Chuck Leverdc045892008-06-23 12:36:37 -04002288 status = nfs_parse_devname(dev_name,
2289 &args->nfs_server.hostname,
2290 NFS4_MAXNAMLEN,
2291 &args->nfs_server.export_path,
2292 NFS4_MAXPATHLEN);
2293 if (status < 0)
2294 return status;
2295
Chuck Lever80071222007-07-01 12:13:59 -04002296 break;
2297 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04002298 }
2299
2300 return 0;
2301
2302out_no_data:
2303 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2304 return -EINVAL;
2305
2306out_inval_auth:
2307 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2308 data->auth_flavourlen);
2309 return -EINVAL;
2310
2311out_no_address:
2312 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2313 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04002314
2315out_no_client_address:
2316 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2317 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04002318}
2319
2320/*
David Howells54ceac42006-08-22 20:06:13 -04002321 * Get the superblock for an NFS4 mountpoint
2322 */
Trond Myklebust816724e2006-06-24 08:41:41 -04002323static int nfs4_get_sb(struct file_system_type *fs_type,
2324 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002325{
Trond Myklebust33852a12008-06-19 14:20:11 -04002326 struct nfs_parsed_mount_data *data;
David Howells54ceac42006-08-22 20:06:13 -04002327 struct super_block *s;
2328 struct nfs_server *server;
Trond Myklebust33852a12008-06-19 14:20:11 -04002329 struct nfs_fh *mntfh;
David Howells54ceac42006-08-22 20:06:13 -04002330 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002331 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002332 struct nfs_sb_mountdata sb_mntdata = {
2333 .mntflags = flags,
2334 };
Trond Myklebust33852a12008-06-19 14:20:11 -04002335 int error = -ENOMEM;
David Howellsf7b422b2006-06-09 09:34:33 -04002336
Trond Myklebust33852a12008-06-19 14:20:11 -04002337 data = kzalloc(sizeof(*data), GFP_KERNEL);
2338 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2339 if (data == NULL || mntfh == NULL)
2340 goto out_free_fh;
2341
2342 security_init_mnt_opts(&data->lsm_opts);
Eric Parisf9c3a382008-03-05 14:20:18 -05002343
Chuck Leverf0768eb2007-07-01 12:13:01 -04002344 /* Validate the mount data */
Trond Myklebust33852a12008-06-19 14:20:11 -04002345 error = nfs4_validate_mount_data(raw_data, data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04002346 if (error < 0)
2347 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002348
David Howells54ceac42006-08-22 20:06:13 -04002349 /* Get a volume representation */
Trond Myklebust33852a12008-06-19 14:20:11 -04002350 server = nfs4_create_server(data, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002351 if (IS_ERR(server)) {
2352 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04002353 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002354 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002355 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04002356
Trond Myklebust75180df2007-05-16 16:53:28 -04002357 if (server->flags & NFS4_MOUNT_UNSHARED)
2358 compare_super = NULL;
2359
David Howells54ceac42006-08-22 20:06:13 -04002360 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002361 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04002362 if (IS_ERR(s)) {
2363 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04002364 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04002365 }
2366
Trond Myklebust5dd31772006-08-24 01:03:05 -04002367 if (s->s_fs_info != server) {
2368 nfs_free_server(server);
2369 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002370 } else {
2371 error = nfs_bdi_register(server);
2372 if (error)
2373 goto error_splat_super;
Trond Myklebust5dd31772006-08-24 01:03:05 -04002374 }
2375
David Howells54ceac42006-08-22 20:06:13 -04002376 if (!s->s_root) {
2377 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002378 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04002379 }
David Howellsf7b422b2006-06-09 09:34:33 -04002380
Trond Myklebust33852a12008-06-19 14:20:11 -04002381 mntroot = nfs4_get_root(s, mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002382 if (IS_ERR(mntroot)) {
2383 error = PTR_ERR(mntroot);
2384 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04002385 }
David Howells54ceac42006-08-22 20:06:13 -04002386
Trond Myklebust33852a12008-06-19 14:20:11 -04002387 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
Eric Paris46c8ac72008-05-02 13:42:42 -07002388 if (error)
2389 goto error_splat_root;
2390
David Howellsf7b422b2006-06-09 09:34:33 -04002391 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04002392 mnt->mnt_sb = s;
2393 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04002394 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04002395
Chuck Lever29eb9812007-07-01 12:12:30 -04002396out:
Trond Myklebust33852a12008-06-19 14:20:11 -04002397 kfree(data->client_address);
2398 kfree(data->nfs_server.export_path);
2399 kfree(data->nfs_server.hostname);
2400 security_free_mnt_opts(&data->lsm_opts);
2401out_free_fh:
2402 kfree(mntfh);
2403 kfree(data);
Trond Myklebust816724e2006-06-24 08:41:41 -04002404 return error;
David Howells54ceac42006-08-22 20:06:13 -04002405
Chuck Lever29eb9812007-07-01 12:12:30 -04002406out_free:
2407 nfs_free_server(server);
2408 goto out;
2409
Eric Paris46c8ac72008-05-02 13:42:42 -07002410error_splat_root:
2411 dput(mntroot);
David Howells54ceac42006-08-22 20:06:13 -04002412error_splat_super:
2413 up_write(&s->s_umount);
2414 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04002415 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04002416}
2417
2418static void nfs4_kill_super(struct super_block *sb)
2419{
2420 struct nfs_server *server = NFS_SB(sb);
2421
2422 nfs_return_all_delegations(sb);
2423 kill_anon_super(sb);
2424
2425 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04002426 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04002427}
2428
2429/*
David Howells54ceac42006-08-22 20:06:13 -04002430 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04002431 */
David Howells54ceac42006-08-22 20:06:13 -04002432static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2433 const char *dev_name, void *raw_data,
2434 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002435{
2436 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002437 struct super_block *s;
2438 struct nfs_server *server;
2439 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04002440 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002441 struct nfs_sb_mountdata sb_mntdata = {
2442 .mntflags = flags,
2443 };
David Howells54ceac42006-08-22 20:06:13 -04002444 int error;
2445
2446 dprintk("--> nfs4_xdev_get_sb()\n");
2447
2448 /* create a new volume representation */
2449 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2450 if (IS_ERR(server)) {
2451 error = PTR_ERR(server);
2452 goto out_err_noserver;
2453 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002454 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002455
Trond Myklebust75180df2007-05-16 16:53:28 -04002456 if (server->flags & NFS4_MOUNT_UNSHARED)
2457 compare_super = NULL;
2458
David Howells54ceac42006-08-22 20:06:13 -04002459 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002460 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002461 if (IS_ERR(s)) {
2462 error = PTR_ERR(s);
2463 goto out_err_nosb;
2464 }
2465
2466 if (s->s_fs_info != server) {
2467 nfs_free_server(server);
2468 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002469 } else {
2470 error = nfs_bdi_register(server);
2471 if (error)
2472 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002473 }
2474
2475 if (!s->s_root) {
2476 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002477 nfs4_clone_super(s, data->sb);
2478 }
2479
2480 mntroot = nfs4_get_root(s, data->fh);
2481 if (IS_ERR(mntroot)) {
2482 error = PTR_ERR(mntroot);
2483 goto error_splat_super;
2484 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002485 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2486 dput(mntroot);
2487 error = -ESTALE;
2488 goto error_splat_super;
2489 }
David Howells54ceac42006-08-22 20:06:13 -04002490
2491 s->s_flags |= MS_ACTIVE;
2492 mnt->mnt_sb = s;
2493 mnt->mnt_root = mntroot;
2494
Eric Paris46c8ac72008-05-02 13:42:42 -07002495 security_sb_clone_mnt_opts(data->sb, s);
2496
David Howells54ceac42006-08-22 20:06:13 -04002497 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2498 return 0;
2499
2500out_err_nosb:
2501 nfs_free_server(server);
2502out_err_noserver:
2503 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2504 return error;
2505
2506error_splat_super:
2507 up_write(&s->s_umount);
2508 deactivate_super(s);
2509 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2510 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002511}
2512
David Howells54ceac42006-08-22 20:06:13 -04002513/*
2514 * Create an NFS4 server record on referral traversal
2515 */
2516static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2517 const char *dev_name, void *raw_data,
2518 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002519{
2520 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002521 struct super_block *s;
2522 struct nfs_server *server;
2523 struct dentry *mntroot;
2524 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002525 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002526 struct nfs_sb_mountdata sb_mntdata = {
2527 .mntflags = flags,
2528 };
David Howells54ceac42006-08-22 20:06:13 -04002529 int error;
2530
2531 dprintk("--> nfs4_referral_get_sb()\n");
2532
2533 /* create a new volume representation */
2534 server = nfs4_create_referral_server(data, &mntfh);
2535 if (IS_ERR(server)) {
2536 error = PTR_ERR(server);
2537 goto out_err_noserver;
2538 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002539 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002540
Trond Myklebust75180df2007-05-16 16:53:28 -04002541 if (server->flags & NFS4_MOUNT_UNSHARED)
2542 compare_super = NULL;
2543
David Howells54ceac42006-08-22 20:06:13 -04002544 /* Get a superblock - note that we may end up sharing one that already exists */
Andy Adamsonec9a05c2008-10-17 10:44:37 -04002545 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002546 if (IS_ERR(s)) {
2547 error = PTR_ERR(s);
2548 goto out_err_nosb;
2549 }
2550
2551 if (s->s_fs_info != server) {
2552 nfs_free_server(server);
2553 server = NULL;
Miklos Szeredifa799752008-04-30 00:54:33 -07002554 } else {
2555 error = nfs_bdi_register(server);
2556 if (error)
2557 goto error_splat_super;
David Howells54ceac42006-08-22 20:06:13 -04002558 }
2559
2560 if (!s->s_root) {
2561 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002562 nfs4_fill_super(s);
2563 }
2564
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002565 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002566 if (IS_ERR(mntroot)) {
2567 error = PTR_ERR(mntroot);
2568 goto error_splat_super;
2569 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002570 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2571 dput(mntroot);
2572 error = -ESTALE;
2573 goto error_splat_super;
2574 }
David Howells54ceac42006-08-22 20:06:13 -04002575
2576 s->s_flags |= MS_ACTIVE;
2577 mnt->mnt_sb = s;
2578 mnt->mnt_root = mntroot;
2579
Eric Paris46c8ac72008-05-02 13:42:42 -07002580 security_sb_clone_mnt_opts(data->sb, s);
2581
David Howells54ceac42006-08-22 20:06:13 -04002582 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2583 return 0;
2584
2585out_err_nosb:
2586 nfs_free_server(server);
2587out_err_noserver:
2588 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2589 return error;
2590
2591error_splat_super:
2592 up_write(&s->s_umount);
2593 deactivate_super(s);
2594 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2595 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002596}
2597
David Howells54ceac42006-08-22 20:06:13 -04002598#endif /* CONFIG_NFS_V4 */