blob: 7f4505f6ac6f55fd49c1a8c07bbb65ce63d41388 [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * linux/fs/nfs/super.c
3 *
4 * Copyright (C) 1992 Rick Sladkey
5 *
6 * nfs superblock handling functions
7 *
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
10 *
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
13 *
14 * Split from inode.c by David Howells <dhowells@redhat.com>
15 *
David Howells54ceac42006-08-22 20:06:13 -040016 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
David Howellsf7b422b2006-06-09 09:34:33 -040021 */
22
David Howellsf7b422b2006-06-09 09:34:33 -040023#include <linux/module.h>
24#include <linux/init.h>
25
26#include <linux/time.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/string.h>
30#include <linux/stat.h>
31#include <linux/errno.h>
32#include <linux/unistd.h>
33#include <linux/sunrpc/clnt.h>
34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/metrics.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040036#include <linux/sunrpc/xprtsock.h>
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040037#include <linux/sunrpc/xprtrdma.h>
David Howellsf7b422b2006-06-09 09:34:33 -040038#include <linux/nfs_fs.h>
39#include <linux/nfs_mount.h>
40#include <linux/nfs4_mount.h>
41#include <linux/lockd/bind.h>
42#include <linux/smp_lock.h>
43#include <linux/seq_file.h>
44#include <linux/mount.h>
45#include <linux/nfs_idmap.h>
46#include <linux/vfs.h>
47#include <linux/inet.h>
Chuck Leverfd00a8f2007-12-10 14:57:38 -050048#include <linux/in6.h>
49#include <net/ipv6.h>
David Howellsf7b422b2006-06-09 09:34:33 -040050#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080051#include <linux/magic.h>
Chuck Leverbf0fd762007-07-01 12:13:44 -040052#include <linux/parser.h>
David Howellsf7b422b2006-06-09 09:34:33 -040053
54#include <asm/system.h>
55#include <asm/uaccess.h>
56
57#include "nfs4_fs.h"
58#include "callback.h"
59#include "delegation.h"
60#include "iostat.h"
61#include "internal.h"
62
63#define NFSDBG_FACILITY NFSDBG_VFS
64
Chuck Leverbf0fd762007-07-01 12:13:44 -040065enum {
66 /* Mount options that take no arguments */
67 Opt_soft, Opt_hard,
68 Opt_intr, Opt_nointr,
69 Opt_posix, Opt_noposix,
70 Opt_cto, Opt_nocto,
71 Opt_ac, Opt_noac,
72 Opt_lock, Opt_nolock,
73 Opt_v2, Opt_v3,
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -040074 Opt_udp, Opt_tcp, Opt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -040075 Opt_acl, Opt_noacl,
76 Opt_rdirplus, Opt_nordirplus,
Trond Myklebust75180df2007-05-16 16:53:28 -040077 Opt_sharecache, Opt_nosharecache,
Chuck Leverbf0fd762007-07-01 12:13:44 -040078
79 /* Mount options that take integer arguments */
80 Opt_port,
81 Opt_rsize, Opt_wsize, Opt_bsize,
82 Opt_timeo, Opt_retrans,
83 Opt_acregmin, Opt_acregmax,
84 Opt_acdirmin, Opt_acdirmax,
85 Opt_actimeo,
86 Opt_namelen,
87 Opt_mountport,
Chuck Levere887cbc2007-10-26 13:32:29 -040088 Opt_mountvers,
Chuck Leverad879ce2007-10-26 13:32:24 -040089 Opt_nfsvers,
Chuck Leverbf0fd762007-07-01 12:13:44 -040090
91 /* Mount options that take string arguments */
Chuck Lever33832032007-12-10 14:59:13 -050092 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
Chuck Lever0ac83772007-09-11 18:01:04 -040093 Opt_addr, Opt_mountaddr, Opt_clientaddr,
Chuck Leverbf0fd762007-07-01 12:13:44 -040094
95 /* Mount options that are ignored */
96 Opt_userspace, Opt_deprecated,
97
98 Opt_err
99};
100
101static match_table_t nfs_mount_option_tokens = {
102 { Opt_userspace, "bg" },
103 { Opt_userspace, "fg" },
104 { Opt_soft, "soft" },
105 { Opt_hard, "hard" },
106 { Opt_intr, "intr" },
107 { Opt_nointr, "nointr" },
108 { Opt_posix, "posix" },
109 { Opt_noposix, "noposix" },
110 { Opt_cto, "cto" },
111 { Opt_nocto, "nocto" },
112 { Opt_ac, "ac" },
113 { Opt_noac, "noac" },
114 { Opt_lock, "lock" },
115 { Opt_nolock, "nolock" },
116 { Opt_v2, "v2" },
117 { Opt_v3, "v3" },
118 { Opt_udp, "udp" },
119 { Opt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400120 { Opt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400121 { Opt_acl, "acl" },
122 { Opt_noacl, "noacl" },
123 { Opt_rdirplus, "rdirplus" },
124 { Opt_nordirplus, "nordirplus" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400125 { Opt_sharecache, "sharecache" },
126 { Opt_nosharecache, "nosharecache" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400127
128 { Opt_port, "port=%u" },
129 { Opt_rsize, "rsize=%u" },
130 { Opt_wsize, "wsize=%u" },
131 { Opt_bsize, "bsize=%u" },
132 { Opt_timeo, "timeo=%u" },
133 { Opt_retrans, "retrans=%u" },
134 { Opt_acregmin, "acregmin=%u" },
135 { Opt_acregmax, "acregmax=%u" },
136 { Opt_acdirmin, "acdirmin=%u" },
137 { Opt_acdirmax, "acdirmax=%u" },
138 { Opt_actimeo, "actimeo=%u" },
139 { Opt_userspace, "retry=%u" },
140 { Opt_namelen, "namlen=%u" },
141 { Opt_mountport, "mountport=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400142 { Opt_mountvers, "mountvers=%u" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400143 { Opt_nfsvers, "nfsvers=%u" },
144 { Opt_nfsvers, "vers=%u" },
145
146 { Opt_sec, "sec=%s" },
147 { Opt_proto, "proto=%s" },
148 { Opt_mountproto, "mountproto=%s" },
149 { Opt_addr, "addr=%s" },
150 { Opt_clientaddr, "clientaddr=%s" },
Chuck Lever33832032007-12-10 14:59:13 -0500151 { Opt_mounthost, "mounthost=%s" },
Chuck Lever0ac83772007-09-11 18:01:04 -0400152 { Opt_mountaddr, "mountaddr=%s" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400153
154 { Opt_err, NULL }
155};
156
157enum {
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400158 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
Chuck Leverbf0fd762007-07-01 12:13:44 -0400159
160 Opt_xprt_err
161};
162
163static match_table_t nfs_xprt_protocol_tokens = {
164 { Opt_xprt_udp, "udp" },
165 { Opt_xprt_tcp, "tcp" },
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400166 { Opt_xprt_rdma, "rdma" },
Chuck Leverbf0fd762007-07-01 12:13:44 -0400167
168 { Opt_xprt_err, NULL }
169};
170
171enum {
172 Opt_sec_none, Opt_sec_sys,
173 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
174 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
175 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
176
177 Opt_sec_err
178};
179
180static match_table_t nfs_secflavor_tokens = {
181 { Opt_sec_none, "none" },
182 { Opt_sec_none, "null" },
183 { Opt_sec_sys, "sys" },
184
185 { Opt_sec_krb5, "krb5" },
186 { Opt_sec_krb5i, "krb5i" },
187 { Opt_sec_krb5p, "krb5p" },
188
189 { Opt_sec_lkey, "lkey" },
190 { Opt_sec_lkeyi, "lkeyi" },
191 { Opt_sec_lkeyp, "lkeyp" },
192
193 { Opt_sec_err, NULL }
194};
195
196
David Howellsf7b422b2006-06-09 09:34:33 -0400197static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -0400198static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -0400199static int nfs_show_options(struct seq_file *, struct vfsmount *);
200static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -0400201static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -0400202static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -0400203 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400204static void nfs_kill_super(struct super_block *);
Steve Dicksonef818a22007-11-08 04:05:04 -0500205static void nfs_put_super(struct super_block *);
David Howellsf7b422b2006-06-09 09:34:33 -0400206
207static struct file_system_type nfs_fs_type = {
208 .owner = THIS_MODULE,
209 .name = "nfs",
210 .get_sb = nfs_get_sb,
211 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700212 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400213};
214
David Howells54ceac42006-08-22 20:06:13 -0400215struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400216 .owner = THIS_MODULE,
217 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -0400218 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400219 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700220 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400221};
222
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800223static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400224 .alloc_inode = nfs_alloc_inode,
225 .destroy_inode = nfs_destroy_inode,
226 .write_inode = nfs_write_inode,
Steve Dicksonef818a22007-11-08 04:05:04 -0500227 .put_super = nfs_put_super,
David Howellsf7b422b2006-06-09 09:34:33 -0400228 .statfs = nfs_statfs,
229 .clear_inode = nfs_clear_inode,
230 .umount_begin = nfs_umount_begin,
231 .show_options = nfs_show_options,
232 .show_stats = nfs_show_stats,
233};
234
235#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -0400236static int nfs4_get_sb(struct file_system_type *fs_type,
237 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -0400238static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
239 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
240static int nfs4_referral_get_sb(struct file_system_type *fs_type,
241 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400242static void nfs4_kill_super(struct super_block *sb);
243
244static struct file_system_type nfs4_fs_type = {
245 .owner = THIS_MODULE,
246 .name = "nfs4",
247 .get_sb = nfs4_get_sb,
248 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700249 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400250};
251
David Howells54ceac42006-08-22 20:06:13 -0400252struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400253 .owner = THIS_MODULE,
254 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400255 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400256 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700257 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400258};
259
David Howells54ceac42006-08-22 20:06:13 -0400260struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400261 .owner = THIS_MODULE,
262 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400263 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400264 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700265 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400266};
267
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800268static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400269 .alloc_inode = nfs_alloc_inode,
270 .destroy_inode = nfs_destroy_inode,
271 .write_inode = nfs_write_inode,
272 .statfs = nfs_statfs,
273 .clear_inode = nfs4_clear_inode,
274 .umount_begin = nfs_umount_begin,
275 .show_options = nfs_show_options,
276 .show_stats = nfs_show_stats,
277};
278#endif
279
Rusty Russell8e1f9362007-07-17 04:03:17 -0700280static struct shrinker acl_shrinker = {
281 .shrink = nfs_access_cache_shrinker,
282 .seeks = DEFAULT_SEEKS,
283};
Trond Myklebust979df722006-07-25 11:28:19 -0400284
David Howellsf7b422b2006-06-09 09:34:33 -0400285/*
286 * Register the NFS filesystems
287 */
288int __init register_nfs_fs(void)
289{
290 int ret;
291
292 ret = register_filesystem(&nfs_fs_type);
293 if (ret < 0)
294 goto error_0;
295
David Howellsf7b422b2006-06-09 09:34:33 -0400296 ret = nfs_register_sysctl();
297 if (ret < 0)
298 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800299#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400300 ret = register_filesystem(&nfs4_fs_type);
301 if (ret < 0)
302 goto error_2;
303#endif
Rusty Russell8e1f9362007-07-17 04:03:17 -0700304 register_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400305 return 0;
306
307#ifdef CONFIG_NFS_V4
308error_2:
309 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800310#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400311error_1:
312 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400313error_0:
314 return ret;
315}
316
317/*
318 * Unregister the NFS filesystems
319 */
320void __exit unregister_nfs_fs(void)
321{
Rusty Russell8e1f9362007-07-17 04:03:17 -0700322 unregister_shrinker(&acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400323#ifdef CONFIG_NFS_V4
324 unregister_filesystem(&nfs4_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400325#endif
Alexey Dobriyan49af7ee2007-09-18 22:46:40 -0700326 nfs_unregister_sysctl();
David Howellsf7b422b2006-06-09 09:34:33 -0400327 unregister_filesystem(&nfs_fs_type);
328}
329
Steve Dicksonef818a22007-11-08 04:05:04 -0500330void nfs_sb_active(struct nfs_server *server)
331{
332 atomic_inc(&server->active);
333}
334
335void nfs_sb_deactive(struct nfs_server *server)
336{
337 if (atomic_dec_and_test(&server->active))
338 wake_up(&server->active_wq);
339}
340
341static void nfs_put_super(struct super_block *sb)
342{
343 struct nfs_server *server = NFS_SB(sb);
344 /*
345 * Make sure there are no outstanding ops to this server.
346 * If so, wait for them to finish before allowing the
347 * unmount to continue.
348 */
349 wait_event(server->active_wq, atomic_read(&server->active) == 0);
350}
351
David Howellsf7b422b2006-06-09 09:34:33 -0400352/*
353 * Deliver file system statistics to userspace
354 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400355static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400356{
David Howells0c7d90c2006-08-22 20:06:10 -0400357 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400358 unsigned char blockbits;
359 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400360 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400361 struct nfs_fattr fattr;
362 struct nfs_fsstat res = {
363 .fattr = &fattr,
364 };
365 int error;
366
367 lock_kernel();
368
David Howells8fa5c002006-08-22 20:06:12 -0400369 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400370 if (error < 0)
371 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700372 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400373
374 /*
375 * Current versions of glibc do not correctly handle the
376 * case where f_frsize != f_bsize. Eventually we want to
377 * report the value of wtmult in this field.
378 */
David Howells0c7d90c2006-08-22 20:06:10 -0400379 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400380
381 /*
382 * On most *nix systems, f_blocks, f_bfree, and f_bavail
383 * are reported in units of f_frsize. Linux hasn't had
384 * an f_frsize field in its statfs struct until recently,
385 * thus historically Linux's sys_statfs reports these
386 * fields in units of f_bsize.
387 */
David Howells0c7d90c2006-08-22 20:06:10 -0400388 buf->f_bsize = dentry->d_sb->s_blocksize;
389 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400390 blockres = (1 << blockbits) - 1;
391 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
392 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
393 buf->f_bavail = (res.abytes + blockres) >> blockbits;
394
395 buf->f_files = res.tfiles;
396 buf->f_ffree = res.afiles;
397
398 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700399
David Howellsf7b422b2006-06-09 09:34:33 -0400400 unlock_kernel();
401 return 0;
402
403 out_err:
404 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700405 unlock_kernel();
406 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400407}
408
David Howells7d4e2742006-08-22 20:06:07 -0400409/*
410 * Map the security flavour number to a name
411 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400412static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
413{
David Howells7d4e2742006-08-22 20:06:07 -0400414 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400415 rpc_authflavor_t flavour;
416 const char *str;
417 } sec_flavours[] = {
418 { RPC_AUTH_NULL, "null" },
419 { RPC_AUTH_UNIX, "sys" },
420 { RPC_AUTH_GSS_KRB5, "krb5" },
421 { RPC_AUTH_GSS_KRB5I, "krb5i" },
422 { RPC_AUTH_GSS_KRB5P, "krb5p" },
423 { RPC_AUTH_GSS_LKEY, "lkey" },
424 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
425 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
426 { RPC_AUTH_GSS_SPKM, "spkm" },
427 { RPC_AUTH_GSS_SPKMI, "spkmi" },
428 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400429 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400430 };
431 int i;
432
Chuck Lever4d81cd12007-07-01 12:12:40 -0400433 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400434 if (sec_flavours[i].flavour == flavour)
435 break;
436 }
437 return sec_flavours[i].str;
438}
439
David Howellsf7b422b2006-06-09 09:34:33 -0400440/*
441 * Describe the mount options in force on this server representation
442 */
443static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
444{
David Howells509de812006-08-22 20:06:11 -0400445 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400446 int flag;
David Howells509de812006-08-22 20:06:11 -0400447 const char *str;
448 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400449 } nfs_info[] = {
450 { NFS_MOUNT_SOFT, ",soft", ",hard" },
David Howellsf7b422b2006-06-09 09:34:33 -0400451 { NFS_MOUNT_NOCTO, ",nocto", "" },
452 { NFS_MOUNT_NOAC, ",noac", "" },
453 { NFS_MOUNT_NONLM, ",nolock", "" },
454 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400455 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400456 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400457 { 0, NULL, NULL }
458 };
David Howells509de812006-08-22 20:06:11 -0400459 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400460 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400461
David Howells8fa5c002006-08-22 20:06:12 -0400462 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400463 seq_printf(m, ",rsize=%d", nfss->rsize);
464 seq_printf(m, ",wsize=%d", nfss->wsize);
465 if (nfss->acregmin != 3*HZ || showdefaults)
466 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
467 if (nfss->acregmax != 60*HZ || showdefaults)
468 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
469 if (nfss->acdirmin != 30*HZ || showdefaults)
470 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
471 if (nfss->acdirmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
473 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
474 if (nfss->flags & nfs_infop->flag)
475 seq_puts(m, nfs_infop->str);
476 else
477 seq_puts(m, nfs_infop->nostr);
478 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400479 seq_printf(m, ",proto=%s",
480 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
Trond Myklebust33170232007-12-20 16:03:59 -0500481 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
482 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
Trond Myklebust81039f12006-06-09 09:34:34 -0400483 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400484}
485
486/*
487 * Describe the mount options on this VFS mountpoint
488 */
489static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
490{
491 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
492
493 nfs_show_mount_options(m, nfss, 0);
494
Chuck Lever5d8515c2007-12-10 14:57:16 -0500495 seq_printf(m, ",addr=%s",
496 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
497 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400498
499 return 0;
500}
501
502/*
503 * Present statistical information for this VFS mountpoint
504 */
505static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
506{
507 int i, cpu;
508 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
509 struct rpc_auth *auth = nfss->client->cl_auth;
510 struct nfs_iostats totals = { };
511
512 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
513
514 /*
515 * Display all mount option settings
516 */
517 seq_printf(m, "\n\topts:\t");
518 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
522 nfs_show_mount_options(m, nfss, 1);
523
524 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
525
526 seq_printf(m, "\n\tcaps:\t");
527 seq_printf(m, "caps=0x%x", nfss->caps);
528 seq_printf(m, ",wtmult=%d", nfss->wtmult);
529 seq_printf(m, ",dtsize=%d", nfss->dtsize);
530 seq_printf(m, ",bsize=%d", nfss->bsize);
531 seq_printf(m, ",namelen=%d", nfss->namelen);
532
533#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500534 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400535 seq_printf(m, "\n\tnfsv4:\t");
536 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
537 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
538 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
539 }
540#endif
541
542 /*
543 * Display security flavor in effect for this mount
544 */
545 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
546 if (auth->au_flavor)
547 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
548
549 /*
550 * Display superblock I/O counters
551 */
552 for_each_possible_cpu(cpu) {
553 struct nfs_iostats *stats;
554
555 preempt_disable();
556 stats = per_cpu_ptr(nfss->io_stats, cpu);
557
558 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
559 totals.events[i] += stats->events[i];
560 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
561 totals.bytes[i] += stats->bytes[i];
562
563 preempt_enable();
564 }
565
566 seq_printf(m, "\n\tevents:\t");
567 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
568 seq_printf(m, "%lu ", totals.events[i]);
569 seq_printf(m, "\n\tbytes:\t");
570 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
571 seq_printf(m, "%Lu ", totals.bytes[i]);
572 seq_printf(m, "\n");
573
574 rpc_print_iostats(m, nfss->client);
575
576 return 0;
577}
578
579/*
580 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400581 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400582 */
583static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
584{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400585 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
586 struct rpc_clnt *rpc;
587
David Howellsf7b422b2006-06-09 09:34:33 -0400588 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400589
590 if (!(flags & MNT_FORCE))
591 return;
592 /* -EIO all pending I/O */
593 rpc = server->client_acl;
594 if (!IS_ERR(rpc))
595 rpc_killall_tasks(rpc);
596 rpc = server->client;
597 if (!IS_ERR(rpc))
598 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400599}
600
601/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500602 * Set the port number in an address. Be agnostic about the address family.
603 */
604static void nfs_set_port(struct sockaddr *sap, unsigned short port)
605{
606 switch (sap->sa_family) {
607 case AF_INET: {
608 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
609 ap->sin_port = htons(port);
610 break;
611 }
612 case AF_INET6: {
613 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
614 ap->sin6_port = htons(port);
615 break;
616 }
617 }
618}
619
620/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500621 * Sanity-check a server address provided by the mount command.
622 *
623 * Address family must be initialized, and address must not be
624 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400625 */
626static int nfs_verify_server_address(struct sockaddr *addr)
627{
628 switch (addr->sa_family) {
629 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500630 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
631 return sa->sin_addr.s_addr != INADDR_ANY;
632 }
633 case AF_INET6: {
634 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
635 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400636 }
637 }
638
639 return 0;
640}
641
642/*
Chuck Lever9412b922007-12-10 14:59:21 -0500643 * Parse string addresses passed in via a mount option,
644 * and construct a sockaddr based on the result.
645 *
646 * If address parsing fails, set the sockaddr's address
647 * family to AF_UNSPEC to force nfs_verify_server_address()
648 * to punt the mount.
649 */
650static void nfs_parse_server_address(char *value,
Chuck Lever4c568012007-12-10 14:59:28 -0500651 struct sockaddr *sap,
652 size_t *len)
Chuck Lever9412b922007-12-10 14:59:21 -0500653{
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500654 if (strchr(value, ':')) {
655 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
656 u8 *addr = (u8 *)&ap->sin6_addr.in6_u;
Chuck Lever9412b922007-12-10 14:59:21 -0500657
Chuck Lever3c7c7e42007-12-10 14:59:35 -0500658 ap->sin6_family = AF_INET6;
659 *len = sizeof(*ap);
660 if (in6_pton(value, -1, addr, '\0', NULL))
661 return;
662 } else {
663 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
664 u8 *addr = (u8 *)&ap->sin_addr.s_addr;
665
666 ap->sin_family = AF_INET;
667 *len = sizeof(*ap);
668 if (in4_pton(value, -1, addr, '\0', NULL))
669 return;
670 }
Chuck Lever9412b922007-12-10 14:59:21 -0500671
672 sap->sa_family = AF_UNSPEC;
Chuck Lever4c568012007-12-10 14:59:28 -0500673 *len = 0;
Chuck Lever9412b922007-12-10 14:59:21 -0500674}
675
676/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400677 * Error-check and convert a string of mount options from user space into
678 * a data structure
679 */
680static int nfs_parse_mount_options(char *raw,
681 struct nfs_parsed_mount_data *mnt)
682{
683 char *p, *string;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500684 unsigned short port = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400685
686 if (!raw) {
687 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
688 return 1;
689 }
690 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
691
692 while ((p = strsep(&raw, ",")) != NULL) {
693 substring_t args[MAX_OPT_ARGS];
694 int option, token;
695
696 if (!*p)
697 continue;
698
699 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
700
701 token = match_token(p, nfs_mount_option_tokens, args);
702 switch (token) {
703 case Opt_soft:
704 mnt->flags |= NFS_MOUNT_SOFT;
705 break;
706 case Opt_hard:
707 mnt->flags &= ~NFS_MOUNT_SOFT;
708 break;
709 case Opt_intr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400710 case Opt_nointr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400711 break;
712 case Opt_posix:
713 mnt->flags |= NFS_MOUNT_POSIX;
714 break;
715 case Opt_noposix:
716 mnt->flags &= ~NFS_MOUNT_POSIX;
717 break;
718 case Opt_cto:
719 mnt->flags &= ~NFS_MOUNT_NOCTO;
720 break;
721 case Opt_nocto:
722 mnt->flags |= NFS_MOUNT_NOCTO;
723 break;
724 case Opt_ac:
725 mnt->flags &= ~NFS_MOUNT_NOAC;
726 break;
727 case Opt_noac:
728 mnt->flags |= NFS_MOUNT_NOAC;
729 break;
730 case Opt_lock:
731 mnt->flags &= ~NFS_MOUNT_NONLM;
732 break;
733 case Opt_nolock:
734 mnt->flags |= NFS_MOUNT_NONLM;
735 break;
736 case Opt_v2:
737 mnt->flags &= ~NFS_MOUNT_VER3;
738 break;
739 case Opt_v3:
740 mnt->flags |= NFS_MOUNT_VER3;
741 break;
742 case Opt_udp:
743 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400744 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400745 mnt->timeo = 7;
746 mnt->retrans = 5;
747 break;
748 case Opt_tcp:
749 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400750 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400751 mnt->timeo = 600;
752 mnt->retrans = 2;
753 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400754 case Opt_rdma:
755 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
756 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
757 mnt->timeo = 600;
758 mnt->retrans = 2;
759 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400760 case Opt_acl:
761 mnt->flags &= ~NFS_MOUNT_NOACL;
762 break;
763 case Opt_noacl:
764 mnt->flags |= NFS_MOUNT_NOACL;
765 break;
766 case Opt_rdirplus:
767 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
768 break;
769 case Opt_nordirplus:
770 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
771 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400772 case Opt_sharecache:
773 mnt->flags &= ~NFS_MOUNT_UNSHARED;
774 break;
775 case Opt_nosharecache:
776 mnt->flags |= NFS_MOUNT_UNSHARED;
777 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400778
779 case Opt_port:
780 if (match_int(args, &option))
781 return 0;
782 if (option < 0 || option > 65535)
783 return 0;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500784 port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400785 break;
786 case Opt_rsize:
787 if (match_int(args, &mnt->rsize))
788 return 0;
789 break;
790 case Opt_wsize:
791 if (match_int(args, &mnt->wsize))
792 return 0;
793 break;
794 case Opt_bsize:
795 if (match_int(args, &option))
796 return 0;
797 if (option < 0)
798 return 0;
799 mnt->bsize = option;
800 break;
801 case Opt_timeo:
802 if (match_int(args, &mnt->timeo))
803 return 0;
804 break;
805 case Opt_retrans:
806 if (match_int(args, &mnt->retrans))
807 return 0;
808 break;
809 case Opt_acregmin:
810 if (match_int(args, &mnt->acregmin))
811 return 0;
812 break;
813 case Opt_acregmax:
814 if (match_int(args, &mnt->acregmax))
815 return 0;
816 break;
817 case Opt_acdirmin:
818 if (match_int(args, &mnt->acdirmin))
819 return 0;
820 break;
821 case Opt_acdirmax:
822 if (match_int(args, &mnt->acdirmax))
823 return 0;
824 break;
825 case Opt_actimeo:
826 if (match_int(args, &option))
827 return 0;
828 if (option < 0)
829 return 0;
830 mnt->acregmin =
831 mnt->acregmax =
832 mnt->acdirmin =
833 mnt->acdirmax = option;
834 break;
835 case Opt_namelen:
836 if (match_int(args, &mnt->namlen))
837 return 0;
838 break;
839 case Opt_mountport:
840 if (match_int(args, &option))
841 return 0;
842 if (option < 0 || option > 65535)
843 return 0;
844 mnt->mount_server.port = option;
845 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400846 case Opt_mountvers:
847 if (match_int(args, &option))
848 return 0;
849 if (option < 0)
850 return 0;
851 mnt->mount_server.version = option;
852 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400853 case Opt_nfsvers:
854 if (match_int(args, &option))
855 return 0;
856 switch (option) {
857 case 2:
858 mnt->flags &= ~NFS_MOUNT_VER3;
859 break;
860 case 3:
861 mnt->flags |= NFS_MOUNT_VER3;
862 break;
863 default:
864 goto out_unrec_vers;
865 }
866 break;
867
868 case Opt_sec:
869 string = match_strdup(args);
870 if (string == NULL)
871 goto out_nomem;
872 token = match_token(string, nfs_secflavor_tokens, args);
873 kfree(string);
874
875 /*
876 * The flags setting is for v2/v3. The flavor_len
877 * setting is for v4. v2/v3 also need to know the
878 * difference between NULL and UNIX.
879 */
880 switch (token) {
881 case Opt_sec_none:
882 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 0;
884 mnt->auth_flavors[0] = RPC_AUTH_NULL;
885 break;
886 case Opt_sec_sys:
887 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
888 mnt->auth_flavor_len = 0;
889 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
890 break;
891 case Opt_sec_krb5:
892 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
893 mnt->auth_flavor_len = 1;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
895 break;
896 case Opt_sec_krb5i:
897 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
898 mnt->auth_flavor_len = 1;
899 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
900 break;
901 case Opt_sec_krb5p:
902 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
905 break;
906 case Opt_sec_lkey:
907 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
908 mnt->auth_flavor_len = 1;
909 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
910 break;
911 case Opt_sec_lkeyi:
912 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
913 mnt->auth_flavor_len = 1;
914 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
915 break;
916 case Opt_sec_lkeyp:
917 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
918 mnt->auth_flavor_len = 1;
919 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
920 break;
921 case Opt_sec_spkm:
922 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
923 mnt->auth_flavor_len = 1;
924 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
925 break;
926 case Opt_sec_spkmi:
927 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
928 mnt->auth_flavor_len = 1;
929 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
930 break;
931 case Opt_sec_spkmp:
932 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
933 mnt->auth_flavor_len = 1;
934 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
935 break;
936 default:
937 goto out_unrec_sec;
938 }
939 break;
940 case Opt_proto:
941 string = match_strdup(args);
942 if (string == NULL)
943 goto out_nomem;
944 token = match_token(string,
945 nfs_xprt_protocol_tokens, args);
946 kfree(string);
947
948 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400949 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400950 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400951 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400952 mnt->timeo = 7;
953 mnt->retrans = 5;
954 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400955 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400956 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400957 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958 mnt->timeo = 600;
959 mnt->retrans = 2;
960 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400961 case Opt_xprt_rdma:
962 /* vector side protocols to TCP */
963 mnt->flags |= NFS_MOUNT_TCP;
964 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
965 mnt->timeo = 600;
966 mnt->retrans = 2;
967 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400968 default:
969 goto out_unrec_xprt;
970 }
971 break;
972 case Opt_mountproto:
973 string = match_strdup(args);
974 if (string == NULL)
975 goto out_nomem;
976 token = match_token(string,
977 nfs_xprt_protocol_tokens, args);
978 kfree(string);
979
980 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400981 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400982 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400983 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400984 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400985 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400986 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400987 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400988 default:
989 goto out_unrec_xprt;
990 }
991 break;
992 case Opt_addr:
993 string = match_strdup(args);
994 if (string == NULL)
995 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -0500996 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -0500997 &mnt->nfs_server.address,
998 &mnt->nfs_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400999 kfree(string);
1000 break;
1001 case Opt_clientaddr:
1002 string = match_strdup(args);
1003 if (string == NULL)
1004 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001005 kfree(mnt->client_address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001006 mnt->client_address = string;
1007 break;
Chuck Lever33832032007-12-10 14:59:13 -05001008 case Opt_mounthost:
1009 string = match_strdup(args);
1010 if (string == NULL)
1011 goto out_nomem;
Chuck Leverfc601472008-01-16 16:38:10 -05001012 kfree(mnt->mount_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001013 mnt->mount_server.hostname = string;
1014 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001015 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001016 string = match_strdup(args);
1017 if (string == NULL)
1018 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001019 nfs_parse_server_address(string, (struct sockaddr *)
Chuck Lever4c568012007-12-10 14:59:28 -05001020 &mnt->mount_server.address,
1021 &mnt->mount_server.addrlen);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001022 kfree(string);
1023 break;
1024
1025 case Opt_userspace:
1026 case Opt_deprecated:
1027 break;
1028
1029 default:
1030 goto out_unknown;
1031 }
1032 }
1033
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001034 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port);
1035
Chuck Leverbf0fd762007-07-01 12:13:44 -04001036 return 1;
1037
1038out_nomem:
1039 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1040 return 0;
1041
1042out_unrec_vers:
1043 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1044 return 0;
1045
1046out_unrec_xprt:
1047 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1048 return 0;
1049
1050out_unrec_sec:
1051 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1052 return 0;
1053
1054out_unknown:
1055 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1056 return 0;
1057}
1058
1059/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001060 * Use the remote server's MOUNT service to request the NFS file handle
1061 * corresponding to the provided path.
1062 */
1063static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1064 struct nfs_fh *root_fh)
1065{
Chuck Lever4c568012007-12-10 14:59:28 -05001066 struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address;
Chuck Lever33832032007-12-10 14:59:13 -05001067 char *hostname;
Chuck Lever4c568012007-12-10 14:59:28 -05001068 int status;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001069
1070 if (args->mount_server.version == 0) {
1071 if (args->flags & NFS_MOUNT_VER3)
1072 args->mount_server.version = NFS_MNT3_VERSION;
1073 else
1074 args->mount_server.version = NFS_MNT_VERSION;
1075 }
1076
Chuck Lever33832032007-12-10 14:59:13 -05001077 if (args->mount_server.hostname)
1078 hostname = args->mount_server.hostname;
1079 else
1080 hostname = args->nfs_server.hostname;
1081
Chuck Lever0076d7b2007-07-01 12:13:49 -04001082 /*
1083 * Construct the mount server's address.
1084 */
Chuck Lever4c568012007-12-10 14:59:28 -05001085 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1086 memcpy(sap, &args->nfs_server.address,
1087 args->nfs_server.addrlen);
1088 args->mount_server.addrlen = args->nfs_server.addrlen;
1089 }
1090
James Lentiniaad70002007-09-24 17:32:49 -04001091 /*
1092 * autobind will be used if mount_server.port == 0
1093 */
Chuck Lever4c568012007-12-10 14:59:28 -05001094 nfs_set_port(sap, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001095
1096 /*
1097 * Now ask the mount server to map our export path
1098 * to a file handle.
1099 */
Chuck Lever4c568012007-12-10 14:59:28 -05001100 status = nfs_mount(sap,
1101 args->mount_server.addrlen,
Chuck Lever33832032007-12-10 14:59:13 -05001102 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001103 args->nfs_server.export_path,
1104 args->mount_server.version,
1105 args->mount_server.protocol,
1106 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001107 if (status == 0)
1108 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001109
Chuck Lever33832032007-12-10 14:59:13 -05001110 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1111 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001112 return status;
1113}
1114
1115/*
David Howells54ceac42006-08-22 20:06:13 -04001116 * Validate the NFS2/NFS3 mount data
1117 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001118 *
1119 * For option strings, user space handles the following behaviors:
1120 *
1121 * + DNS: mapping server host name to IP address ("addr=" option)
1122 *
1123 * + failure mode: how to behave if a mount request can't be handled
1124 * immediately ("fg/bg" option)
1125 *
1126 * + retry: how often to retry a mount request ("retry=" option)
1127 *
1128 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1129 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001130 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001131static int nfs_validate_mount_data(void *options,
1132 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001133 struct nfs_fh *mntfh,
1134 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001135{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001136 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001137
Russell Kingf16c9602007-11-16 22:13:24 +00001138 memset(args, 0, sizeof(*args));
1139
Chuck Lever5df36e72007-07-01 12:12:56 -04001140 if (data == NULL)
1141 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001142
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001143 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1144 args->rsize = NFS_MAX_FILE_IO_SIZE;
1145 args->wsize = NFS_MAX_FILE_IO_SIZE;
1146 args->timeo = 600;
1147 args->retrans = 2;
1148 args->acregmin = 3;
1149 args->acregmax = 60;
1150 args->acdirmin = 30;
1151 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001152 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001153 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001154
David Howellsf7b422b2006-06-09 09:34:33 -04001155 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001156 case 1:
1157 data->namlen = 0;
1158 case 2:
1159 data->bsize = 0;
1160 case 3:
1161 if (data->flags & NFS_MOUNT_VER3)
1162 goto out_no_v3;
1163 data->root.size = NFS2_FHSIZE;
1164 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1165 case 4:
1166 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1167 goto out_no_sec;
1168 case 5:
1169 memset(data->context, 0, sizeof(data->context));
1170 case 6:
1171 if (data->flags & NFS_MOUNT_VER3)
1172 mntfh->size = data->root.size;
1173 else
1174 mntfh->size = NFS2_FHSIZE;
1175
1176 if (mntfh->size > sizeof(mntfh->data))
1177 goto out_invalid_fh;
1178
1179 memcpy(mntfh->data, data->root.data, mntfh->size);
1180 if (mntfh->size < sizeof(mntfh->data))
1181 memset(mntfh->data + mntfh->size, 0,
1182 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001183
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001184 /*
1185 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1186 * can deal with.
1187 */
1188 args->flags = data->flags;
1189 args->rsize = data->rsize;
1190 args->wsize = data->wsize;
1191 args->flags = data->flags;
1192 args->timeo = data->timeo;
1193 args->retrans = data->retrans;
1194 args->acregmin = data->acregmin;
1195 args->acregmax = data->acregmax;
1196 args->acdirmin = data->acdirmin;
1197 args->acdirmax = data->acdirmax;
Chuck Lever4c568012007-12-10 14:59:28 -05001198
1199 memcpy(&args->nfs_server.address, &data->addr,
1200 sizeof(data->addr));
1201 args->nfs_server.addrlen = sizeof(data->addr);
1202 if (!nfs_verify_server_address((struct sockaddr *)
1203 &args->nfs_server.address))
1204 goto out_no_address;
1205
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001206 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001207 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001208 /* N.B. caller will free nfs_server.hostname in all cases */
1209 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1210 args->namlen = data->namlen;
1211 args->bsize = data->bsize;
1212 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001213 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001214 default: {
1215 unsigned int len;
1216 char *c;
1217 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001218
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001219 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001220 return -EINVAL;
1221
Chuck Lever6e88e062007-09-24 15:39:50 -04001222 if (!nfs_verify_server_address((struct sockaddr *)
1223 &args->nfs_server.address))
1224 goto out_no_address;
1225
Chuck Lever136d5582007-07-01 12:13:54 -04001226 c = strchr(dev_name, ':');
1227 if (c == NULL)
1228 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001229 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001230 /* N.B. caller will free nfs_server.hostname in all cases */
1231 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001232
1233 c++;
1234 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001235 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001236 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001237
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001238 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001239 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001240 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001241
Chuck Lever136d5582007-07-01 12:13:54 -04001242 break;
1243 }
David Howellsf7b422b2006-06-09 09:34:33 -04001244 }
David Howells54ceac42006-08-22 20:06:13 -04001245
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001246 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1247 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001248
David Howellsf7b422b2006-06-09 09:34:33 -04001249#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001250 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001251 goto out_v3_not_compiled;
1252#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001253
David Howells54ceac42006-08-22 20:06:13 -04001254 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001255
1256out_no_data:
1257 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1258 return -EINVAL;
1259
1260out_no_v3:
1261 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1262 data->version);
1263 return -EINVAL;
1264
1265out_no_sec:
1266 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1267 return -EINVAL;
1268
Chuck Lever5df36e72007-07-01 12:12:56 -04001269#ifndef CONFIG_NFS_V3
1270out_v3_not_compiled:
1271 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1272 return -EPROTONOSUPPORT;
1273#endif /* !CONFIG_NFS_V3 */
1274
1275out_no_address:
1276 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1277 return -EINVAL;
1278
1279out_invalid_fh:
1280 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1281 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001282}
1283
1284/*
1285 * Initialise the common bits of the superblock
1286 */
1287static inline void nfs_initialise_sb(struct super_block *sb)
1288{
1289 struct nfs_server *server = NFS_SB(sb);
1290
1291 sb->s_magic = NFS_SUPER_MAGIC;
1292
1293 /* We probably want something more informative here */
1294 snprintf(sb->s_id, sizeof(sb->s_id),
1295 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1296
1297 if (sb->s_blocksize == 0)
1298 sb->s_blocksize = nfs_block_bits(server->wsize,
1299 &sb->s_blocksize_bits);
1300
1301 if (server->flags & NFS_MOUNT_NOAC)
1302 sb->s_flags |= MS_SYNCHRONOUS;
1303
1304 nfs_super_set_maxbytes(sb, server->maxfilesize);
1305}
1306
1307/*
1308 * Finish setting up an NFS2/3 superblock
1309 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001310static void nfs_fill_super(struct super_block *sb,
1311 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001312{
1313 struct nfs_server *server = NFS_SB(sb);
1314
1315 sb->s_blocksize_bits = 0;
1316 sb->s_blocksize = 0;
1317 if (data->bsize)
1318 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1319
1320 if (server->flags & NFS_MOUNT_VER3) {
1321 /* The VFS shouldn't apply the umask to mode bits. We will do
1322 * so ourselves when necessary.
1323 */
1324 sb->s_flags |= MS_POSIXACL;
1325 sb->s_time_gran = 1;
1326 }
1327
1328 sb->s_op = &nfs_sops;
1329 nfs_initialise_sb(sb);
1330}
1331
1332/*
1333 * Finish setting up a cloned NFS2/3 superblock
1334 */
1335static void nfs_clone_super(struct super_block *sb,
1336 const struct super_block *old_sb)
1337{
1338 struct nfs_server *server = NFS_SB(sb);
1339
1340 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1341 sb->s_blocksize = old_sb->s_blocksize;
1342 sb->s_maxbytes = old_sb->s_maxbytes;
1343
1344 if (server->flags & NFS_MOUNT_VER3) {
1345 /* The VFS shouldn't apply the umask to mode bits. We will do
1346 * so ourselves when necessary.
1347 */
1348 sb->s_flags |= MS_POSIXACL;
1349 sb->s_time_gran = 1;
1350 }
1351
1352 sb->s_op = old_sb->s_op;
1353 nfs_initialise_sb(sb);
1354}
1355
Trond Myklebust275a5d22007-05-16 16:53:28 -04001356#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1357
1358static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1359{
1360 const struct nfs_server *a = s->s_fs_info;
1361 const struct rpc_clnt *clnt_a = a->client;
1362 const struct rpc_clnt *clnt_b = b->client;
1363
1364 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1365 goto Ebusy;
1366 if (a->nfs_client != b->nfs_client)
1367 goto Ebusy;
1368 if (a->flags != b->flags)
1369 goto Ebusy;
1370 if (a->wsize != b->wsize)
1371 goto Ebusy;
1372 if (a->rsize != b->rsize)
1373 goto Ebusy;
1374 if (a->acregmin != b->acregmin)
1375 goto Ebusy;
1376 if (a->acregmax != b->acregmax)
1377 goto Ebusy;
1378 if (a->acdirmin != b->acdirmin)
1379 goto Ebusy;
1380 if (a->acdirmax != b->acdirmax)
1381 goto Ebusy;
1382 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1383 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001384 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001385Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001386 return 0;
1387}
1388
1389struct nfs_sb_mountdata {
1390 struct nfs_server *server;
1391 int mntflags;
1392};
1393
1394static int nfs_set_super(struct super_block *s, void *data)
1395{
1396 struct nfs_sb_mountdata *sb_mntdata = data;
1397 struct nfs_server *server = sb_mntdata->server;
1398 int ret;
1399
1400 s->s_flags = sb_mntdata->mntflags;
1401 s->s_fs_info = server;
1402 ret = set_anon_super(s, server);
1403 if (ret == 0)
1404 server->s_dev = s->s_dev;
1405 return ret;
1406}
1407
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001408static int nfs_compare_super_address(struct nfs_server *server1,
1409 struct nfs_server *server2)
1410{
1411 struct sockaddr *sap1, *sap2;
1412
1413 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1414 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1415
1416 if (sap1->sa_family != sap2->sa_family)
1417 return 0;
1418
1419 switch (sap1->sa_family) {
1420 case AF_INET: {
1421 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1422 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1423 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1424 return 0;
1425 if (sin1->sin_port != sin2->sin_port)
1426 return 0;
1427 break;
1428 }
1429 case AF_INET6: {
1430 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1431 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1432 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1433 return 0;
1434 if (sin1->sin6_port != sin2->sin6_port)
1435 return 0;
1436 break;
1437 }
1438 default:
1439 return 0;
1440 }
1441
1442 return 1;
1443}
1444
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001445static int nfs_compare_super(struct super_block *sb, void *data)
1446{
1447 struct nfs_sb_mountdata *sb_mntdata = data;
1448 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1449 int mntflags = sb_mntdata->mntflags;
1450
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001451 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001452 return 0;
1453 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1454 if (old->flags & NFS_MOUNT_UNSHARED)
1455 return 0;
1456 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1457 return 0;
1458 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001459}
1460
David Howells54ceac42006-08-22 20:06:13 -04001461static int nfs_get_sb(struct file_system_type *fs_type,
1462 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1463{
1464 struct nfs_server *server = NULL;
1465 struct super_block *s;
1466 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001467 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001468 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001469 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001470 struct nfs_sb_mountdata sb_mntdata = {
1471 .mntflags = flags,
1472 };
David Howells54ceac42006-08-22 20:06:13 -04001473 int error;
1474
1475 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001476 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001477 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001478 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001479
1480 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001481 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001482 if (IS_ERR(server)) {
1483 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001484 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001485 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001486 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001487
Trond Myklebust75180df2007-05-16 16:53:28 -04001488 if (server->flags & NFS_MOUNT_UNSHARED)
1489 compare_super = NULL;
1490
David Howells54ceac42006-08-22 20:06:13 -04001491 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001492 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001493 if (IS_ERR(s)) {
1494 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001495 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001496 }
1497
David Howells54ceac42006-08-22 20:06:13 -04001498 if (s->s_fs_info != server) {
1499 nfs_free_server(server);
1500 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001501 }
David Howells54ceac42006-08-22 20:06:13 -04001502
1503 if (!s->s_root) {
1504 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001505 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001506 }
1507
1508 mntroot = nfs_get_root(s, &mntfh);
1509 if (IS_ERR(mntroot)) {
1510 error = PTR_ERR(mntroot);
1511 goto error_splat_super;
1512 }
1513
David Howellsf7b422b2006-06-09 09:34:33 -04001514 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001515 mnt->mnt_sb = s;
1516 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001517 error = 0;
1518
1519out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001520 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001521 kfree(data.mount_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001522 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001523
David Howells54ceac42006-08-22 20:06:13 -04001524out_err_nosb:
1525 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001526 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001527
1528error_splat_super:
1529 up_write(&s->s_umount);
1530 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001531 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001532}
1533
David Howells54ceac42006-08-22 20:06:13 -04001534/*
1535 * Destroy an NFS2/3 superblock
1536 */
David Howellsf7b422b2006-06-09 09:34:33 -04001537static void nfs_kill_super(struct super_block *s)
1538{
1539 struct nfs_server *server = NFS_SB(s);
1540
1541 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001542 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001543}
1544
David Howells54ceac42006-08-22 20:06:13 -04001545/*
1546 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1547 */
1548static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1549 const char *dev_name, void *raw_data,
1550 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001551{
1552 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001553 struct super_block *s;
1554 struct nfs_server *server;
1555 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001556 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001557 struct nfs_sb_mountdata sb_mntdata = {
1558 .mntflags = flags,
1559 };
David Howells54ceac42006-08-22 20:06:13 -04001560 int error;
1561
1562 dprintk("--> nfs_xdev_get_sb()\n");
1563
1564 /* create a new volume representation */
1565 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1566 if (IS_ERR(server)) {
1567 error = PTR_ERR(server);
1568 goto out_err_noserver;
1569 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001570 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001571
Trond Myklebust75180df2007-05-16 16:53:28 -04001572 if (server->flags & NFS_MOUNT_UNSHARED)
1573 compare_super = NULL;
1574
David Howells54ceac42006-08-22 20:06:13 -04001575 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001576 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001577 if (IS_ERR(s)) {
1578 error = PTR_ERR(s);
1579 goto out_err_nosb;
1580 }
1581
1582 if (s->s_fs_info != server) {
1583 nfs_free_server(server);
1584 server = NULL;
1585 }
1586
1587 if (!s->s_root) {
1588 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001589 nfs_clone_super(s, data->sb);
1590 }
1591
1592 mntroot = nfs_get_root(s, data->fh);
1593 if (IS_ERR(mntroot)) {
1594 error = PTR_ERR(mntroot);
1595 goto error_splat_super;
1596 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001597 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001598 dput(mntroot);
1599 error = -ESTALE;
1600 goto error_splat_super;
1601 }
David Howells54ceac42006-08-22 20:06:13 -04001602
1603 s->s_flags |= MS_ACTIVE;
1604 mnt->mnt_sb = s;
1605 mnt->mnt_root = mntroot;
1606
1607 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1608 return 0;
1609
1610out_err_nosb:
1611 nfs_free_server(server);
1612out_err_noserver:
1613 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1614 return error;
1615
1616error_splat_super:
1617 up_write(&s->s_umount);
1618 deactivate_super(s);
1619 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1620 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001621}
1622
1623#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001624
1625/*
1626 * Finish setting up a cloned NFS4 superblock
1627 */
1628static void nfs4_clone_super(struct super_block *sb,
1629 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001630{
David Howells54ceac42006-08-22 20:06:13 -04001631 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1632 sb->s_blocksize = old_sb->s_blocksize;
1633 sb->s_maxbytes = old_sb->s_maxbytes;
1634 sb->s_time_gran = 1;
1635 sb->s_op = old_sb->s_op;
1636 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001637}
1638
1639/*
1640 * Set up an NFS4 superblock
1641 */
David Howells54ceac42006-08-22 20:06:13 -04001642static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001643{
David Howellsf7b422b2006-06-09 09:34:33 -04001644 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001645 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001646 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001647}
1648
David Howells54ceac42006-08-22 20:06:13 -04001649/*
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001650 * If the user didn't specify a port, set the port number to
1651 * the NFS version 4 default port.
1652 */
1653static void nfs4_default_port(struct sockaddr *sap)
1654{
1655 switch (sap->sa_family) {
1656 case AF_INET: {
1657 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1658 if (ap->sin_port == 0)
1659 ap->sin_port = htons(NFS_PORT);
1660 break;
1661 }
1662 case AF_INET6: {
1663 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1664 if (ap->sin6_port == 0)
1665 ap->sin6_port = htons(NFS_PORT);
1666 break;
1667 }
1668 }
1669}
1670
1671/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001672 * Validate NFSv4 mount options
1673 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001674static int nfs4_validate_mount_data(void *options,
1675 struct nfs_parsed_mount_data *args,
1676 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001677{
Chuck Lever4c568012007-12-10 14:59:28 -05001678 struct sockaddr_in *ap;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001679 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001680 char *c;
1681
Russell Kingf16c9602007-11-16 22:13:24 +00001682 memset(args, 0, sizeof(*args));
1683
Chuck Leverf0768eb2007-07-01 12:13:01 -04001684 if (data == NULL)
1685 goto out_no_data;
1686
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001687 args->rsize = NFS_MAX_FILE_IO_SIZE;
1688 args->wsize = NFS_MAX_FILE_IO_SIZE;
1689 args->timeo = 600;
1690 args->retrans = 2;
1691 args->acregmin = 3;
1692 args->acregmax = 60;
1693 args->acdirmin = 30;
1694 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001695 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001696
Chuck Leverf0768eb2007-07-01 12:13:01 -04001697 switch (data->version) {
1698 case 1:
Chuck Lever4c568012007-12-10 14:59:28 -05001699 ap = (struct sockaddr_in *)&args->nfs_server.address;
1700 if (data->host_addrlen > sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001701 goto out_no_address;
Chuck Lever4c568012007-12-10 14:59:28 -05001702 if (data->host_addrlen == 0)
1703 goto out_no_address;
1704 args->nfs_server.addrlen = data->host_addrlen;
1705 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001706 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001707 if (!nfs_verify_server_address((struct sockaddr *)
1708 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001709 goto out_no_address;
1710
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001711 nfs4_default_port((struct sockaddr *)
1712 &args->nfs_server.address);
1713
Chuck Leverf0768eb2007-07-01 12:13:01 -04001714 switch (data->auth_flavourlen) {
1715 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001716 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001717 break;
1718 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001719 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001720 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001721 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001722 return -EFAULT;
1723 break;
1724 default:
1725 goto out_inval_auth;
1726 }
1727
1728 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1729 if (IS_ERR(c))
1730 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001731 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001732
1733 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1734 if (IS_ERR(c))
1735 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001736 args->nfs_server.export_path = c;
1737 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001738
1739 c = strndup_user(data->client_addr.data, 16);
1740 if (IS_ERR(c))
1741 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001742 args->client_address = c;
1743
1744 /*
1745 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1746 * can deal with.
1747 */
1748
1749 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1750 args->rsize = data->rsize;
1751 args->wsize = data->wsize;
1752 args->timeo = data->timeo;
1753 args->retrans = data->retrans;
1754 args->acregmin = data->acregmin;
1755 args->acregmax = data->acregmax;
1756 args->acdirmin = data->acdirmin;
1757 args->acdirmax = data->acdirmax;
1758 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001759
1760 break;
Chuck Lever80071222007-07-01 12:13:59 -04001761 default: {
1762 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001763
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001764 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001765 return -EINVAL;
1766
1767 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001768 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001769 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001770
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001771 nfs4_default_port((struct sockaddr *)
1772 &args->nfs_server.address);
1773
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001774 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001775 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001776 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001777 break;
1778 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001779 break;
1780 default:
1781 goto out_inval_auth;
1782 }
1783
1784 /*
Chuck Lever80071222007-07-01 12:13:59 -04001785 * Split "dev_name" into "hostname:mntpath".
1786 */
1787 c = strchr(dev_name, ':');
1788 if (c == NULL)
1789 return -EINVAL;
1790 /* while calculating len, pretend ':' is '\0' */
1791 len = c - dev_name;
1792 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001793 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001794 /* N.B. caller will free nfs_server.hostname in all cases */
1795 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001796
1797 c++; /* step over the ':' */
1798 len = strlen(c);
1799 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001800 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001801 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001802
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001803 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001804
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001805 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001806 goto out_no_client_address;
1807
Chuck Lever80071222007-07-01 12:13:59 -04001808 break;
1809 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001810 }
1811
1812 return 0;
1813
1814out_no_data:
1815 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1816 return -EINVAL;
1817
1818out_inval_auth:
1819 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1820 data->auth_flavourlen);
1821 return -EINVAL;
1822
1823out_no_address:
1824 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1825 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001826
1827out_no_client_address:
1828 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1829 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001830}
1831
1832/*
David Howells54ceac42006-08-22 20:06:13 -04001833 * Get the superblock for an NFS4 mountpoint
1834 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001835static int nfs4_get_sb(struct file_system_type *fs_type,
1836 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001837{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001838 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001839 struct super_block *s;
1840 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001841 struct nfs_fh mntfh;
1842 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001843 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001844 struct nfs_sb_mountdata sb_mntdata = {
1845 .mntflags = flags,
1846 };
David Howells54ceac42006-08-22 20:06:13 -04001847 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001848
Chuck Leverf0768eb2007-07-01 12:13:01 -04001849 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001850 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001851 if (error < 0)
1852 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001853
David Howells54ceac42006-08-22 20:06:13 -04001854 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001855 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001856 if (IS_ERR(server)) {
1857 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001858 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001859 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001860 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001861
Trond Myklebust75180df2007-05-16 16:53:28 -04001862 if (server->flags & NFS4_MOUNT_UNSHARED)
1863 compare_super = NULL;
1864
David Howells54ceac42006-08-22 20:06:13 -04001865 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001866 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001867 if (IS_ERR(s)) {
1868 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001869 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001870 }
1871
Trond Myklebust5dd31772006-08-24 01:03:05 -04001872 if (s->s_fs_info != server) {
1873 nfs_free_server(server);
1874 server = NULL;
1875 }
1876
David Howells54ceac42006-08-22 20:06:13 -04001877 if (!s->s_root) {
1878 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001879 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001880 }
David Howellsf7b422b2006-06-09 09:34:33 -04001881
David Howells54ceac42006-08-22 20:06:13 -04001882 mntroot = nfs4_get_root(s, &mntfh);
1883 if (IS_ERR(mntroot)) {
1884 error = PTR_ERR(mntroot);
1885 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001886 }
David Howells54ceac42006-08-22 20:06:13 -04001887
David Howellsf7b422b2006-06-09 09:34:33 -04001888 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001889 mnt->mnt_sb = s;
1890 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001891 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001892
Chuck Lever29eb9812007-07-01 12:12:30 -04001893out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001894 kfree(data.client_address);
1895 kfree(data.nfs_server.export_path);
1896 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001897 return error;
David Howells54ceac42006-08-22 20:06:13 -04001898
Chuck Lever29eb9812007-07-01 12:12:30 -04001899out_free:
1900 nfs_free_server(server);
1901 goto out;
1902
David Howells54ceac42006-08-22 20:06:13 -04001903error_splat_super:
1904 up_write(&s->s_umount);
1905 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001906 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001907}
1908
1909static void nfs4_kill_super(struct super_block *sb)
1910{
1911 struct nfs_server *server = NFS_SB(sb);
1912
1913 nfs_return_all_delegations(sb);
1914 kill_anon_super(sb);
1915
1916 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001917 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001918}
1919
1920/*
David Howells54ceac42006-08-22 20:06:13 -04001921 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001922 */
David Howells54ceac42006-08-22 20:06:13 -04001923static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1924 const char *dev_name, void *raw_data,
1925 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001926{
1927 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001928 struct super_block *s;
1929 struct nfs_server *server;
1930 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001931 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001932 struct nfs_sb_mountdata sb_mntdata = {
1933 .mntflags = flags,
1934 };
David Howells54ceac42006-08-22 20:06:13 -04001935 int error;
1936
1937 dprintk("--> nfs4_xdev_get_sb()\n");
1938
1939 /* create a new volume representation */
1940 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1941 if (IS_ERR(server)) {
1942 error = PTR_ERR(server);
1943 goto out_err_noserver;
1944 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001945 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001946
Trond Myklebust75180df2007-05-16 16:53:28 -04001947 if (server->flags & NFS4_MOUNT_UNSHARED)
1948 compare_super = NULL;
1949
David Howells54ceac42006-08-22 20:06:13 -04001950 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001951 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001952 if (IS_ERR(s)) {
1953 error = PTR_ERR(s);
1954 goto out_err_nosb;
1955 }
1956
1957 if (s->s_fs_info != server) {
1958 nfs_free_server(server);
1959 server = NULL;
1960 }
1961
1962 if (!s->s_root) {
1963 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001964 nfs4_clone_super(s, data->sb);
1965 }
1966
1967 mntroot = nfs4_get_root(s, data->fh);
1968 if (IS_ERR(mntroot)) {
1969 error = PTR_ERR(mntroot);
1970 goto error_splat_super;
1971 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001972 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1973 dput(mntroot);
1974 error = -ESTALE;
1975 goto error_splat_super;
1976 }
David Howells54ceac42006-08-22 20:06:13 -04001977
1978 s->s_flags |= MS_ACTIVE;
1979 mnt->mnt_sb = s;
1980 mnt->mnt_root = mntroot;
1981
1982 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1983 return 0;
1984
1985out_err_nosb:
1986 nfs_free_server(server);
1987out_err_noserver:
1988 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1989 return error;
1990
1991error_splat_super:
1992 up_write(&s->s_umount);
1993 deactivate_super(s);
1994 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1995 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001996}
1997
David Howells54ceac42006-08-22 20:06:13 -04001998/*
1999 * Create an NFS4 server record on referral traversal
2000 */
2001static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2002 const char *dev_name, void *raw_data,
2003 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04002004{
2005 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04002006 struct super_block *s;
2007 struct nfs_server *server;
2008 struct dentry *mntroot;
2009 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04002010 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002011 struct nfs_sb_mountdata sb_mntdata = {
2012 .mntflags = flags,
2013 };
David Howells54ceac42006-08-22 20:06:13 -04002014 int error;
2015
2016 dprintk("--> nfs4_referral_get_sb()\n");
2017
2018 /* create a new volume representation */
2019 server = nfs4_create_referral_server(data, &mntfh);
2020 if (IS_ERR(server)) {
2021 error = PTR_ERR(server);
2022 goto out_err_noserver;
2023 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002024 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04002025
Trond Myklebust75180df2007-05-16 16:53:28 -04002026 if (server->flags & NFS4_MOUNT_UNSHARED)
2027 compare_super = NULL;
2028
David Howells54ceac42006-08-22 20:06:13 -04002029 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04002030 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002031 if (IS_ERR(s)) {
2032 error = PTR_ERR(s);
2033 goto out_err_nosb;
2034 }
2035
2036 if (s->s_fs_info != server) {
2037 nfs_free_server(server);
2038 server = NULL;
2039 }
2040
2041 if (!s->s_root) {
2042 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002043 nfs4_fill_super(s);
2044 }
2045
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002046 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002047 if (IS_ERR(mntroot)) {
2048 error = PTR_ERR(mntroot);
2049 goto error_splat_super;
2050 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002051 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2052 dput(mntroot);
2053 error = -ESTALE;
2054 goto error_splat_super;
2055 }
David Howells54ceac42006-08-22 20:06:13 -04002056
2057 s->s_flags |= MS_ACTIVE;
2058 mnt->mnt_sb = s;
2059 mnt->mnt_root = mntroot;
2060
2061 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2062 return 0;
2063
2064out_err_nosb:
2065 nfs_free_server(server);
2066out_err_noserver:
2067 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2068 return error;
2069
2070error_splat_super:
2071 up_write(&s->s_umount);
2072 deactivate_super(s);
2073 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2074 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002075}
2076
David Howells54ceac42006-08-22 20:06:13 -04002077#endif /* CONFIG_NFS_V4 */