blob: 041fe9e9b74d872587578c69f2198c265cc605de [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" },
Chuck Leverbcf35612007-09-24 15:39:55 -0400451 { NFS_MOUNT_INTR, ",intr", ",nointr" },
David Howellsf7b422b2006-06-09 09:34:33 -0400452 { NFS_MOUNT_NOCTO, ",nocto", "" },
453 { NFS_MOUNT_NOAC, ",noac", "" },
454 { NFS_MOUNT_NONLM, ",nolock", "" },
455 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400456 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
Trond Myklebust75180df2007-05-16 16:53:28 -0400457 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
David Howellsf7b422b2006-06-09 09:34:33 -0400458 { 0, NULL, NULL }
459 };
David Howells509de812006-08-22 20:06:11 -0400460 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400461 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400462
David Howells8fa5c002006-08-22 20:06:12 -0400463 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400464 seq_printf(m, ",rsize=%d", nfss->rsize);
465 seq_printf(m, ",wsize=%d", nfss->wsize);
466 if (nfss->acregmin != 3*HZ || showdefaults)
467 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
468 if (nfss->acregmax != 60*HZ || showdefaults)
469 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
470 if (nfss->acdirmin != 30*HZ || showdefaults)
471 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
472 if (nfss->acdirmax != 60*HZ || showdefaults)
473 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
474 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
475 if (nfss->flags & nfs_infop->flag)
476 seq_puts(m, nfs_infop->str);
477 else
478 seq_puts(m, nfs_infop->nostr);
479 }
\"Talpey, Thomas\56928ed2007-09-10 13:48:47 -0400480 seq_printf(m, ",proto=%s",
481 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
David Howells5006a762006-08-22 20:06:12 -0400482 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
483 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400484 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400485}
486
487/*
488 * Describe the mount options on this VFS mountpoint
489 */
490static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
491{
492 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
493
494 nfs_show_mount_options(m, nfss, 0);
495
Chuck Lever5d8515c2007-12-10 14:57:16 -0500496 seq_printf(m, ",addr=%s",
497 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
498 RPC_DISPLAY_ADDR));
David Howellsf7b422b2006-06-09 09:34:33 -0400499
500 return 0;
501}
502
503/*
504 * Present statistical information for this VFS mountpoint
505 */
506static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
507{
508 int i, cpu;
509 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
510 struct rpc_auth *auth = nfss->client->cl_auth;
511 struct nfs_iostats totals = { };
512
513 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
514
515 /*
516 * Display all mount option settings
517 */
518 seq_printf(m, "\n\topts:\t");
519 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
520 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
521 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
522 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
523 nfs_show_mount_options(m, nfss, 1);
524
525 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
526
527 seq_printf(m, "\n\tcaps:\t");
528 seq_printf(m, "caps=0x%x", nfss->caps);
529 seq_printf(m, ",wtmult=%d", nfss->wtmult);
530 seq_printf(m, ",dtsize=%d", nfss->dtsize);
531 seq_printf(m, ",bsize=%d", nfss->bsize);
532 seq_printf(m, ",namelen=%d", nfss->namelen);
533
534#ifdef CONFIG_NFS_V4
Trond Myklebust40c553192007-12-14 14:56:07 -0500535 if (nfss->nfs_client->rpc_ops->version == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400536 seq_printf(m, "\n\tnfsv4:\t");
537 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
538 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
539 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
540 }
541#endif
542
543 /*
544 * Display security flavor in effect for this mount
545 */
546 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
547 if (auth->au_flavor)
548 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
549
550 /*
551 * Display superblock I/O counters
552 */
553 for_each_possible_cpu(cpu) {
554 struct nfs_iostats *stats;
555
556 preempt_disable();
557 stats = per_cpu_ptr(nfss->io_stats, cpu);
558
559 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
560 totals.events[i] += stats->events[i];
561 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
562 totals.bytes[i] += stats->bytes[i];
563
564 preempt_enable();
565 }
566
567 seq_printf(m, "\n\tevents:\t");
568 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
569 seq_printf(m, "%lu ", totals.events[i]);
570 seq_printf(m, "\n\tbytes:\t");
571 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
572 seq_printf(m, "%Lu ", totals.bytes[i]);
573 seq_printf(m, "\n");
574
575 rpc_print_iostats(m, nfss->client);
576
577 return 0;
578}
579
580/*
581 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400582 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400583 */
584static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
585{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400586 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
587 struct rpc_clnt *rpc;
588
David Howellsf7b422b2006-06-09 09:34:33 -0400589 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400590
591 if (!(flags & MNT_FORCE))
592 return;
593 /* -EIO all pending I/O */
594 rpc = server->client_acl;
595 if (!IS_ERR(rpc))
596 rpc_killall_tasks(rpc);
597 rpc = server->client;
598 if (!IS_ERR(rpc))
599 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400600}
601
602/*
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500603 * Set the port number in an address. Be agnostic about the address family.
604 */
605static void nfs_set_port(struct sockaddr *sap, unsigned short port)
606{
607 switch (sap->sa_family) {
608 case AF_INET: {
609 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
610 ap->sin_port = htons(port);
611 break;
612 }
613 case AF_INET6: {
614 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
615 ap->sin6_port = htons(port);
616 break;
617 }
618 }
619}
620
621/*
Chuck Levercdcd7f92007-12-10 14:57:45 -0500622 * Sanity-check a server address provided by the mount command.
623 *
624 * Address family must be initialized, and address must not be
625 * the ANY address for that family.
Chuck Leverfc50d582007-07-01 12:12:46 -0400626 */
627static int nfs_verify_server_address(struct sockaddr *addr)
628{
629 switch (addr->sa_family) {
630 case AF_INET: {
Chuck Levercdcd7f92007-12-10 14:57:45 -0500631 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
632 return sa->sin_addr.s_addr != INADDR_ANY;
633 }
634 case AF_INET6: {
635 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
636 return !ipv6_addr_any(sa);
Chuck Leverfc50d582007-07-01 12:12:46 -0400637 }
638 }
639
640 return 0;
641}
642
643/*
Chuck Lever9412b922007-12-10 14:59:21 -0500644 * Parse string addresses passed in via a mount option,
645 * and construct a sockaddr based on the result.
646 *
647 * If address parsing fails, set the sockaddr's address
648 * family to AF_UNSPEC to force nfs_verify_server_address()
649 * to punt the mount.
650 */
651static void nfs_parse_server_address(char *value,
652 struct sockaddr *sap)
653{
654 struct sockaddr_in *ap = (void *)sap;
655
656 ap->sin_family = AF_INET;
657 if (in4_pton(value, -1, (u8 *)&ap->sin_addr.s_addr, '\0', NULL))
658 return;
659
660 sap->sa_family = AF_UNSPEC;
661}
662
663/*
Chuck Leverbf0fd762007-07-01 12:13:44 -0400664 * Error-check and convert a string of mount options from user space into
665 * a data structure
666 */
667static int nfs_parse_mount_options(char *raw,
668 struct nfs_parsed_mount_data *mnt)
669{
670 char *p, *string;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500671 unsigned short port = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400672
673 if (!raw) {
674 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
675 return 1;
676 }
677 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
678
679 while ((p = strsep(&raw, ",")) != NULL) {
680 substring_t args[MAX_OPT_ARGS];
681 int option, token;
682
683 if (!*p)
684 continue;
685
686 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
687
688 token = match_token(p, nfs_mount_option_tokens, args);
689 switch (token) {
690 case Opt_soft:
691 mnt->flags |= NFS_MOUNT_SOFT;
692 break;
693 case Opt_hard:
694 mnt->flags &= ~NFS_MOUNT_SOFT;
695 break;
696 case Opt_intr:
697 mnt->flags |= NFS_MOUNT_INTR;
698 break;
699 case Opt_nointr:
700 mnt->flags &= ~NFS_MOUNT_INTR;
701 break;
702 case Opt_posix:
703 mnt->flags |= NFS_MOUNT_POSIX;
704 break;
705 case Opt_noposix:
706 mnt->flags &= ~NFS_MOUNT_POSIX;
707 break;
708 case Opt_cto:
709 mnt->flags &= ~NFS_MOUNT_NOCTO;
710 break;
711 case Opt_nocto:
712 mnt->flags |= NFS_MOUNT_NOCTO;
713 break;
714 case Opt_ac:
715 mnt->flags &= ~NFS_MOUNT_NOAC;
716 break;
717 case Opt_noac:
718 mnt->flags |= NFS_MOUNT_NOAC;
719 break;
720 case Opt_lock:
721 mnt->flags &= ~NFS_MOUNT_NONLM;
722 break;
723 case Opt_nolock:
724 mnt->flags |= NFS_MOUNT_NONLM;
725 break;
726 case Opt_v2:
727 mnt->flags &= ~NFS_MOUNT_VER3;
728 break;
729 case Opt_v3:
730 mnt->flags |= NFS_MOUNT_VER3;
731 break;
732 case Opt_udp:
733 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400734 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400735 mnt->timeo = 7;
736 mnt->retrans = 5;
737 break;
738 case Opt_tcp:
739 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400740 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400741 mnt->timeo = 600;
742 mnt->retrans = 2;
743 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400744 case Opt_rdma:
745 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
746 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
747 mnt->timeo = 600;
748 mnt->retrans = 2;
749 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400750 case Opt_acl:
751 mnt->flags &= ~NFS_MOUNT_NOACL;
752 break;
753 case Opt_noacl:
754 mnt->flags |= NFS_MOUNT_NOACL;
755 break;
756 case Opt_rdirplus:
757 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
758 break;
759 case Opt_nordirplus:
760 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
761 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400762 case Opt_sharecache:
763 mnt->flags &= ~NFS_MOUNT_UNSHARED;
764 break;
765 case Opt_nosharecache:
766 mnt->flags |= NFS_MOUNT_UNSHARED;
767 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400768
769 case Opt_port:
770 if (match_int(args, &option))
771 return 0;
772 if (option < 0 || option > 65535)
773 return 0;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500774 port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400775 break;
776 case Opt_rsize:
777 if (match_int(args, &mnt->rsize))
778 return 0;
779 break;
780 case Opt_wsize:
781 if (match_int(args, &mnt->wsize))
782 return 0;
783 break;
784 case Opt_bsize:
785 if (match_int(args, &option))
786 return 0;
787 if (option < 0)
788 return 0;
789 mnt->bsize = option;
790 break;
791 case Opt_timeo:
792 if (match_int(args, &mnt->timeo))
793 return 0;
794 break;
795 case Opt_retrans:
796 if (match_int(args, &mnt->retrans))
797 return 0;
798 break;
799 case Opt_acregmin:
800 if (match_int(args, &mnt->acregmin))
801 return 0;
802 break;
803 case Opt_acregmax:
804 if (match_int(args, &mnt->acregmax))
805 return 0;
806 break;
807 case Opt_acdirmin:
808 if (match_int(args, &mnt->acdirmin))
809 return 0;
810 break;
811 case Opt_acdirmax:
812 if (match_int(args, &mnt->acdirmax))
813 return 0;
814 break;
815 case Opt_actimeo:
816 if (match_int(args, &option))
817 return 0;
818 if (option < 0)
819 return 0;
820 mnt->acregmin =
821 mnt->acregmax =
822 mnt->acdirmin =
823 mnt->acdirmax = option;
824 break;
825 case Opt_namelen:
826 if (match_int(args, &mnt->namlen))
827 return 0;
828 break;
829 case Opt_mountport:
830 if (match_int(args, &option))
831 return 0;
832 if (option < 0 || option > 65535)
833 return 0;
834 mnt->mount_server.port = option;
835 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400836 case Opt_mountvers:
837 if (match_int(args, &option))
838 return 0;
839 if (option < 0)
840 return 0;
841 mnt->mount_server.version = option;
842 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400843 case Opt_nfsvers:
844 if (match_int(args, &option))
845 return 0;
846 switch (option) {
847 case 2:
848 mnt->flags &= ~NFS_MOUNT_VER3;
849 break;
850 case 3:
851 mnt->flags |= NFS_MOUNT_VER3;
852 break;
853 default:
854 goto out_unrec_vers;
855 }
856 break;
857
858 case Opt_sec:
859 string = match_strdup(args);
860 if (string == NULL)
861 goto out_nomem;
862 token = match_token(string, nfs_secflavor_tokens, args);
863 kfree(string);
864
865 /*
866 * The flags setting is for v2/v3. The flavor_len
867 * setting is for v4. v2/v3 also need to know the
868 * difference between NULL and UNIX.
869 */
870 switch (token) {
871 case Opt_sec_none:
872 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 0;
874 mnt->auth_flavors[0] = RPC_AUTH_NULL;
875 break;
876 case Opt_sec_sys:
877 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 0;
879 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
880 break;
881 case Opt_sec_krb5:
882 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 1;
884 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
885 break;
886 case Opt_sec_krb5i:
887 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
888 mnt->auth_flavor_len = 1;
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
890 break;
891 case Opt_sec_krb5p:
892 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
893 mnt->auth_flavor_len = 1;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
895 break;
896 case Opt_sec_lkey:
897 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
898 mnt->auth_flavor_len = 1;
899 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
900 break;
901 case Opt_sec_lkeyi:
902 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
905 break;
906 case Opt_sec_lkeyp:
907 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
908 mnt->auth_flavor_len = 1;
909 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
910 break;
911 case Opt_sec_spkm:
912 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
913 mnt->auth_flavor_len = 1;
914 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
915 break;
916 case Opt_sec_spkmi:
917 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
918 mnt->auth_flavor_len = 1;
919 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
920 break;
921 case Opt_sec_spkmp:
922 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
923 mnt->auth_flavor_len = 1;
924 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
925 break;
926 default:
927 goto out_unrec_sec;
928 }
929 break;
930 case Opt_proto:
931 string = match_strdup(args);
932 if (string == NULL)
933 goto out_nomem;
934 token = match_token(string,
935 nfs_xprt_protocol_tokens, args);
936 kfree(string);
937
938 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400939 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400940 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400941 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400942 mnt->timeo = 7;
943 mnt->retrans = 5;
944 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400945 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400946 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400947 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400948 mnt->timeo = 600;
949 mnt->retrans = 2;
950 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400951 case Opt_xprt_rdma:
952 /* vector side protocols to TCP */
953 mnt->flags |= NFS_MOUNT_TCP;
954 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
955 mnt->timeo = 600;
956 mnt->retrans = 2;
957 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958 default:
959 goto out_unrec_xprt;
960 }
961 break;
962 case Opt_mountproto:
963 string = match_strdup(args);
964 if (string == NULL)
965 goto out_nomem;
966 token = match_token(string,
967 nfs_xprt_protocol_tokens, args);
968 kfree(string);
969
970 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400971 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400972 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400973 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400974 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400975 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400976 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400977 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400978 default:
979 goto out_unrec_xprt;
980 }
981 break;
982 case Opt_addr:
983 string = match_strdup(args);
984 if (string == NULL)
985 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -0500986 nfs_parse_server_address(string, (struct sockaddr *)
987 &mnt->nfs_server.address);
Chuck Leverbf0fd762007-07-01 12:13:44 -0400988 kfree(string);
989 break;
990 case Opt_clientaddr:
991 string = match_strdup(args);
992 if (string == NULL)
993 goto out_nomem;
994 mnt->client_address = string;
995 break;
Chuck Lever33832032007-12-10 14:59:13 -0500996 case Opt_mounthost:
997 string = match_strdup(args);
998 if (string == NULL)
999 goto out_nomem;
1000 mnt->mount_server.hostname = string;
1001 break;
Chuck Lever0ac83772007-09-11 18:01:04 -04001002 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -04001003 string = match_strdup(args);
1004 if (string == NULL)
1005 goto out_nomem;
Chuck Lever9412b922007-12-10 14:59:21 -05001006 nfs_parse_server_address(string, (struct sockaddr *)
1007 &mnt->mount_server.address);
Chuck Leverbf0fd762007-07-01 12:13:44 -04001008 kfree(string);
1009 break;
1010
1011 case Opt_userspace:
1012 case Opt_deprecated:
1013 break;
1014
1015 default:
1016 goto out_unknown;
1017 }
1018 }
1019
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001020 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port);
1021
Chuck Leverbf0fd762007-07-01 12:13:44 -04001022 return 1;
1023
1024out_nomem:
1025 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1026 return 0;
1027
1028out_unrec_vers:
1029 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1030 return 0;
1031
1032out_unrec_xprt:
1033 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1034 return 0;
1035
1036out_unrec_sec:
1037 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1038 return 0;
1039
1040out_unknown:
1041 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1042 return 0;
1043}
1044
1045/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001046 * Use the remote server's MOUNT service to request the NFS file handle
1047 * corresponding to the provided path.
1048 */
1049static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1050 struct nfs_fh *root_fh)
1051{
1052 struct sockaddr_in sin;
1053 int status;
Chuck Lever33832032007-12-10 14:59:13 -05001054 char *hostname;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001055
1056 if (args->mount_server.version == 0) {
1057 if (args->flags & NFS_MOUNT_VER3)
1058 args->mount_server.version = NFS_MNT3_VERSION;
1059 else
1060 args->mount_server.version = NFS_MNT_VERSION;
1061 }
1062
Chuck Lever33832032007-12-10 14:59:13 -05001063 if (args->mount_server.hostname)
1064 hostname = args->mount_server.hostname;
1065 else
1066 hostname = args->nfs_server.hostname;
1067
Chuck Lever0076d7b2007-07-01 12:13:49 -04001068 /*
1069 * Construct the mount server's address.
1070 */
1071 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1072 sin = args->mount_server.address;
1073 else
1074 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001075 /*
1076 * autobind will be used if mount_server.port == 0
1077 */
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001078 nfs_set_port((struct sockaddr *)&sin, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001079
1080 /*
1081 * Now ask the mount server to map our export path
1082 * to a file handle.
1083 */
1084 status = nfs_mount((struct sockaddr *) &sin,
1085 sizeof(sin),
Chuck Lever33832032007-12-10 14:59:13 -05001086 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001087 args->nfs_server.export_path,
1088 args->mount_server.version,
1089 args->mount_server.protocol,
1090 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001091 if (status == 0)
1092 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001093
Chuck Lever33832032007-12-10 14:59:13 -05001094 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1095 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001096 return status;
1097}
1098
1099/*
David Howells54ceac42006-08-22 20:06:13 -04001100 * Validate the NFS2/NFS3 mount data
1101 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001102 *
1103 * For option strings, user space handles the following behaviors:
1104 *
1105 * + DNS: mapping server host name to IP address ("addr=" option)
1106 *
1107 * + failure mode: how to behave if a mount request can't be handled
1108 * immediately ("fg/bg" option)
1109 *
1110 * + retry: how often to retry a mount request ("retry=" option)
1111 *
1112 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1113 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001114 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001115static int nfs_validate_mount_data(void *options,
1116 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001117 struct nfs_fh *mntfh,
1118 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001119{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001120 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001121
Russell Kingf16c9602007-11-16 22:13:24 +00001122 memset(args, 0, sizeof(*args));
1123
Chuck Lever5df36e72007-07-01 12:12:56 -04001124 if (data == NULL)
1125 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001126
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001127 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1128 args->rsize = NFS_MAX_FILE_IO_SIZE;
1129 args->wsize = NFS_MAX_FILE_IO_SIZE;
1130 args->timeo = 600;
1131 args->retrans = 2;
1132 args->acregmin = 3;
1133 args->acregmax = 60;
1134 args->acdirmin = 30;
1135 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001136 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001137 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001138
David Howellsf7b422b2006-06-09 09:34:33 -04001139 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001140 case 1:
1141 data->namlen = 0;
1142 case 2:
1143 data->bsize = 0;
1144 case 3:
1145 if (data->flags & NFS_MOUNT_VER3)
1146 goto out_no_v3;
1147 data->root.size = NFS2_FHSIZE;
1148 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1149 case 4:
1150 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1151 goto out_no_sec;
1152 case 5:
1153 memset(data->context, 0, sizeof(data->context));
1154 case 6:
1155 if (data->flags & NFS_MOUNT_VER3)
1156 mntfh->size = data->root.size;
1157 else
1158 mntfh->size = NFS2_FHSIZE;
1159
1160 if (mntfh->size > sizeof(mntfh->data))
1161 goto out_invalid_fh;
1162
1163 memcpy(mntfh->data, data->root.data, mntfh->size);
1164 if (mntfh->size < sizeof(mntfh->data))
1165 memset(mntfh->data + mntfh->size, 0,
1166 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001167
1168 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1169 goto out_no_address;
1170
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001171 /*
1172 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1173 * can deal with.
1174 */
1175 args->flags = data->flags;
1176 args->rsize = data->rsize;
1177 args->wsize = data->wsize;
1178 args->flags = data->flags;
1179 args->timeo = data->timeo;
1180 args->retrans = data->retrans;
1181 args->acregmin = data->acregmin;
1182 args->acregmax = data->acregmax;
1183 args->acdirmin = data->acdirmin;
1184 args->acdirmax = data->acdirmax;
1185 args->nfs_server.address = data->addr;
1186 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001187 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001188 /* N.B. caller will free nfs_server.hostname in all cases */
1189 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1190 args->namlen = data->namlen;
1191 args->bsize = data->bsize;
1192 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001193 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001194 default: {
1195 unsigned int len;
1196 char *c;
1197 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001198
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001199 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001200 return -EINVAL;
1201
Chuck Lever6e88e062007-09-24 15:39:50 -04001202 if (!nfs_verify_server_address((struct sockaddr *)
1203 &args->nfs_server.address))
1204 goto out_no_address;
1205
Chuck Lever136d5582007-07-01 12:13:54 -04001206 c = strchr(dev_name, ':');
1207 if (c == NULL)
1208 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001209 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001210 /* N.B. caller will free nfs_server.hostname in all cases */
1211 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001212
1213 c++;
1214 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001215 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001216 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001217
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001218 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001219 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001220 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001221
Chuck Lever136d5582007-07-01 12:13:54 -04001222 break;
1223 }
David Howellsf7b422b2006-06-09 09:34:33 -04001224 }
David Howells54ceac42006-08-22 20:06:13 -04001225
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001226 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1227 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001228
David Howellsf7b422b2006-06-09 09:34:33 -04001229#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001230 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001231 goto out_v3_not_compiled;
1232#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001233
David Howells54ceac42006-08-22 20:06:13 -04001234 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001235
1236out_no_data:
1237 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1238 return -EINVAL;
1239
1240out_no_v3:
1241 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1242 data->version);
1243 return -EINVAL;
1244
1245out_no_sec:
1246 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1247 return -EINVAL;
1248
Chuck Lever5df36e72007-07-01 12:12:56 -04001249#ifndef CONFIG_NFS_V3
1250out_v3_not_compiled:
1251 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1252 return -EPROTONOSUPPORT;
1253#endif /* !CONFIG_NFS_V3 */
1254
1255out_no_address:
1256 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1257 return -EINVAL;
1258
1259out_invalid_fh:
1260 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1261 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001262}
1263
1264/*
1265 * Initialise the common bits of the superblock
1266 */
1267static inline void nfs_initialise_sb(struct super_block *sb)
1268{
1269 struct nfs_server *server = NFS_SB(sb);
1270
1271 sb->s_magic = NFS_SUPER_MAGIC;
1272
1273 /* We probably want something more informative here */
1274 snprintf(sb->s_id, sizeof(sb->s_id),
1275 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1276
1277 if (sb->s_blocksize == 0)
1278 sb->s_blocksize = nfs_block_bits(server->wsize,
1279 &sb->s_blocksize_bits);
1280
1281 if (server->flags & NFS_MOUNT_NOAC)
1282 sb->s_flags |= MS_SYNCHRONOUS;
1283
1284 nfs_super_set_maxbytes(sb, server->maxfilesize);
1285}
1286
1287/*
1288 * Finish setting up an NFS2/3 superblock
1289 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001290static void nfs_fill_super(struct super_block *sb,
1291 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001292{
1293 struct nfs_server *server = NFS_SB(sb);
1294
1295 sb->s_blocksize_bits = 0;
1296 sb->s_blocksize = 0;
1297 if (data->bsize)
1298 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1299
1300 if (server->flags & NFS_MOUNT_VER3) {
1301 /* The VFS shouldn't apply the umask to mode bits. We will do
1302 * so ourselves when necessary.
1303 */
1304 sb->s_flags |= MS_POSIXACL;
1305 sb->s_time_gran = 1;
1306 }
1307
1308 sb->s_op = &nfs_sops;
1309 nfs_initialise_sb(sb);
1310}
1311
1312/*
1313 * Finish setting up a cloned NFS2/3 superblock
1314 */
1315static void nfs_clone_super(struct super_block *sb,
1316 const struct super_block *old_sb)
1317{
1318 struct nfs_server *server = NFS_SB(sb);
1319
1320 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1321 sb->s_blocksize = old_sb->s_blocksize;
1322 sb->s_maxbytes = old_sb->s_maxbytes;
1323
1324 if (server->flags & NFS_MOUNT_VER3) {
1325 /* The VFS shouldn't apply the umask to mode bits. We will do
1326 * so ourselves when necessary.
1327 */
1328 sb->s_flags |= MS_POSIXACL;
1329 sb->s_time_gran = 1;
1330 }
1331
1332 sb->s_op = old_sb->s_op;
1333 nfs_initialise_sb(sb);
1334}
1335
Trond Myklebust275a5d22007-05-16 16:53:28 -04001336#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1337
1338static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1339{
1340 const struct nfs_server *a = s->s_fs_info;
1341 const struct rpc_clnt *clnt_a = a->client;
1342 const struct rpc_clnt *clnt_b = b->client;
1343
1344 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1345 goto Ebusy;
1346 if (a->nfs_client != b->nfs_client)
1347 goto Ebusy;
1348 if (a->flags != b->flags)
1349 goto Ebusy;
1350 if (a->wsize != b->wsize)
1351 goto Ebusy;
1352 if (a->rsize != b->rsize)
1353 goto Ebusy;
1354 if (a->acregmin != b->acregmin)
1355 goto Ebusy;
1356 if (a->acregmax != b->acregmax)
1357 goto Ebusy;
1358 if (a->acdirmin != b->acdirmin)
1359 goto Ebusy;
1360 if (a->acdirmax != b->acdirmax)
1361 goto Ebusy;
1362 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1363 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001364 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001365Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001366 return 0;
1367}
1368
1369struct nfs_sb_mountdata {
1370 struct nfs_server *server;
1371 int mntflags;
1372};
1373
1374static int nfs_set_super(struct super_block *s, void *data)
1375{
1376 struct nfs_sb_mountdata *sb_mntdata = data;
1377 struct nfs_server *server = sb_mntdata->server;
1378 int ret;
1379
1380 s->s_flags = sb_mntdata->mntflags;
1381 s->s_fs_info = server;
1382 ret = set_anon_super(s, server);
1383 if (ret == 0)
1384 server->s_dev = s->s_dev;
1385 return ret;
1386}
1387
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001388static int nfs_compare_super_address(struct nfs_server *server1,
1389 struct nfs_server *server2)
1390{
1391 struct sockaddr *sap1, *sap2;
1392
1393 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1394 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1395
1396 if (sap1->sa_family != sap2->sa_family)
1397 return 0;
1398
1399 switch (sap1->sa_family) {
1400 case AF_INET: {
1401 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1402 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1403 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1404 return 0;
1405 if (sin1->sin_port != sin2->sin_port)
1406 return 0;
1407 break;
1408 }
1409 case AF_INET6: {
1410 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1411 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1412 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1413 return 0;
1414 if (sin1->sin6_port != sin2->sin6_port)
1415 return 0;
1416 break;
1417 }
1418 default:
1419 return 0;
1420 }
1421
1422 return 1;
1423}
1424
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001425static int nfs_compare_super(struct super_block *sb, void *data)
1426{
1427 struct nfs_sb_mountdata *sb_mntdata = data;
1428 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1429 int mntflags = sb_mntdata->mntflags;
1430
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001431 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001432 return 0;
1433 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1434 if (old->flags & NFS_MOUNT_UNSHARED)
1435 return 0;
1436 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1437 return 0;
1438 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001439}
1440
David Howells54ceac42006-08-22 20:06:13 -04001441static int nfs_get_sb(struct file_system_type *fs_type,
1442 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1443{
1444 struct nfs_server *server = NULL;
1445 struct super_block *s;
1446 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001447 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001448 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001449 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001450 struct nfs_sb_mountdata sb_mntdata = {
1451 .mntflags = flags,
1452 };
David Howells54ceac42006-08-22 20:06:13 -04001453 int error;
1454
1455 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001456 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001457 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001458 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001459
1460 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001461 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001462 if (IS_ERR(server)) {
1463 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001464 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001465 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001466 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001467
Trond Myklebust75180df2007-05-16 16:53:28 -04001468 if (server->flags & NFS_MOUNT_UNSHARED)
1469 compare_super = NULL;
1470
David Howells54ceac42006-08-22 20:06:13 -04001471 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001472 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001473 if (IS_ERR(s)) {
1474 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001475 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001476 }
1477
David Howells54ceac42006-08-22 20:06:13 -04001478 if (s->s_fs_info != server) {
1479 nfs_free_server(server);
1480 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001481 }
David Howells54ceac42006-08-22 20:06:13 -04001482
1483 if (!s->s_root) {
1484 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001485 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001486 }
1487
1488 mntroot = nfs_get_root(s, &mntfh);
1489 if (IS_ERR(mntroot)) {
1490 error = PTR_ERR(mntroot);
1491 goto error_splat_super;
1492 }
1493
David Howellsf7b422b2006-06-09 09:34:33 -04001494 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001495 mnt->mnt_sb = s;
1496 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001497 error = 0;
1498
1499out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001500 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001501 kfree(data.mount_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001502 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001503
David Howells54ceac42006-08-22 20:06:13 -04001504out_err_nosb:
1505 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001506 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001507
1508error_splat_super:
1509 up_write(&s->s_umount);
1510 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001511 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001512}
1513
David Howells54ceac42006-08-22 20:06:13 -04001514/*
1515 * Destroy an NFS2/3 superblock
1516 */
David Howellsf7b422b2006-06-09 09:34:33 -04001517static void nfs_kill_super(struct super_block *s)
1518{
1519 struct nfs_server *server = NFS_SB(s);
1520
1521 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001522 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001523}
1524
David Howells54ceac42006-08-22 20:06:13 -04001525/*
1526 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1527 */
1528static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1529 const char *dev_name, void *raw_data,
1530 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001531{
1532 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001533 struct super_block *s;
1534 struct nfs_server *server;
1535 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001536 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001537 struct nfs_sb_mountdata sb_mntdata = {
1538 .mntflags = flags,
1539 };
David Howells54ceac42006-08-22 20:06:13 -04001540 int error;
1541
1542 dprintk("--> nfs_xdev_get_sb()\n");
1543
1544 /* create a new volume representation */
1545 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1546 if (IS_ERR(server)) {
1547 error = PTR_ERR(server);
1548 goto out_err_noserver;
1549 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001550 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001551
Trond Myklebust75180df2007-05-16 16:53:28 -04001552 if (server->flags & NFS_MOUNT_UNSHARED)
1553 compare_super = NULL;
1554
David Howells54ceac42006-08-22 20:06:13 -04001555 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001556 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001557 if (IS_ERR(s)) {
1558 error = PTR_ERR(s);
1559 goto out_err_nosb;
1560 }
1561
1562 if (s->s_fs_info != server) {
1563 nfs_free_server(server);
1564 server = NULL;
1565 }
1566
1567 if (!s->s_root) {
1568 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001569 nfs_clone_super(s, data->sb);
1570 }
1571
1572 mntroot = nfs_get_root(s, data->fh);
1573 if (IS_ERR(mntroot)) {
1574 error = PTR_ERR(mntroot);
1575 goto error_splat_super;
1576 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001577 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001578 dput(mntroot);
1579 error = -ESTALE;
1580 goto error_splat_super;
1581 }
David Howells54ceac42006-08-22 20:06:13 -04001582
1583 s->s_flags |= MS_ACTIVE;
1584 mnt->mnt_sb = s;
1585 mnt->mnt_root = mntroot;
1586
1587 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1588 return 0;
1589
1590out_err_nosb:
1591 nfs_free_server(server);
1592out_err_noserver:
1593 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1594 return error;
1595
1596error_splat_super:
1597 up_write(&s->s_umount);
1598 deactivate_super(s);
1599 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1600 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001601}
1602
1603#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001604
1605/*
1606 * Finish setting up a cloned NFS4 superblock
1607 */
1608static void nfs4_clone_super(struct super_block *sb,
1609 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001610{
David Howells54ceac42006-08-22 20:06:13 -04001611 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1612 sb->s_blocksize = old_sb->s_blocksize;
1613 sb->s_maxbytes = old_sb->s_maxbytes;
1614 sb->s_time_gran = 1;
1615 sb->s_op = old_sb->s_op;
1616 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001617}
1618
1619/*
1620 * Set up an NFS4 superblock
1621 */
David Howells54ceac42006-08-22 20:06:13 -04001622static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001623{
David Howellsf7b422b2006-06-09 09:34:33 -04001624 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001625 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001626 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001627}
1628
David Howells54ceac42006-08-22 20:06:13 -04001629/*
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001630 * If the user didn't specify a port, set the port number to
1631 * the NFS version 4 default port.
1632 */
1633static void nfs4_default_port(struct sockaddr *sap)
1634{
1635 switch (sap->sa_family) {
1636 case AF_INET: {
1637 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1638 if (ap->sin_port == 0)
1639 ap->sin_port = htons(NFS_PORT);
1640 break;
1641 }
1642 case AF_INET6: {
1643 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1644 if (ap->sin6_port == 0)
1645 ap->sin6_port = htons(NFS_PORT);
1646 break;
1647 }
1648 }
1649}
1650
1651/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001652 * Validate NFSv4 mount options
1653 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001654static int nfs4_validate_mount_data(void *options,
1655 struct nfs_parsed_mount_data *args,
1656 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001657{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001658 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001659 char *c;
1660
Russell Kingf16c9602007-11-16 22:13:24 +00001661 memset(args, 0, sizeof(*args));
1662
Chuck Leverf0768eb2007-07-01 12:13:01 -04001663 if (data == NULL)
1664 goto out_no_data;
1665
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001666 args->rsize = NFS_MAX_FILE_IO_SIZE;
1667 args->wsize = NFS_MAX_FILE_IO_SIZE;
1668 args->timeo = 600;
1669 args->retrans = 2;
1670 args->acregmin = 3;
1671 args->acregmax = 60;
1672 args->acdirmin = 30;
1673 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001674 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001675
Chuck Leverf0768eb2007-07-01 12:13:01 -04001676 switch (data->version) {
1677 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001678 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001679 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001680 if (copy_from_user(&args->nfs_server.address,
1681 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001682 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001683 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001684 if (!nfs_verify_server_address((struct sockaddr *)
1685 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001686 goto out_no_address;
1687
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001688 nfs4_default_port((struct sockaddr *)
1689 &args->nfs_server.address);
1690
Chuck Leverf0768eb2007-07-01 12:13:01 -04001691 switch (data->auth_flavourlen) {
1692 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001693 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001694 break;
1695 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001696 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001697 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001698 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001699 return -EFAULT;
1700 break;
1701 default:
1702 goto out_inval_auth;
1703 }
1704
1705 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1706 if (IS_ERR(c))
1707 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001708 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001709
1710 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1711 if (IS_ERR(c))
1712 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001713 args->nfs_server.export_path = c;
1714 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001715
1716 c = strndup_user(data->client_addr.data, 16);
1717 if (IS_ERR(c))
1718 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001719 args->client_address = c;
1720
1721 /*
1722 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1723 * can deal with.
1724 */
1725
1726 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1727 args->rsize = data->rsize;
1728 args->wsize = data->wsize;
1729 args->timeo = data->timeo;
1730 args->retrans = data->retrans;
1731 args->acregmin = data->acregmin;
1732 args->acregmax = data->acregmax;
1733 args->acdirmin = data->acdirmin;
1734 args->acdirmax = data->acdirmax;
1735 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001736
1737 break;
Chuck Lever80071222007-07-01 12:13:59 -04001738 default: {
1739 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001740
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001741 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001742 return -EINVAL;
1743
1744 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001745 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001746 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001747
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001748 nfs4_default_port((struct sockaddr *)
1749 &args->nfs_server.address);
1750
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001751 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001752 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001753 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001754 break;
1755 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001756 break;
1757 default:
1758 goto out_inval_auth;
1759 }
1760
1761 /*
Chuck Lever80071222007-07-01 12:13:59 -04001762 * Split "dev_name" into "hostname:mntpath".
1763 */
1764 c = strchr(dev_name, ':');
1765 if (c == NULL)
1766 return -EINVAL;
1767 /* while calculating len, pretend ':' is '\0' */
1768 len = c - dev_name;
1769 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001770 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001771 /* N.B. caller will free nfs_server.hostname in all cases */
1772 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001773
1774 c++; /* step over the ':' */
1775 len = strlen(c);
1776 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001777 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001778 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001779
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001780 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001781
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001782 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001783 goto out_no_client_address;
1784
Chuck Lever80071222007-07-01 12:13:59 -04001785 break;
1786 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001787 }
1788
1789 return 0;
1790
1791out_no_data:
1792 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1793 return -EINVAL;
1794
1795out_inval_auth:
1796 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1797 data->auth_flavourlen);
1798 return -EINVAL;
1799
1800out_no_address:
1801 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1802 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001803
1804out_no_client_address:
1805 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1806 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001807}
1808
1809/*
David Howells54ceac42006-08-22 20:06:13 -04001810 * Get the superblock for an NFS4 mountpoint
1811 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001812static int nfs4_get_sb(struct file_system_type *fs_type,
1813 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001814{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001815 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001816 struct super_block *s;
1817 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001818 struct nfs_fh mntfh;
1819 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001820 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001821 struct nfs_sb_mountdata sb_mntdata = {
1822 .mntflags = flags,
1823 };
David Howells54ceac42006-08-22 20:06:13 -04001824 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001825
Chuck Leverf0768eb2007-07-01 12:13:01 -04001826 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001827 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001828 if (error < 0)
1829 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001830
David Howells54ceac42006-08-22 20:06:13 -04001831 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001832 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001833 if (IS_ERR(server)) {
1834 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001835 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001836 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001837 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001838
Trond Myklebust75180df2007-05-16 16:53:28 -04001839 if (server->flags & NFS4_MOUNT_UNSHARED)
1840 compare_super = NULL;
1841
David Howells54ceac42006-08-22 20:06:13 -04001842 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001843 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001844 if (IS_ERR(s)) {
1845 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001846 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001847 }
1848
Trond Myklebust5dd31772006-08-24 01:03:05 -04001849 if (s->s_fs_info != server) {
1850 nfs_free_server(server);
1851 server = NULL;
1852 }
1853
David Howells54ceac42006-08-22 20:06:13 -04001854 if (!s->s_root) {
1855 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001856 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001857 }
David Howellsf7b422b2006-06-09 09:34:33 -04001858
David Howells54ceac42006-08-22 20:06:13 -04001859 mntroot = nfs4_get_root(s, &mntfh);
1860 if (IS_ERR(mntroot)) {
1861 error = PTR_ERR(mntroot);
1862 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001863 }
David Howells54ceac42006-08-22 20:06:13 -04001864
David Howellsf7b422b2006-06-09 09:34:33 -04001865 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001866 mnt->mnt_sb = s;
1867 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001868 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001869
Chuck Lever29eb9812007-07-01 12:12:30 -04001870out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001871 kfree(data.client_address);
1872 kfree(data.nfs_server.export_path);
1873 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001874 return error;
David Howells54ceac42006-08-22 20:06:13 -04001875
Chuck Lever29eb9812007-07-01 12:12:30 -04001876out_free:
1877 nfs_free_server(server);
1878 goto out;
1879
David Howells54ceac42006-08-22 20:06:13 -04001880error_splat_super:
1881 up_write(&s->s_umount);
1882 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001883 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001884}
1885
1886static void nfs4_kill_super(struct super_block *sb)
1887{
1888 struct nfs_server *server = NFS_SB(sb);
1889
1890 nfs_return_all_delegations(sb);
1891 kill_anon_super(sb);
1892
1893 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001894 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001895}
1896
1897/*
David Howells54ceac42006-08-22 20:06:13 -04001898 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001899 */
David Howells54ceac42006-08-22 20:06:13 -04001900static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1901 const char *dev_name, void *raw_data,
1902 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001903{
1904 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001905 struct super_block *s;
1906 struct nfs_server *server;
1907 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001908 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001909 struct nfs_sb_mountdata sb_mntdata = {
1910 .mntflags = flags,
1911 };
David Howells54ceac42006-08-22 20:06:13 -04001912 int error;
1913
1914 dprintk("--> nfs4_xdev_get_sb()\n");
1915
1916 /* create a new volume representation */
1917 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1918 if (IS_ERR(server)) {
1919 error = PTR_ERR(server);
1920 goto out_err_noserver;
1921 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001922 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001923
Trond Myklebust75180df2007-05-16 16:53:28 -04001924 if (server->flags & NFS4_MOUNT_UNSHARED)
1925 compare_super = NULL;
1926
David Howells54ceac42006-08-22 20:06:13 -04001927 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001928 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001929 if (IS_ERR(s)) {
1930 error = PTR_ERR(s);
1931 goto out_err_nosb;
1932 }
1933
1934 if (s->s_fs_info != server) {
1935 nfs_free_server(server);
1936 server = NULL;
1937 }
1938
1939 if (!s->s_root) {
1940 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001941 nfs4_clone_super(s, data->sb);
1942 }
1943
1944 mntroot = nfs4_get_root(s, data->fh);
1945 if (IS_ERR(mntroot)) {
1946 error = PTR_ERR(mntroot);
1947 goto error_splat_super;
1948 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001949 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1950 dput(mntroot);
1951 error = -ESTALE;
1952 goto error_splat_super;
1953 }
David Howells54ceac42006-08-22 20:06:13 -04001954
1955 s->s_flags |= MS_ACTIVE;
1956 mnt->mnt_sb = s;
1957 mnt->mnt_root = mntroot;
1958
1959 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1960 return 0;
1961
1962out_err_nosb:
1963 nfs_free_server(server);
1964out_err_noserver:
1965 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1966 return error;
1967
1968error_splat_super:
1969 up_write(&s->s_umount);
1970 deactivate_super(s);
1971 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1972 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001973}
1974
David Howells54ceac42006-08-22 20:06:13 -04001975/*
1976 * Create an NFS4 server record on referral traversal
1977 */
1978static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1979 const char *dev_name, void *raw_data,
1980 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001981{
1982 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001983 struct super_block *s;
1984 struct nfs_server *server;
1985 struct dentry *mntroot;
1986 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001987 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001988 struct nfs_sb_mountdata sb_mntdata = {
1989 .mntflags = flags,
1990 };
David Howells54ceac42006-08-22 20:06:13 -04001991 int error;
1992
1993 dprintk("--> nfs4_referral_get_sb()\n");
1994
1995 /* create a new volume representation */
1996 server = nfs4_create_referral_server(data, &mntfh);
1997 if (IS_ERR(server)) {
1998 error = PTR_ERR(server);
1999 goto out_err_noserver;
2000 }
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 & NFS4_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(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04002008 if (IS_ERR(s)) {
2009 error = PTR_ERR(s);
2010 goto out_err_nosb;
2011 }
2012
2013 if (s->s_fs_info != server) {
2014 nfs_free_server(server);
2015 server = NULL;
2016 }
2017
2018 if (!s->s_root) {
2019 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002020 nfs4_fill_super(s);
2021 }
2022
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002023 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002024 if (IS_ERR(mntroot)) {
2025 error = PTR_ERR(mntroot);
2026 goto error_splat_super;
2027 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002028 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2029 dput(mntroot);
2030 error = -ESTALE;
2031 goto error_splat_super;
2032 }
David Howells54ceac42006-08-22 20:06:13 -04002033
2034 s->s_flags |= MS_ACTIVE;
2035 mnt->mnt_sb = s;
2036 mnt->mnt_root = mntroot;
2037
2038 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2039 return 0;
2040
2041out_err_nosb:
2042 nfs_free_server(server);
2043out_err_noserver:
2044 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2045 return error;
2046
2047error_splat_super:
2048 up_write(&s->s_umount);
2049 deactivate_super(s);
2050 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2051 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002052}
2053
David Howells54ceac42006-08-22 20:06:13 -04002054#endif /* CONFIG_NFS_V4 */