blob: f120be43d543931ce71d2a3edb32257f1a500612 [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 Leverbf0fd762007-07-01 12:13:44 -0400644 * Error-check and convert a string of mount options from user space into
645 * a data structure
646 */
647static int nfs_parse_mount_options(char *raw,
648 struct nfs_parsed_mount_data *mnt)
649{
650 char *p, *string;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500651 unsigned short port = 0;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400652
653 if (!raw) {
654 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
655 return 1;
656 }
657 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
658
659 while ((p = strsep(&raw, ",")) != NULL) {
660 substring_t args[MAX_OPT_ARGS];
661 int option, token;
662
663 if (!*p)
664 continue;
665
666 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
667
668 token = match_token(p, nfs_mount_option_tokens, args);
669 switch (token) {
670 case Opt_soft:
671 mnt->flags |= NFS_MOUNT_SOFT;
672 break;
673 case Opt_hard:
674 mnt->flags &= ~NFS_MOUNT_SOFT;
675 break;
676 case Opt_intr:
677 mnt->flags |= NFS_MOUNT_INTR;
678 break;
679 case Opt_nointr:
680 mnt->flags &= ~NFS_MOUNT_INTR;
681 break;
682 case Opt_posix:
683 mnt->flags |= NFS_MOUNT_POSIX;
684 break;
685 case Opt_noposix:
686 mnt->flags &= ~NFS_MOUNT_POSIX;
687 break;
688 case Opt_cto:
689 mnt->flags &= ~NFS_MOUNT_NOCTO;
690 break;
691 case Opt_nocto:
692 mnt->flags |= NFS_MOUNT_NOCTO;
693 break;
694 case Opt_ac:
695 mnt->flags &= ~NFS_MOUNT_NOAC;
696 break;
697 case Opt_noac:
698 mnt->flags |= NFS_MOUNT_NOAC;
699 break;
700 case Opt_lock:
701 mnt->flags &= ~NFS_MOUNT_NONLM;
702 break;
703 case Opt_nolock:
704 mnt->flags |= NFS_MOUNT_NONLM;
705 break;
706 case Opt_v2:
707 mnt->flags &= ~NFS_MOUNT_VER3;
708 break;
709 case Opt_v3:
710 mnt->flags |= NFS_MOUNT_VER3;
711 break;
712 case Opt_udp:
713 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400714 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400715 mnt->timeo = 7;
716 mnt->retrans = 5;
717 break;
718 case Opt_tcp:
719 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400720 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400721 mnt->timeo = 600;
722 mnt->retrans = 2;
723 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400724 case Opt_rdma:
725 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
726 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
727 mnt->timeo = 600;
728 mnt->retrans = 2;
729 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400730 case Opt_acl:
731 mnt->flags &= ~NFS_MOUNT_NOACL;
732 break;
733 case Opt_noacl:
734 mnt->flags |= NFS_MOUNT_NOACL;
735 break;
736 case Opt_rdirplus:
737 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
738 break;
739 case Opt_nordirplus:
740 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
741 break;
Trond Myklebust75180df2007-05-16 16:53:28 -0400742 case Opt_sharecache:
743 mnt->flags &= ~NFS_MOUNT_UNSHARED;
744 break;
745 case Opt_nosharecache:
746 mnt->flags |= NFS_MOUNT_UNSHARED;
747 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400748
749 case Opt_port:
750 if (match_int(args, &option))
751 return 0;
752 if (option < 0 || option > 65535)
753 return 0;
Chuck Lever04dcd6e2007-12-10 14:57:53 -0500754 port = option;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400755 break;
756 case Opt_rsize:
757 if (match_int(args, &mnt->rsize))
758 return 0;
759 break;
760 case Opt_wsize:
761 if (match_int(args, &mnt->wsize))
762 return 0;
763 break;
764 case Opt_bsize:
765 if (match_int(args, &option))
766 return 0;
767 if (option < 0)
768 return 0;
769 mnt->bsize = option;
770 break;
771 case Opt_timeo:
772 if (match_int(args, &mnt->timeo))
773 return 0;
774 break;
775 case Opt_retrans:
776 if (match_int(args, &mnt->retrans))
777 return 0;
778 break;
779 case Opt_acregmin:
780 if (match_int(args, &mnt->acregmin))
781 return 0;
782 break;
783 case Opt_acregmax:
784 if (match_int(args, &mnt->acregmax))
785 return 0;
786 break;
787 case Opt_acdirmin:
788 if (match_int(args, &mnt->acdirmin))
789 return 0;
790 break;
791 case Opt_acdirmax:
792 if (match_int(args, &mnt->acdirmax))
793 return 0;
794 break;
795 case Opt_actimeo:
796 if (match_int(args, &option))
797 return 0;
798 if (option < 0)
799 return 0;
800 mnt->acregmin =
801 mnt->acregmax =
802 mnt->acdirmin =
803 mnt->acdirmax = option;
804 break;
805 case Opt_namelen:
806 if (match_int(args, &mnt->namlen))
807 return 0;
808 break;
809 case Opt_mountport:
810 if (match_int(args, &option))
811 return 0;
812 if (option < 0 || option > 65535)
813 return 0;
814 mnt->mount_server.port = option;
815 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400816 case Opt_mountvers:
817 if (match_int(args, &option))
818 return 0;
819 if (option < 0)
820 return 0;
821 mnt->mount_server.version = option;
822 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400823 case Opt_nfsvers:
824 if (match_int(args, &option))
825 return 0;
826 switch (option) {
827 case 2:
828 mnt->flags &= ~NFS_MOUNT_VER3;
829 break;
830 case 3:
831 mnt->flags |= NFS_MOUNT_VER3;
832 break;
833 default:
834 goto out_unrec_vers;
835 }
836 break;
837
838 case Opt_sec:
839 string = match_strdup(args);
840 if (string == NULL)
841 goto out_nomem;
842 token = match_token(string, nfs_secflavor_tokens, args);
843 kfree(string);
844
845 /*
846 * The flags setting is for v2/v3. The flavor_len
847 * setting is for v4. v2/v3 also need to know the
848 * difference between NULL and UNIX.
849 */
850 switch (token) {
851 case Opt_sec_none:
852 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 0;
854 mnt->auth_flavors[0] = RPC_AUTH_NULL;
855 break;
856 case Opt_sec_sys:
857 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 0;
859 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
860 break;
861 case Opt_sec_krb5:
862 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
863 mnt->auth_flavor_len = 1;
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
865 break;
866 case Opt_sec_krb5i:
867 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
868 mnt->auth_flavor_len = 1;
869 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
870 break;
871 case Opt_sec_krb5p:
872 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
873 mnt->auth_flavor_len = 1;
874 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
875 break;
876 case Opt_sec_lkey:
877 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
878 mnt->auth_flavor_len = 1;
879 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
880 break;
881 case Opt_sec_lkeyi:
882 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
883 mnt->auth_flavor_len = 1;
884 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
885 break;
886 case Opt_sec_lkeyp:
887 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
888 mnt->auth_flavor_len = 1;
889 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
890 break;
891 case Opt_sec_spkm:
892 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
893 mnt->auth_flavor_len = 1;
894 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
895 break;
896 case Opt_sec_spkmi:
897 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
898 mnt->auth_flavor_len = 1;
899 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
900 break;
901 case Opt_sec_spkmp:
902 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
903 mnt->auth_flavor_len = 1;
904 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
905 break;
906 default:
907 goto out_unrec_sec;
908 }
909 break;
910 case Opt_proto:
911 string = match_strdup(args);
912 if (string == NULL)
913 goto out_nomem;
914 token = match_token(string,
915 nfs_xprt_protocol_tokens, args);
916 kfree(string);
917
918 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400919 case Opt_xprt_udp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400920 mnt->flags &= ~NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400921 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400922 mnt->timeo = 7;
923 mnt->retrans = 5;
924 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400925 case Opt_xprt_tcp:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400926 mnt->flags |= NFS_MOUNT_TCP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400927 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400928 mnt->timeo = 600;
929 mnt->retrans = 2;
930 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400931 case Opt_xprt_rdma:
932 /* vector side protocols to TCP */
933 mnt->flags |= NFS_MOUNT_TCP;
934 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
935 mnt->timeo = 600;
936 mnt->retrans = 2;
937 break;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400938 default:
939 goto out_unrec_xprt;
940 }
941 break;
942 case Opt_mountproto:
943 string = match_strdup(args);
944 if (string == NULL)
945 goto out_nomem;
946 token = match_token(string,
947 nfs_xprt_protocol_tokens, args);
948 kfree(string);
949
950 switch (token) {
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400951 case Opt_xprt_udp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400952 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400953 break;
Chuck Leverfdb66ff2007-08-29 17:58:57 -0400954 case Opt_xprt_tcp:
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -0400955 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
Chuck Leverbf0fd762007-07-01 12:13:44 -0400956 break;
\"Talpey, Thomas\2cf7ff72007-09-10 13:49:41 -0400957 case Opt_xprt_rdma: /* not used for side protocols */
Chuck Leverbf0fd762007-07-01 12:13:44 -0400958 default:
959 goto out_unrec_xprt;
960 }
961 break;
962 case Opt_addr:
963 string = match_strdup(args);
964 if (string == NULL)
965 goto out_nomem;
966 mnt->nfs_server.address.sin_family = AF_INET;
967 mnt->nfs_server.address.sin_addr.s_addr =
968 in_aton(string);
969 kfree(string);
970 break;
971 case Opt_clientaddr:
972 string = match_strdup(args);
973 if (string == NULL)
974 goto out_nomem;
975 mnt->client_address = string;
976 break;
Chuck Lever33832032007-12-10 14:59:13 -0500977 case Opt_mounthost:
978 string = match_strdup(args);
979 if (string == NULL)
980 goto out_nomem;
981 mnt->mount_server.hostname = string;
982 break;
Chuck Lever0ac83772007-09-11 18:01:04 -0400983 case Opt_mountaddr:
Chuck Leverbf0fd762007-07-01 12:13:44 -0400984 string = match_strdup(args);
985 if (string == NULL)
986 goto out_nomem;
987 mnt->mount_server.address.sin_family = AF_INET;
988 mnt->mount_server.address.sin_addr.s_addr =
989 in_aton(string);
990 kfree(string);
991 break;
992
993 case Opt_userspace:
994 case Opt_deprecated:
995 break;
996
997 default:
998 goto out_unknown;
999 }
1000 }
1001
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001002 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port);
1003
Chuck Leverbf0fd762007-07-01 12:13:44 -04001004 return 1;
1005
1006out_nomem:
1007 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1008 return 0;
1009
1010out_unrec_vers:
1011 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
1012 return 0;
1013
1014out_unrec_xprt:
1015 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
1016 return 0;
1017
1018out_unrec_sec:
1019 printk(KERN_INFO "NFS: unrecognized security flavor\n");
1020 return 0;
1021
1022out_unknown:
1023 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
1024 return 0;
1025}
1026
1027/*
Chuck Lever0076d7b2007-07-01 12:13:49 -04001028 * Use the remote server's MOUNT service to request the NFS file handle
1029 * corresponding to the provided path.
1030 */
1031static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1032 struct nfs_fh *root_fh)
1033{
1034 struct sockaddr_in sin;
1035 int status;
Chuck Lever33832032007-12-10 14:59:13 -05001036 char *hostname;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001037
1038 if (args->mount_server.version == 0) {
1039 if (args->flags & NFS_MOUNT_VER3)
1040 args->mount_server.version = NFS_MNT3_VERSION;
1041 else
1042 args->mount_server.version = NFS_MNT_VERSION;
1043 }
1044
Chuck Lever33832032007-12-10 14:59:13 -05001045 if (args->mount_server.hostname)
1046 hostname = args->mount_server.hostname;
1047 else
1048 hostname = args->nfs_server.hostname;
1049
Chuck Lever0076d7b2007-07-01 12:13:49 -04001050 /*
1051 * Construct the mount server's address.
1052 */
1053 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
1054 sin = args->mount_server.address;
1055 else
1056 sin = args->nfs_server.address;
James Lentiniaad70002007-09-24 17:32:49 -04001057 /*
1058 * autobind will be used if mount_server.port == 0
1059 */
Chuck Lever04dcd6e2007-12-10 14:57:53 -05001060 nfs_set_port((struct sockaddr *)&sin, args->mount_server.port);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001061
1062 /*
1063 * Now ask the mount server to map our export path
1064 * to a file handle.
1065 */
1066 status = nfs_mount((struct sockaddr *) &sin,
1067 sizeof(sin),
Chuck Lever33832032007-12-10 14:59:13 -05001068 hostname,
Chuck Lever0076d7b2007-07-01 12:13:49 -04001069 args->nfs_server.export_path,
1070 args->mount_server.version,
1071 args->mount_server.protocol,
1072 root_fh);
Chuck Leverefd83402007-09-11 18:00:58 -04001073 if (status == 0)
1074 return 0;
Chuck Lever0076d7b2007-07-01 12:13:49 -04001075
Chuck Lever33832032007-12-10 14:59:13 -05001076 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d",
1077 hostname, status);
Chuck Lever0076d7b2007-07-01 12:13:49 -04001078 return status;
1079}
1080
1081/*
David Howells54ceac42006-08-22 20:06:13 -04001082 * Validate the NFS2/NFS3 mount data
1083 * - fills in the mount root filehandle
Chuck Lever136d5582007-07-01 12:13:54 -04001084 *
1085 * For option strings, user space handles the following behaviors:
1086 *
1087 * + DNS: mapping server host name to IP address ("addr=" option)
1088 *
1089 * + failure mode: how to behave if a mount request can't be handled
1090 * immediately ("fg/bg" option)
1091 *
1092 * + retry: how often to retry a mount request ("retry=" option)
1093 *
1094 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1095 * mountproto=tcp after mountproto=udp, and so on
David Howellsf7b422b2006-06-09 09:34:33 -04001096 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001097static int nfs_validate_mount_data(void *options,
1098 struct nfs_parsed_mount_data *args,
Chuck Lever136d5582007-07-01 12:13:54 -04001099 struct nfs_fh *mntfh,
1100 const char *dev_name)
David Howellsf7b422b2006-06-09 09:34:33 -04001101{
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001102 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
Chuck Lever136d5582007-07-01 12:13:54 -04001103
Russell Kingf16c9602007-11-16 22:13:24 +00001104 memset(args, 0, sizeof(*args));
1105
Chuck Lever5df36e72007-07-01 12:12:56 -04001106 if (data == NULL)
1107 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -04001108
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001109 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1110 args->rsize = NFS_MAX_FILE_IO_SIZE;
1111 args->wsize = NFS_MAX_FILE_IO_SIZE;
1112 args->timeo = 600;
1113 args->retrans = 2;
1114 args->acregmin = 3;
1115 args->acregmax = 60;
1116 args->acdirmin = 30;
1117 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001118 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001119 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001120
David Howellsf7b422b2006-06-09 09:34:33 -04001121 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -04001122 case 1:
1123 data->namlen = 0;
1124 case 2:
1125 data->bsize = 0;
1126 case 3:
1127 if (data->flags & NFS_MOUNT_VER3)
1128 goto out_no_v3;
1129 data->root.size = NFS2_FHSIZE;
1130 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1131 case 4:
1132 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1133 goto out_no_sec;
1134 case 5:
1135 memset(data->context, 0, sizeof(data->context));
1136 case 6:
1137 if (data->flags & NFS_MOUNT_VER3)
1138 mntfh->size = data->root.size;
1139 else
1140 mntfh->size = NFS2_FHSIZE;
1141
1142 if (mntfh->size > sizeof(mntfh->data))
1143 goto out_invalid_fh;
1144
1145 memcpy(mntfh->data, data->root.data, mntfh->size);
1146 if (mntfh->size < sizeof(mntfh->data))
1147 memset(mntfh->data + mntfh->size, 0,
1148 sizeof(mntfh->data) - mntfh->size);
Chuck Lever6e88e062007-09-24 15:39:50 -04001149
1150 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
1151 goto out_no_address;
1152
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001153 /*
1154 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1155 * can deal with.
1156 */
1157 args->flags = data->flags;
1158 args->rsize = data->rsize;
1159 args->wsize = data->wsize;
1160 args->flags = data->flags;
1161 args->timeo = data->timeo;
1162 args->retrans = data->retrans;
1163 args->acregmin = data->acregmin;
1164 args->acregmax = data->acregmax;
1165 args->acdirmin = data->acdirmin;
1166 args->acdirmax = data->acdirmax;
1167 args->nfs_server.address = data->addr;
1168 if (!(data->flags & NFS_MOUNT_TCP))
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001169 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001170 /* N.B. caller will free nfs_server.hostname in all cases */
1171 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1172 args->namlen = data->namlen;
1173 args->bsize = data->bsize;
1174 args->auth_flavors[0] = data->pseudoflavor;
Chuck Lever5df36e72007-07-01 12:12:56 -04001175 break;
Chuck Lever136d5582007-07-01 12:13:54 -04001176 default: {
1177 unsigned int len;
1178 char *c;
1179 int status;
Chuck Lever136d5582007-07-01 12:13:54 -04001180
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001181 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever136d5582007-07-01 12:13:54 -04001182 return -EINVAL;
1183
Chuck Lever6e88e062007-09-24 15:39:50 -04001184 if (!nfs_verify_server_address((struct sockaddr *)
1185 &args->nfs_server.address))
1186 goto out_no_address;
1187
Chuck Lever136d5582007-07-01 12:13:54 -04001188 c = strchr(dev_name, ':');
1189 if (c == NULL)
1190 return -EINVAL;
Chuck Lever350c73a2007-08-29 17:59:01 -04001191 len = c - dev_name;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001192 /* N.B. caller will free nfs_server.hostname in all cases */
1193 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever136d5582007-07-01 12:13:54 -04001194
1195 c++;
1196 if (strlen(c) > NFS_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001197 return -ENAMETOOLONG;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001198 args->nfs_server.export_path = c;
Chuck Lever136d5582007-07-01 12:13:54 -04001199
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001200 status = nfs_try_mount(args, mntfh);
Chuck Lever136d5582007-07-01 12:13:54 -04001201 if (status)
Chuck Leverfdc6e2c2007-08-29 17:58:59 -04001202 return status;
Chuck Lever136d5582007-07-01 12:13:54 -04001203
Chuck Lever136d5582007-07-01 12:13:54 -04001204 break;
1205 }
David Howellsf7b422b2006-06-09 09:34:33 -04001206 }
David Howells54ceac42006-08-22 20:06:13 -04001207
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001208 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1209 args->auth_flavors[0] = RPC_AUTH_UNIX;
Trond Myklebust36b15c52006-08-22 20:06:14 -04001210
David Howellsf7b422b2006-06-09 09:34:33 -04001211#ifndef CONFIG_NFS_V3
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001212 if (args->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -04001213 goto out_v3_not_compiled;
1214#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -04001215
David Howells54ceac42006-08-22 20:06:13 -04001216 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -04001217
1218out_no_data:
1219 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1220 return -EINVAL;
1221
1222out_no_v3:
1223 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1224 data->version);
1225 return -EINVAL;
1226
1227out_no_sec:
1228 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1229 return -EINVAL;
1230
Chuck Lever5df36e72007-07-01 12:12:56 -04001231#ifndef CONFIG_NFS_V3
1232out_v3_not_compiled:
1233 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1234 return -EPROTONOSUPPORT;
1235#endif /* !CONFIG_NFS_V3 */
1236
1237out_no_address:
1238 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1239 return -EINVAL;
1240
1241out_invalid_fh:
1242 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1243 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -04001244}
1245
1246/*
1247 * Initialise the common bits of the superblock
1248 */
1249static inline void nfs_initialise_sb(struct super_block *sb)
1250{
1251 struct nfs_server *server = NFS_SB(sb);
1252
1253 sb->s_magic = NFS_SUPER_MAGIC;
1254
1255 /* We probably want something more informative here */
1256 snprintf(sb->s_id, sizeof(sb->s_id),
1257 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1258
1259 if (sb->s_blocksize == 0)
1260 sb->s_blocksize = nfs_block_bits(server->wsize,
1261 &sb->s_blocksize_bits);
1262
1263 if (server->flags & NFS_MOUNT_NOAC)
1264 sb->s_flags |= MS_SYNCHRONOUS;
1265
1266 nfs_super_set_maxbytes(sb, server->maxfilesize);
1267}
1268
1269/*
1270 * Finish setting up an NFS2/3 superblock
1271 */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001272static void nfs_fill_super(struct super_block *sb,
1273 struct nfs_parsed_mount_data *data)
David Howells54ceac42006-08-22 20:06:13 -04001274{
1275 struct nfs_server *server = NFS_SB(sb);
1276
1277 sb->s_blocksize_bits = 0;
1278 sb->s_blocksize = 0;
1279 if (data->bsize)
1280 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1281
1282 if (server->flags & NFS_MOUNT_VER3) {
1283 /* The VFS shouldn't apply the umask to mode bits. We will do
1284 * so ourselves when necessary.
1285 */
1286 sb->s_flags |= MS_POSIXACL;
1287 sb->s_time_gran = 1;
1288 }
1289
1290 sb->s_op = &nfs_sops;
1291 nfs_initialise_sb(sb);
1292}
1293
1294/*
1295 * Finish setting up a cloned NFS2/3 superblock
1296 */
1297static void nfs_clone_super(struct super_block *sb,
1298 const struct super_block *old_sb)
1299{
1300 struct nfs_server *server = NFS_SB(sb);
1301
1302 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1303 sb->s_blocksize = old_sb->s_blocksize;
1304 sb->s_maxbytes = old_sb->s_maxbytes;
1305
1306 if (server->flags & NFS_MOUNT_VER3) {
1307 /* The VFS shouldn't apply the umask to mode bits. We will do
1308 * so ourselves when necessary.
1309 */
1310 sb->s_flags |= MS_POSIXACL;
1311 sb->s_time_gran = 1;
1312 }
1313
1314 sb->s_op = old_sb->s_op;
1315 nfs_initialise_sb(sb);
1316}
1317
Trond Myklebust275a5d22007-05-16 16:53:28 -04001318#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1319
1320static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1321{
1322 const struct nfs_server *a = s->s_fs_info;
1323 const struct rpc_clnt *clnt_a = a->client;
1324 const struct rpc_clnt *clnt_b = b->client;
1325
1326 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1327 goto Ebusy;
1328 if (a->nfs_client != b->nfs_client)
1329 goto Ebusy;
1330 if (a->flags != b->flags)
1331 goto Ebusy;
1332 if (a->wsize != b->wsize)
1333 goto Ebusy;
1334 if (a->rsize != b->rsize)
1335 goto Ebusy;
1336 if (a->acregmin != b->acregmin)
1337 goto Ebusy;
1338 if (a->acregmax != b->acregmax)
1339 goto Ebusy;
1340 if (a->acdirmin != b->acdirmin)
1341 goto Ebusy;
1342 if (a->acdirmax != b->acdirmax)
1343 goto Ebusy;
1344 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1345 goto Ebusy;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001346 return 1;
Trond Myklebust275a5d22007-05-16 16:53:28 -04001347Ebusy:
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001348 return 0;
1349}
1350
1351struct nfs_sb_mountdata {
1352 struct nfs_server *server;
1353 int mntflags;
1354};
1355
1356static int nfs_set_super(struct super_block *s, void *data)
1357{
1358 struct nfs_sb_mountdata *sb_mntdata = data;
1359 struct nfs_server *server = sb_mntdata->server;
1360 int ret;
1361
1362 s->s_flags = sb_mntdata->mntflags;
1363 s->s_fs_info = server;
1364 ret = set_anon_super(s, server);
1365 if (ret == 0)
1366 server->s_dev = s->s_dev;
1367 return ret;
1368}
1369
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001370static int nfs_compare_super_address(struct nfs_server *server1,
1371 struct nfs_server *server2)
1372{
1373 struct sockaddr *sap1, *sap2;
1374
1375 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1376 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1377
1378 if (sap1->sa_family != sap2->sa_family)
1379 return 0;
1380
1381 switch (sap1->sa_family) {
1382 case AF_INET: {
1383 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1384 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1385 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1386 return 0;
1387 if (sin1->sin_port != sin2->sin_port)
1388 return 0;
1389 break;
1390 }
1391 case AF_INET6: {
1392 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1393 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1394 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1395 return 0;
1396 if (sin1->sin6_port != sin2->sin6_port)
1397 return 0;
1398 break;
1399 }
1400 default:
1401 return 0;
1402 }
1403
1404 return 1;
1405}
1406
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001407static int nfs_compare_super(struct super_block *sb, void *data)
1408{
1409 struct nfs_sb_mountdata *sb_mntdata = data;
1410 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1411 int mntflags = sb_mntdata->mntflags;
1412
Chuck Leverfd00a8f2007-12-10 14:57:38 -05001413 if (!nfs_compare_super_address(old, server))
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001414 return 0;
1415 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1416 if (old->flags & NFS_MOUNT_UNSHARED)
1417 return 0;
1418 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1419 return 0;
1420 return nfs_compare_mount_options(sb, server, mntflags);
Trond Myklebust275a5d22007-05-16 16:53:28 -04001421}
1422
David Howells54ceac42006-08-22 20:06:13 -04001423static int nfs_get_sb(struct file_system_type *fs_type,
1424 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1425{
1426 struct nfs_server *server = NULL;
1427 struct super_block *s;
1428 struct nfs_fh mntfh;
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001429 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001430 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001431 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001432 struct nfs_sb_mountdata sb_mntdata = {
1433 .mntflags = flags,
1434 };
David Howells54ceac42006-08-22 20:06:13 -04001435 int error;
1436
1437 /* Validate the mount data */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001438 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
David Howells54ceac42006-08-22 20:06:13 -04001439 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -04001440 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001441
1442 /* Get a volume representation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001443 server = nfs_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001444 if (IS_ERR(server)) {
1445 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -04001446 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001447 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001448 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001449
Trond Myklebust75180df2007-05-16 16:53:28 -04001450 if (server->flags & NFS_MOUNT_UNSHARED)
1451 compare_super = NULL;
1452
David Howells54ceac42006-08-22 20:06:13 -04001453 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001454 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001455 if (IS_ERR(s)) {
1456 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -04001457 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -04001458 }
1459
David Howells54ceac42006-08-22 20:06:13 -04001460 if (s->s_fs_info != server) {
1461 nfs_free_server(server);
1462 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -04001463 }
David Howells54ceac42006-08-22 20:06:13 -04001464
1465 if (!s->s_root) {
1466 /* initial superblock/root creation */
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001467 nfs_fill_super(s, &data);
David Howells54ceac42006-08-22 20:06:13 -04001468 }
1469
1470 mntroot = nfs_get_root(s, &mntfh);
1471 if (IS_ERR(mntroot)) {
1472 error = PTR_ERR(mntroot);
1473 goto error_splat_super;
1474 }
1475
David Howellsf7b422b2006-06-09 09:34:33 -04001476 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001477 mnt->mnt_sb = s;
1478 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -04001479 error = 0;
1480
1481out:
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -04001482 kfree(data.nfs_server.hostname);
Chuck Lever33832032007-12-10 14:59:13 -05001483 kfree(data.mount_server.hostname);
Chuck Lever06559602007-07-01 12:12:35 -04001484 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -04001485
David Howells54ceac42006-08-22 20:06:13 -04001486out_err_nosb:
1487 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -04001488 goto out;
David Howells54ceac42006-08-22 20:06:13 -04001489
1490error_splat_super:
1491 up_write(&s->s_umount);
1492 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -04001493 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001494}
1495
David Howells54ceac42006-08-22 20:06:13 -04001496/*
1497 * Destroy an NFS2/3 superblock
1498 */
David Howellsf7b422b2006-06-09 09:34:33 -04001499static void nfs_kill_super(struct super_block *s)
1500{
1501 struct nfs_server *server = NFS_SB(s);
1502
1503 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -04001504 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001505}
1506
David Howells54ceac42006-08-22 20:06:13 -04001507/*
1508 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1509 */
1510static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1511 const char *dev_name, void *raw_data,
1512 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001513{
1514 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001515 struct super_block *s;
1516 struct nfs_server *server;
1517 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001518 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001519 struct nfs_sb_mountdata sb_mntdata = {
1520 .mntflags = flags,
1521 };
David Howells54ceac42006-08-22 20:06:13 -04001522 int error;
1523
1524 dprintk("--> nfs_xdev_get_sb()\n");
1525
1526 /* create a new volume representation */
1527 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1528 if (IS_ERR(server)) {
1529 error = PTR_ERR(server);
1530 goto out_err_noserver;
1531 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001532 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001533
Trond Myklebust75180df2007-05-16 16:53:28 -04001534 if (server->flags & NFS_MOUNT_UNSHARED)
1535 compare_super = NULL;
1536
David Howells54ceac42006-08-22 20:06:13 -04001537 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001538 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001539 if (IS_ERR(s)) {
1540 error = PTR_ERR(s);
1541 goto out_err_nosb;
1542 }
1543
1544 if (s->s_fs_info != server) {
1545 nfs_free_server(server);
1546 server = NULL;
1547 }
1548
1549 if (!s->s_root) {
1550 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001551 nfs_clone_super(s, data->sb);
1552 }
1553
1554 mntroot = nfs_get_root(s, data->fh);
1555 if (IS_ERR(mntroot)) {
1556 error = PTR_ERR(mntroot);
1557 goto error_splat_super;
1558 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001559 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
Neil Brown4c1fe2f2007-11-01 16:50:20 +11001560 dput(mntroot);
1561 error = -ESTALE;
1562 goto error_splat_super;
1563 }
David Howells54ceac42006-08-22 20:06:13 -04001564
1565 s->s_flags |= MS_ACTIVE;
1566 mnt->mnt_sb = s;
1567 mnt->mnt_root = mntroot;
1568
1569 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1570 return 0;
1571
1572out_err_nosb:
1573 nfs_free_server(server);
1574out_err_noserver:
1575 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1576 return error;
1577
1578error_splat_super:
1579 up_write(&s->s_umount);
1580 deactivate_super(s);
1581 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1582 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001583}
1584
1585#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -04001586
1587/*
1588 * Finish setting up a cloned NFS4 superblock
1589 */
1590static void nfs4_clone_super(struct super_block *sb,
1591 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001592{
David Howells54ceac42006-08-22 20:06:13 -04001593 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1594 sb->s_blocksize = old_sb->s_blocksize;
1595 sb->s_maxbytes = old_sb->s_maxbytes;
1596 sb->s_time_gran = 1;
1597 sb->s_op = old_sb->s_op;
1598 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001599}
1600
1601/*
1602 * Set up an NFS4 superblock
1603 */
David Howells54ceac42006-08-22 20:06:13 -04001604static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -04001605{
David Howellsf7b422b2006-06-09 09:34:33 -04001606 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -04001607 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -04001608 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -04001609}
1610
David Howells54ceac42006-08-22 20:06:13 -04001611/*
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001612 * If the user didn't specify a port, set the port number to
1613 * the NFS version 4 default port.
1614 */
1615static void nfs4_default_port(struct sockaddr *sap)
1616{
1617 switch (sap->sa_family) {
1618 case AF_INET: {
1619 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1620 if (ap->sin_port == 0)
1621 ap->sin_port = htons(NFS_PORT);
1622 break;
1623 }
1624 case AF_INET6: {
1625 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1626 if (ap->sin6_port == 0)
1627 ap->sin6_port = htons(NFS_PORT);
1628 break;
1629 }
1630 }
1631}
1632
1633/*
Chuck Leverf0768eb2007-07-01 12:13:01 -04001634 * Validate NFSv4 mount options
1635 */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001636static int nfs4_validate_mount_data(void *options,
1637 struct nfs_parsed_mount_data *args,
1638 const char *dev_name)
Chuck Leverf0768eb2007-07-01 12:13:01 -04001639{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001640 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001641 char *c;
1642
Russell Kingf16c9602007-11-16 22:13:24 +00001643 memset(args, 0, sizeof(*args));
1644
Chuck Leverf0768eb2007-07-01 12:13:01 -04001645 if (data == NULL)
1646 goto out_no_data;
1647
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001648 args->rsize = NFS_MAX_FILE_IO_SIZE;
1649 args->wsize = NFS_MAX_FILE_IO_SIZE;
1650 args->timeo = 600;
1651 args->retrans = 2;
1652 args->acregmin = 3;
1653 args->acregmax = 60;
1654 args->acdirmin = 30;
1655 args->acdirmax = 60;
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -04001656 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001657
Chuck Leverf0768eb2007-07-01 12:13:01 -04001658 switch (data->version) {
1659 case 1:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001660 if (data->host_addrlen != sizeof(args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001661 goto out_no_address;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001662 if (copy_from_user(&args->nfs_server.address,
1663 data->host_addr,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001664 sizeof(args->nfs_server.address)))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001665 return -EFAULT;
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001666 if (!nfs_verify_server_address((struct sockaddr *)
1667 &args->nfs_server.address))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001668 goto out_no_address;
1669
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001670 nfs4_default_port((struct sockaddr *)
1671 &args->nfs_server.address);
1672
Chuck Leverf0768eb2007-07-01 12:13:01 -04001673 switch (data->auth_flavourlen) {
1674 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001675 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001676 break;
1677 case 1:
Trond Myklebust20c71f52007-09-20 20:23:51 -04001678 if (copy_from_user(&args->auth_flavors[0],
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001679 data->auth_flavours,
Trond Myklebust20c71f52007-09-20 20:23:51 -04001680 sizeof(args->auth_flavors[0])))
Chuck Leverf0768eb2007-07-01 12:13:01 -04001681 return -EFAULT;
1682 break;
1683 default:
1684 goto out_inval_auth;
1685 }
1686
1687 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1688 if (IS_ERR(c))
1689 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001690 args->nfs_server.hostname = c;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001691
1692 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1693 if (IS_ERR(c))
1694 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001695 args->nfs_server.export_path = c;
1696 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001697
1698 c = strndup_user(data->client_addr.data, 16);
1699 if (IS_ERR(c))
1700 return PTR_ERR(c);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001701 args->client_address = c;
1702
1703 /*
1704 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1705 * can deal with.
1706 */
1707
1708 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1709 args->rsize = data->rsize;
1710 args->wsize = data->wsize;
1711 args->timeo = data->timeo;
1712 args->retrans = data->retrans;
1713 args->acregmin = data->acregmin;
1714 args->acregmax = data->acregmax;
1715 args->acdirmin = data->acdirmin;
1716 args->acdirmax = data->acdirmax;
1717 args->nfs_server.protocol = data->proto;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001718
1719 break;
Chuck Lever80071222007-07-01 12:13:59 -04001720 default: {
1721 unsigned int len;
Chuck Lever80071222007-07-01 12:13:59 -04001722
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001723 if (nfs_parse_mount_options((char *)options, args) == 0)
Chuck Lever80071222007-07-01 12:13:59 -04001724 return -EINVAL;
1725
1726 if (!nfs_verify_server_address((struct sockaddr *)
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001727 &args->nfs_server.address))
Chuck Lever80071222007-07-01 12:13:59 -04001728 return -EINVAL;
Chuck Lever80071222007-07-01 12:13:59 -04001729
Chuck Lever0d0f0c12007-12-10 14:58:00 -05001730 nfs4_default_port((struct sockaddr *)
1731 &args->nfs_server.address);
1732
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001733 switch (args->auth_flavor_len) {
Chuck Lever80071222007-07-01 12:13:59 -04001734 case 0:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001735 args->auth_flavors[0] = RPC_AUTH_UNIX;
Chuck Lever80071222007-07-01 12:13:59 -04001736 break;
1737 case 1:
Chuck Lever80071222007-07-01 12:13:59 -04001738 break;
1739 default:
1740 goto out_inval_auth;
1741 }
1742
1743 /*
Chuck Lever80071222007-07-01 12:13:59 -04001744 * Split "dev_name" into "hostname:mntpath".
1745 */
1746 c = strchr(dev_name, ':');
1747 if (c == NULL)
1748 return -EINVAL;
1749 /* while calculating len, pretend ':' is '\0' */
1750 len = c - dev_name;
1751 if (len > NFS4_MAXNAMLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001752 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001753 /* N.B. caller will free nfs_server.hostname in all cases */
1754 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001755
1756 c++; /* step over the ':' */
1757 len = strlen(c);
1758 if (len > NFS4_MAXPATHLEN)
Chuck Lever7d1cca722007-08-29 17:59:03 -04001759 return -ENAMETOOLONG;
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001760 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
Chuck Lever80071222007-07-01 12:13:59 -04001761
Chuck Lever6a0ed1d2007-10-26 13:32:40 -04001762 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
Chuck Lever80071222007-07-01 12:13:59 -04001763
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001764 if (args->client_address == NULL)
Jeff Layton0a87cf12007-07-18 11:28:43 -04001765 goto out_no_client_address;
1766
Chuck Lever80071222007-07-01 12:13:59 -04001767 break;
1768 }
Chuck Leverf0768eb2007-07-01 12:13:01 -04001769 }
1770
1771 return 0;
1772
1773out_no_data:
1774 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1775 return -EINVAL;
1776
1777out_inval_auth:
1778 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1779 data->auth_flavourlen);
1780 return -EINVAL;
1781
1782out_no_address:
1783 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1784 return -EINVAL;
Jeff Layton0a87cf12007-07-18 11:28:43 -04001785
1786out_no_client_address:
1787 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1788 return -EINVAL;
Chuck Leverf0768eb2007-07-01 12:13:01 -04001789}
1790
1791/*
David Howells54ceac42006-08-22 20:06:13 -04001792 * Get the superblock for an NFS4 mountpoint
1793 */
Trond Myklebust816724e2006-06-24 08:41:41 -04001794static int nfs4_get_sb(struct file_system_type *fs_type,
1795 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001796{
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001797 struct nfs_parsed_mount_data data;
David Howells54ceac42006-08-22 20:06:13 -04001798 struct super_block *s;
1799 struct nfs_server *server;
David Howells54ceac42006-08-22 20:06:13 -04001800 struct nfs_fh mntfh;
1801 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001802 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001803 struct nfs_sb_mountdata sb_mntdata = {
1804 .mntflags = flags,
1805 };
David Howells54ceac42006-08-22 20:06:13 -04001806 int error;
David Howellsf7b422b2006-06-09 09:34:33 -04001807
Chuck Leverf0768eb2007-07-01 12:13:01 -04001808 /* Validate the mount data */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001809 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
Chuck Leverf0768eb2007-07-01 12:13:01 -04001810 if (error < 0)
1811 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001812
David Howells54ceac42006-08-22 20:06:13 -04001813 /* Get a volume representation */
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001814 server = nfs4_create_server(&data, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001815 if (IS_ERR(server)) {
1816 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -04001817 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001818 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001819 sb_mntdata.server = server;
David Howellsf7b422b2006-06-09 09:34:33 -04001820
Trond Myklebust75180df2007-05-16 16:53:28 -04001821 if (server->flags & NFS4_MOUNT_UNSHARED)
1822 compare_super = NULL;
1823
David Howells54ceac42006-08-22 20:06:13 -04001824 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001825 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
Trond Myklebust816724e2006-06-24 08:41:41 -04001826 if (IS_ERR(s)) {
1827 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -04001828 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -04001829 }
1830
Trond Myklebust5dd31772006-08-24 01:03:05 -04001831 if (s->s_fs_info != server) {
1832 nfs_free_server(server);
1833 server = NULL;
1834 }
1835
David Howells54ceac42006-08-22 20:06:13 -04001836 if (!s->s_root) {
1837 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001838 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -04001839 }
David Howellsf7b422b2006-06-09 09:34:33 -04001840
David Howells54ceac42006-08-22 20:06:13 -04001841 mntroot = nfs4_get_root(s, &mntfh);
1842 if (IS_ERR(mntroot)) {
1843 error = PTR_ERR(mntroot);
1844 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -04001845 }
David Howells54ceac42006-08-22 20:06:13 -04001846
David Howellsf7b422b2006-06-09 09:34:33 -04001847 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -04001848 mnt->mnt_sb = s;
1849 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -04001850 error = 0;
David Howells54ceac42006-08-22 20:06:13 -04001851
Chuck Lever29eb9812007-07-01 12:12:30 -04001852out:
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -04001853 kfree(data.client_address);
1854 kfree(data.nfs_server.export_path);
1855 kfree(data.nfs_server.hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -04001856 return error;
David Howells54ceac42006-08-22 20:06:13 -04001857
Chuck Lever29eb9812007-07-01 12:12:30 -04001858out_free:
1859 nfs_free_server(server);
1860 goto out;
1861
David Howells54ceac42006-08-22 20:06:13 -04001862error_splat_super:
1863 up_write(&s->s_umount);
1864 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -04001865 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -04001866}
1867
1868static void nfs4_kill_super(struct super_block *sb)
1869{
1870 struct nfs_server *server = NFS_SB(sb);
1871
1872 nfs_return_all_delegations(sb);
1873 kill_anon_super(sb);
1874
1875 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -04001876 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -04001877}
1878
1879/*
David Howells54ceac42006-08-22 20:06:13 -04001880 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -04001881 */
David Howells54ceac42006-08-22 20:06:13 -04001882static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1883 const char *dev_name, void *raw_data,
1884 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001885{
1886 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001887 struct super_block *s;
1888 struct nfs_server *server;
1889 struct dentry *mntroot;
Trond Myklebust75180df2007-05-16 16:53:28 -04001890 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001891 struct nfs_sb_mountdata sb_mntdata = {
1892 .mntflags = flags,
1893 };
David Howells54ceac42006-08-22 20:06:13 -04001894 int error;
1895
1896 dprintk("--> nfs4_xdev_get_sb()\n");
1897
1898 /* create a new volume representation */
1899 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1900 if (IS_ERR(server)) {
1901 error = PTR_ERR(server);
1902 goto out_err_noserver;
1903 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001904 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001905
Trond Myklebust75180df2007-05-16 16:53:28 -04001906 if (server->flags & NFS4_MOUNT_UNSHARED)
1907 compare_super = NULL;
1908
David Howells54ceac42006-08-22 20:06:13 -04001909 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001910 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001911 if (IS_ERR(s)) {
1912 error = PTR_ERR(s);
1913 goto out_err_nosb;
1914 }
1915
1916 if (s->s_fs_info != server) {
1917 nfs_free_server(server);
1918 server = NULL;
1919 }
1920
1921 if (!s->s_root) {
1922 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04001923 nfs4_clone_super(s, data->sb);
1924 }
1925
1926 mntroot = nfs4_get_root(s, data->fh);
1927 if (IS_ERR(mntroot)) {
1928 error = PTR_ERR(mntroot);
1929 goto error_splat_super;
1930 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05001931 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1932 dput(mntroot);
1933 error = -ESTALE;
1934 goto error_splat_super;
1935 }
David Howells54ceac42006-08-22 20:06:13 -04001936
1937 s->s_flags |= MS_ACTIVE;
1938 mnt->mnt_sb = s;
1939 mnt->mnt_root = mntroot;
1940
1941 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1942 return 0;
1943
1944out_err_nosb:
1945 nfs_free_server(server);
1946out_err_noserver:
1947 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1948 return error;
1949
1950error_splat_super:
1951 up_write(&s->s_umount);
1952 deactivate_super(s);
1953 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1954 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001955}
1956
David Howells54ceac42006-08-22 20:06:13 -04001957/*
1958 * Create an NFS4 server record on referral traversal
1959 */
1960static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1961 const char *dev_name, void *raw_data,
1962 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001963{
1964 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001965 struct super_block *s;
1966 struct nfs_server *server;
1967 struct dentry *mntroot;
1968 struct nfs_fh mntfh;
Trond Myklebust75180df2007-05-16 16:53:28 -04001969 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001970 struct nfs_sb_mountdata sb_mntdata = {
1971 .mntflags = flags,
1972 };
David Howells54ceac42006-08-22 20:06:13 -04001973 int error;
1974
1975 dprintk("--> nfs4_referral_get_sb()\n");
1976
1977 /* create a new volume representation */
1978 server = nfs4_create_referral_server(data, &mntfh);
1979 if (IS_ERR(server)) {
1980 error = PTR_ERR(server);
1981 goto out_err_noserver;
1982 }
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001983 sb_mntdata.server = server;
David Howells54ceac42006-08-22 20:06:13 -04001984
Trond Myklebust75180df2007-05-16 16:53:28 -04001985 if (server->flags & NFS4_MOUNT_UNSHARED)
1986 compare_super = NULL;
1987
David Howells54ceac42006-08-22 20:06:13 -04001988 /* Get a superblock - note that we may end up sharing one that already exists */
Trond Myklebuste89a5a42007-08-31 10:45:17 -04001989 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
David Howells54ceac42006-08-22 20:06:13 -04001990 if (IS_ERR(s)) {
1991 error = PTR_ERR(s);
1992 goto out_err_nosb;
1993 }
1994
1995 if (s->s_fs_info != server) {
1996 nfs_free_server(server);
1997 server = NULL;
1998 }
1999
2000 if (!s->s_root) {
2001 /* initial superblock/root creation */
David Howells54ceac42006-08-22 20:06:13 -04002002 nfs4_fill_super(s);
2003 }
2004
Trond Myklebustf2d0d852007-02-02 14:46:09 -08002005 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04002006 if (IS_ERR(mntroot)) {
2007 error = PTR_ERR(mntroot);
2008 goto error_splat_super;
2009 }
Trond Myklebuste9cc6c22008-01-02 13:28:57 -05002010 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2011 dput(mntroot);
2012 error = -ESTALE;
2013 goto error_splat_super;
2014 }
David Howells54ceac42006-08-22 20:06:13 -04002015
2016 s->s_flags |= MS_ACTIVE;
2017 mnt->mnt_sb = s;
2018 mnt->mnt_root = mntroot;
2019
2020 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2021 return 0;
2022
2023out_err_nosb:
2024 nfs_free_server(server);
2025out_err_noserver:
2026 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2027 return error;
2028
2029error_splat_super:
2030 up_write(&s->s_umount);
2031 deactivate_super(s);
2032 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2033 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04002034}
2035
David Howells54ceac42006-08-22 20:06:13 -04002036#endif /* CONFIG_NFS_V4 */