blob: ed3ec4477a0fedf61c5946a8baf791c66c576caa [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>
36#include <linux/nfs_fs.h>
37#include <linux/nfs_mount.h>
38#include <linux/nfs4_mount.h>
39#include <linux/lockd/bind.h>
40#include <linux/smp_lock.h>
41#include <linux/seq_file.h>
42#include <linux/mount.h>
43#include <linux/nfs_idmap.h>
44#include <linux/vfs.h>
45#include <linux/inet.h>
46#include <linux/nfs_xdr.h>
Adrian Bunkb5d5dfb2007-02-12 00:53:40 -080047#include <linux/magic.h>
David Howellsf7b422b2006-06-09 09:34:33 -040048
49#include <asm/system.h>
50#include <asm/uaccess.h>
51
52#include "nfs4_fs.h"
53#include "callback.h"
54#include "delegation.h"
55#include "iostat.h"
56#include "internal.h"
57
58#define NFSDBG_FACILITY NFSDBG_VFS
59
David Howellsf7b422b2006-06-09 09:34:33 -040060static void nfs_umount_begin(struct vfsmount *, int);
Trond Myklebust816724e2006-06-24 08:41:41 -040061static int nfs_statfs(struct dentry *, struct kstatfs *);
David Howellsf7b422b2006-06-09 09:34:33 -040062static int nfs_show_options(struct seq_file *, struct vfsmount *);
63static int nfs_show_stats(struct seq_file *, struct vfsmount *);
Trond Myklebust816724e2006-06-24 08:41:41 -040064static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
David Howells54ceac42006-08-22 20:06:13 -040065static int nfs_xdev_get_sb(struct file_system_type *fs_type,
Trond Myklebust816724e2006-06-24 08:41:41 -040066 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -040067static void nfs_kill_super(struct super_block *);
68
69static struct file_system_type nfs_fs_type = {
70 .owner = THIS_MODULE,
71 .name = "nfs",
72 .get_sb = nfs_get_sb,
73 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -070074 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -040075};
76
David Howells54ceac42006-08-22 20:06:13 -040077struct file_system_type nfs_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -040078 .owner = THIS_MODULE,
79 .name = "nfs",
David Howells54ceac42006-08-22 20:06:13 -040080 .get_sb = nfs_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -040081 .kill_sb = nfs_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -070082 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -040083};
84
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -080085static const struct super_operations nfs_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -040086 .alloc_inode = nfs_alloc_inode,
87 .destroy_inode = nfs_destroy_inode,
88 .write_inode = nfs_write_inode,
89 .statfs = nfs_statfs,
90 .clear_inode = nfs_clear_inode,
91 .umount_begin = nfs_umount_begin,
92 .show_options = nfs_show_options,
93 .show_stats = nfs_show_stats,
94};
95
96#ifdef CONFIG_NFS_V4
Trond Myklebust816724e2006-06-24 08:41:41 -040097static int nfs4_get_sb(struct file_system_type *fs_type,
98 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howells54ceac42006-08-22 20:06:13 -040099static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
100 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
101static int nfs4_referral_get_sb(struct file_system_type *fs_type,
102 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
David Howellsf7b422b2006-06-09 09:34:33 -0400103static void nfs4_kill_super(struct super_block *sb);
104
105static struct file_system_type nfs4_fs_type = {
106 .owner = THIS_MODULE,
107 .name = "nfs4",
108 .get_sb = nfs4_get_sb,
109 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700110 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400111};
112
David Howells54ceac42006-08-22 20:06:13 -0400113struct file_system_type nfs4_xdev_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400114 .owner = THIS_MODULE,
115 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400116 .get_sb = nfs4_xdev_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400117 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700118 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400119};
120
David Howells54ceac42006-08-22 20:06:13 -0400121struct file_system_type nfs4_referral_fs_type = {
David Howellsf7b422b2006-06-09 09:34:33 -0400122 .owner = THIS_MODULE,
123 .name = "nfs4",
David Howells54ceac42006-08-22 20:06:13 -0400124 .get_sb = nfs4_referral_get_sb,
David Howellsf7b422b2006-06-09 09:34:33 -0400125 .kill_sb = nfs4_kill_super,
Mark Fasheh349457c2006-09-08 14:22:21 -0700126 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
David Howellsf7b422b2006-06-09 09:34:33 -0400127};
128
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800129static const struct super_operations nfs4_sops = {
David Howellsf7b422b2006-06-09 09:34:33 -0400130 .alloc_inode = nfs_alloc_inode,
131 .destroy_inode = nfs_destroy_inode,
132 .write_inode = nfs_write_inode,
133 .statfs = nfs_statfs,
134 .clear_inode = nfs4_clear_inode,
135 .umount_begin = nfs_umount_begin,
136 .show_options = nfs_show_options,
137 .show_stats = nfs_show_stats,
138};
139#endif
140
Trond Myklebust979df722006-07-25 11:28:19 -0400141static struct shrinker *acl_shrinker;
142
David Howellsf7b422b2006-06-09 09:34:33 -0400143/*
144 * Register the NFS filesystems
145 */
146int __init register_nfs_fs(void)
147{
148 int ret;
149
150 ret = register_filesystem(&nfs_fs_type);
151 if (ret < 0)
152 goto error_0;
153
David Howellsf7b422b2006-06-09 09:34:33 -0400154 ret = nfs_register_sysctl();
155 if (ret < 0)
156 goto error_1;
Peter Zijlstra89a09142007-03-16 13:38:26 -0800157#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400158 ret = register_filesystem(&nfs4_fs_type);
159 if (ret < 0)
160 goto error_2;
161#endif
Trond Myklebust979df722006-07-25 11:28:19 -0400162 acl_shrinker = set_shrinker(DEFAULT_SEEKS, nfs_access_cache_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400163 return 0;
164
165#ifdef CONFIG_NFS_V4
166error_2:
167 nfs_unregister_sysctl();
Peter Zijlstra89a09142007-03-16 13:38:26 -0800168#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400169error_1:
170 unregister_filesystem(&nfs_fs_type);
David Howellsf7b422b2006-06-09 09:34:33 -0400171error_0:
172 return ret;
173}
174
175/*
176 * Unregister the NFS filesystems
177 */
178void __exit unregister_nfs_fs(void)
179{
Trond Myklebust979df722006-07-25 11:28:19 -0400180 if (acl_shrinker != NULL)
181 remove_shrinker(acl_shrinker);
David Howellsf7b422b2006-06-09 09:34:33 -0400182#ifdef CONFIG_NFS_V4
183 unregister_filesystem(&nfs4_fs_type);
184 nfs_unregister_sysctl();
185#endif
186 unregister_filesystem(&nfs_fs_type);
187}
188
189/*
190 * Deliver file system statistics to userspace
191 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400192static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
David Howellsf7b422b2006-06-09 09:34:33 -0400193{
David Howells0c7d90c2006-08-22 20:06:10 -0400194 struct nfs_server *server = NFS_SB(dentry->d_sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400195 unsigned char blockbits;
196 unsigned long blockres;
David Howells0c7d90c2006-08-22 20:06:10 -0400197 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
David Howellsf7b422b2006-06-09 09:34:33 -0400198 struct nfs_fattr fattr;
199 struct nfs_fsstat res = {
200 .fattr = &fattr,
201 };
202 int error;
203
204 lock_kernel();
205
David Howells8fa5c002006-08-22 20:06:12 -0400206 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
David Howellsf7b422b2006-06-09 09:34:33 -0400207 if (error < 0)
208 goto out_err;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700209 buf->f_type = NFS_SUPER_MAGIC;
David Howellsf7b422b2006-06-09 09:34:33 -0400210
211 /*
212 * Current versions of glibc do not correctly handle the
213 * case where f_frsize != f_bsize. Eventually we want to
214 * report the value of wtmult in this field.
215 */
David Howells0c7d90c2006-08-22 20:06:10 -0400216 buf->f_frsize = dentry->d_sb->s_blocksize;
David Howellsf7b422b2006-06-09 09:34:33 -0400217
218 /*
219 * On most *nix systems, f_blocks, f_bfree, and f_bavail
220 * are reported in units of f_frsize. Linux hasn't had
221 * an f_frsize field in its statfs struct until recently,
222 * thus historically Linux's sys_statfs reports these
223 * fields in units of f_bsize.
224 */
David Howells0c7d90c2006-08-22 20:06:10 -0400225 buf->f_bsize = dentry->d_sb->s_blocksize;
226 blockbits = dentry->d_sb->s_blocksize_bits;
David Howellsf7b422b2006-06-09 09:34:33 -0400227 blockres = (1 << blockbits) - 1;
228 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
229 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
230 buf->f_bavail = (res.abytes + blockres) >> blockbits;
231
232 buf->f_files = res.tfiles;
233 buf->f_ffree = res.afiles;
234
235 buf->f_namelen = server->namelen;
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700236
David Howellsf7b422b2006-06-09 09:34:33 -0400237 unlock_kernel();
238 return 0;
239
240 out_err:
241 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
Amnon Aaronsohn1a0ba9a2007-04-09 22:05:26 -0700242 unlock_kernel();
243 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400244}
245
David Howells7d4e2742006-08-22 20:06:07 -0400246/*
247 * Map the security flavour number to a name
248 */
Trond Myklebust81039f12006-06-09 09:34:34 -0400249static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
250{
David Howells7d4e2742006-08-22 20:06:07 -0400251 static const struct {
Trond Myklebust81039f12006-06-09 09:34:34 -0400252 rpc_authflavor_t flavour;
253 const char *str;
254 } sec_flavours[] = {
255 { RPC_AUTH_NULL, "null" },
256 { RPC_AUTH_UNIX, "sys" },
257 { RPC_AUTH_GSS_KRB5, "krb5" },
258 { RPC_AUTH_GSS_KRB5I, "krb5i" },
259 { RPC_AUTH_GSS_KRB5P, "krb5p" },
260 { RPC_AUTH_GSS_LKEY, "lkey" },
261 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
262 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
263 { RPC_AUTH_GSS_SPKM, "spkm" },
264 { RPC_AUTH_GSS_SPKMI, "spkmi" },
265 { RPC_AUTH_GSS_SPKMP, "spkmp" },
Chuck Lever4d81cd12007-07-01 12:12:40 -0400266 { UINT_MAX, "unknown" }
Trond Myklebust81039f12006-06-09 09:34:34 -0400267 };
268 int i;
269
Chuck Lever4d81cd12007-07-01 12:12:40 -0400270 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
Trond Myklebust81039f12006-06-09 09:34:34 -0400271 if (sec_flavours[i].flavour == flavour)
272 break;
273 }
274 return sec_flavours[i].str;
275}
276
David Howellsf7b422b2006-06-09 09:34:33 -0400277/*
278 * Describe the mount options in force on this server representation
279 */
280static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
281{
David Howells509de812006-08-22 20:06:11 -0400282 static const struct proc_nfs_info {
David Howellsf7b422b2006-06-09 09:34:33 -0400283 int flag;
David Howells509de812006-08-22 20:06:11 -0400284 const char *str;
285 const char *nostr;
David Howellsf7b422b2006-06-09 09:34:33 -0400286 } nfs_info[] = {
287 { NFS_MOUNT_SOFT, ",soft", ",hard" },
288 { NFS_MOUNT_INTR, ",intr", "" },
289 { NFS_MOUNT_NOCTO, ",nocto", "" },
290 { NFS_MOUNT_NOAC, ",noac", "" },
291 { NFS_MOUNT_NONLM, ",nolock", "" },
292 { NFS_MOUNT_NOACL, ",noacl", "" },
Steve Dickson74dd34e2007-04-14 17:01:15 -0400293 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
David Howellsf7b422b2006-06-09 09:34:33 -0400294 { 0, NULL, NULL }
295 };
David Howells509de812006-08-22 20:06:11 -0400296 const struct proc_nfs_info *nfs_infop;
David Howells8fa5c002006-08-22 20:06:12 -0400297 struct nfs_client *clp = nfss->nfs_client;
David Howellsf7b422b2006-06-09 09:34:33 -0400298 char buf[12];
David Howells509de812006-08-22 20:06:11 -0400299 const char *proto;
David Howellsf7b422b2006-06-09 09:34:33 -0400300
David Howells8fa5c002006-08-22 20:06:12 -0400301 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
David Howellsf7b422b2006-06-09 09:34:33 -0400302 seq_printf(m, ",rsize=%d", nfss->rsize);
303 seq_printf(m, ",wsize=%d", nfss->wsize);
304 if (nfss->acregmin != 3*HZ || showdefaults)
305 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
306 if (nfss->acregmax != 60*HZ || showdefaults)
307 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
308 if (nfss->acdirmin != 30*HZ || showdefaults)
309 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
310 if (nfss->acdirmax != 60*HZ || showdefaults)
311 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
312 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
313 if (nfss->flags & nfs_infop->flag)
314 seq_puts(m, nfs_infop->str);
315 else
316 seq_puts(m, nfs_infop->nostr);
317 }
318 switch (nfss->client->cl_xprt->prot) {
319 case IPPROTO_TCP:
320 proto = "tcp";
321 break;
322 case IPPROTO_UDP:
323 proto = "udp";
324 break;
325 default:
326 snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
327 proto = buf;
328 }
329 seq_printf(m, ",proto=%s", proto);
David Howells5006a762006-08-22 20:06:12 -0400330 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
331 seq_printf(m, ",retrans=%u", clp->retrans_count);
Trond Myklebust81039f12006-06-09 09:34:34 -0400332 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
David Howellsf7b422b2006-06-09 09:34:33 -0400333}
334
335/*
336 * Describe the mount options on this VFS mountpoint
337 */
338static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
339{
340 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
341
342 nfs_show_mount_options(m, nfss, 0);
343
344 seq_puts(m, ",addr=");
David Howells54ceac42006-08-22 20:06:13 -0400345 seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\");
David Howellsf7b422b2006-06-09 09:34:33 -0400346
347 return 0;
348}
349
350/*
351 * Present statistical information for this VFS mountpoint
352 */
353static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
354{
355 int i, cpu;
356 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
357 struct rpc_auth *auth = nfss->client->cl_auth;
358 struct nfs_iostats totals = { };
359
360 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
361
362 /*
363 * Display all mount option settings
364 */
365 seq_printf(m, "\n\topts:\t");
366 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
367 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
368 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
369 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
370 nfs_show_mount_options(m, nfss, 1);
371
372 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
373
374 seq_printf(m, "\n\tcaps:\t");
375 seq_printf(m, "caps=0x%x", nfss->caps);
376 seq_printf(m, ",wtmult=%d", nfss->wtmult);
377 seq_printf(m, ",dtsize=%d", nfss->dtsize);
378 seq_printf(m, ",bsize=%d", nfss->bsize);
379 seq_printf(m, ",namelen=%d", nfss->namelen);
380
381#ifdef CONFIG_NFS_V4
David Howells8fa5c002006-08-22 20:06:12 -0400382 if (nfss->nfs_client->cl_nfsversion == 4) {
David Howellsf7b422b2006-06-09 09:34:33 -0400383 seq_printf(m, "\n\tnfsv4:\t");
384 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
385 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
386 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
387 }
388#endif
389
390 /*
391 * Display security flavor in effect for this mount
392 */
393 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
394 if (auth->au_flavor)
395 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
396
397 /*
398 * Display superblock I/O counters
399 */
400 for_each_possible_cpu(cpu) {
401 struct nfs_iostats *stats;
402
403 preempt_disable();
404 stats = per_cpu_ptr(nfss->io_stats, cpu);
405
406 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
407 totals.events[i] += stats->events[i];
408 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
409 totals.bytes[i] += stats->bytes[i];
410
411 preempt_enable();
412 }
413
414 seq_printf(m, "\n\tevents:\t");
415 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
416 seq_printf(m, "%lu ", totals.events[i]);
417 seq_printf(m, "\n\tbytes:\t");
418 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
419 seq_printf(m, "%Lu ", totals.bytes[i]);
420 seq_printf(m, "\n");
421
422 rpc_print_iostats(m, nfss->client);
423
424 return 0;
425}
426
427/*
428 * Begin unmount by attempting to remove all automounted mountpoints we added
David Howells54ceac42006-08-22 20:06:13 -0400429 * in response to xdev traversals and referrals
David Howellsf7b422b2006-06-09 09:34:33 -0400430 */
431static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
432{
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400433 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
434 struct rpc_clnt *rpc;
435
David Howellsf7b422b2006-06-09 09:34:33 -0400436 shrink_submounts(vfsmnt, &nfs_automount_list);
Trond Myklebustfc6ae3c2007-06-05 19:13:47 -0400437
438 if (!(flags & MNT_FORCE))
439 return;
440 /* -EIO all pending I/O */
441 rpc = server->client_acl;
442 if (!IS_ERR(rpc))
443 rpc_killall_tasks(rpc);
444 rpc = server->client;
445 if (!IS_ERR(rpc))
446 rpc_killall_tasks(rpc);
David Howellsf7b422b2006-06-09 09:34:33 -0400447}
448
449/*
Chuck Leverfc50d582007-07-01 12:12:46 -0400450 * Sanity-check a server address provided by the mount command
451 */
452static int nfs_verify_server_address(struct sockaddr *addr)
453{
454 switch (addr->sa_family) {
455 case AF_INET: {
456 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
457 if (sa->sin_addr.s_addr != INADDR_ANY)
458 return 1;
459 break;
460 }
461 }
462
463 return 0;
464}
465
466/*
David Howells54ceac42006-08-22 20:06:13 -0400467 * Validate the NFS2/NFS3 mount data
468 * - fills in the mount root filehandle
David Howellsf7b422b2006-06-09 09:34:33 -0400469 */
David Howells54ceac42006-08-22 20:06:13 -0400470static int nfs_validate_mount_data(struct nfs_mount_data *data,
471 struct nfs_fh *mntfh)
David Howellsf7b422b2006-06-09 09:34:33 -0400472{
Chuck Lever5df36e72007-07-01 12:12:56 -0400473 if (data == NULL)
474 goto out_no_data;
David Howells54ceac42006-08-22 20:06:13 -0400475
David Howellsf7b422b2006-06-09 09:34:33 -0400476 switch (data->version) {
Chuck Lever5df36e72007-07-01 12:12:56 -0400477 case 1:
478 data->namlen = 0;
479 case 2:
480 data->bsize = 0;
481 case 3:
482 if (data->flags & NFS_MOUNT_VER3)
483 goto out_no_v3;
484 data->root.size = NFS2_FHSIZE;
485 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
486 case 4:
487 if (data->flags & NFS_MOUNT_SECFLAVOUR)
488 goto out_no_sec;
489 case 5:
490 memset(data->context, 0, sizeof(data->context));
491 case 6:
492 if (data->flags & NFS_MOUNT_VER3)
493 mntfh->size = data->root.size;
494 else
495 mntfh->size = NFS2_FHSIZE;
496
497 if (mntfh->size > sizeof(mntfh->data))
498 goto out_invalid_fh;
499
500 memcpy(mntfh->data, data->root.data, mntfh->size);
501 if (mntfh->size < sizeof(mntfh->data))
502 memset(mntfh->data + mntfh->size, 0,
503 sizeof(mntfh->data) - mntfh->size);
504 break;
505 default:
506 goto out_bad_version;
David Howellsf7b422b2006-06-09 09:34:33 -0400507 }
David Howells54ceac42006-08-22 20:06:13 -0400508
Trond Myklebust36b15c52006-08-22 20:06:14 -0400509 if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
510 data->pseudoflavor = RPC_AUTH_UNIX;
511
David Howellsf7b422b2006-06-09 09:34:33 -0400512#ifndef CONFIG_NFS_V3
David Howells54ceac42006-08-22 20:06:13 -0400513 if (data->flags & NFS_MOUNT_VER3)
Chuck Lever5df36e72007-07-01 12:12:56 -0400514 goto out_v3_not_compiled;
515#endif /* !CONFIG_NFS_V3 */
David Howells54ceac42006-08-22 20:06:13 -0400516
Chuck Lever5df36e72007-07-01 12:12:56 -0400517 if (!nfs_verify_server_address((struct sockaddr *) &data->addr))
518 goto out_no_address;
David Howells54ceac42006-08-22 20:06:13 -0400519
520 return 0;
Chuck Lever5df36e72007-07-01 12:12:56 -0400521
522out_no_data:
523 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
524 return -EINVAL;
525
526out_no_v3:
527 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
528 data->version);
529 return -EINVAL;
530
531out_no_sec:
532 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
533 return -EINVAL;
534
535out_bad_version:
536 dfprintk(MOUNT, "NFS: bad nfs_mount_data version %d\n",
537 data->version);
538 return -EINVAL;
539
540#ifndef CONFIG_NFS_V3
541out_v3_not_compiled:
542 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
543 return -EPROTONOSUPPORT;
544#endif /* !CONFIG_NFS_V3 */
545
546out_no_address:
547 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
548 return -EINVAL;
549
550out_invalid_fh:
551 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
552 return -EINVAL;
David Howells54ceac42006-08-22 20:06:13 -0400553}
554
555/*
556 * Initialise the common bits of the superblock
557 */
558static inline void nfs_initialise_sb(struct super_block *sb)
559{
560 struct nfs_server *server = NFS_SB(sb);
561
562 sb->s_magic = NFS_SUPER_MAGIC;
563
564 /* We probably want something more informative here */
565 snprintf(sb->s_id, sizeof(sb->s_id),
566 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
567
568 if (sb->s_blocksize == 0)
569 sb->s_blocksize = nfs_block_bits(server->wsize,
570 &sb->s_blocksize_bits);
571
572 if (server->flags & NFS_MOUNT_NOAC)
573 sb->s_flags |= MS_SYNCHRONOUS;
574
575 nfs_super_set_maxbytes(sb, server->maxfilesize);
576}
577
578/*
579 * Finish setting up an NFS2/3 superblock
580 */
581static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data)
582{
583 struct nfs_server *server = NFS_SB(sb);
584
585 sb->s_blocksize_bits = 0;
586 sb->s_blocksize = 0;
587 if (data->bsize)
588 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
589
590 if (server->flags & NFS_MOUNT_VER3) {
591 /* The VFS shouldn't apply the umask to mode bits. We will do
592 * so ourselves when necessary.
593 */
594 sb->s_flags |= MS_POSIXACL;
595 sb->s_time_gran = 1;
596 }
597
598 sb->s_op = &nfs_sops;
599 nfs_initialise_sb(sb);
600}
601
602/*
603 * Finish setting up a cloned NFS2/3 superblock
604 */
605static void nfs_clone_super(struct super_block *sb,
606 const struct super_block *old_sb)
607{
608 struct nfs_server *server = NFS_SB(sb);
609
610 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
611 sb->s_blocksize = old_sb->s_blocksize;
612 sb->s_maxbytes = old_sb->s_maxbytes;
613
614 if (server->flags & NFS_MOUNT_VER3) {
615 /* The VFS shouldn't apply the umask to mode bits. We will do
616 * so ourselves when necessary.
617 */
618 sb->s_flags |= MS_POSIXACL;
619 sb->s_time_gran = 1;
620 }
621
622 sb->s_op = old_sb->s_op;
623 nfs_initialise_sb(sb);
624}
625
626static int nfs_set_super(struct super_block *s, void *_server)
627{
628 struct nfs_server *server = _server;
629 int ret;
630
631 s->s_fs_info = server;
632 ret = set_anon_super(s, server);
633 if (ret == 0)
634 server->s_dev = s->s_dev;
635 return ret;
636}
637
638static int nfs_compare_super(struct super_block *sb, void *data)
639{
640 struct nfs_server *server = data, *old = NFS_SB(sb);
641
642 if (old->nfs_client != server->nfs_client)
643 return 0;
644 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
645 return 0;
646 return 1;
647}
648
649static int nfs_get_sb(struct file_system_type *fs_type,
650 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
651{
652 struct nfs_server *server = NULL;
653 struct super_block *s;
654 struct nfs_fh mntfh;
655 struct nfs_mount_data *data = raw_data;
656 struct dentry *mntroot;
657 int error;
658
659 /* Validate the mount data */
660 error = nfs_validate_mount_data(data, &mntfh);
661 if (error < 0)
Chuck Lever06559602007-07-01 12:12:35 -0400662 goto out;
David Howells54ceac42006-08-22 20:06:13 -0400663
664 /* Get a volume representation */
665 server = nfs_create_server(data, &mntfh);
666 if (IS_ERR(server)) {
667 error = PTR_ERR(server);
Chuck Lever06559602007-07-01 12:12:35 -0400668 goto out;
David Howells54ceac42006-08-22 20:06:13 -0400669 }
670
671 /* Get a superblock - note that we may end up sharing one that already exists */
David Howellsf7b422b2006-06-09 09:34:33 -0400672 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
Trond Myklebust816724e2006-06-24 08:41:41 -0400673 if (IS_ERR(s)) {
674 error = PTR_ERR(s);
David Howells54ceac42006-08-22 20:06:13 -0400675 goto out_err_nosb;
Trond Myklebust816724e2006-06-24 08:41:41 -0400676 }
677
David Howells54ceac42006-08-22 20:06:13 -0400678 if (s->s_fs_info != server) {
679 nfs_free_server(server);
680 server = NULL;
David Howellsf7b422b2006-06-09 09:34:33 -0400681 }
David Howells54ceac42006-08-22 20:06:13 -0400682
683 if (!s->s_root) {
684 /* initial superblock/root creation */
685 s->s_flags = flags;
686 nfs_fill_super(s, data);
687 }
688
689 mntroot = nfs_get_root(s, &mntfh);
690 if (IS_ERR(mntroot)) {
691 error = PTR_ERR(mntroot);
692 goto error_splat_super;
693 }
694
David Howellsf7b422b2006-06-09 09:34:33 -0400695 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -0400696 mnt->mnt_sb = s;
697 mnt->mnt_root = mntroot;
Chuck Lever06559602007-07-01 12:12:35 -0400698 error = 0;
699
700out:
701 return error;
Trond Myklebust816724e2006-06-24 08:41:41 -0400702
David Howells54ceac42006-08-22 20:06:13 -0400703out_err_nosb:
704 nfs_free_server(server);
Chuck Lever06559602007-07-01 12:12:35 -0400705 goto out;
David Howells54ceac42006-08-22 20:06:13 -0400706
707error_splat_super:
708 up_write(&s->s_umount);
709 deactivate_super(s);
Chuck Lever06559602007-07-01 12:12:35 -0400710 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -0400711}
712
David Howells54ceac42006-08-22 20:06:13 -0400713/*
714 * Destroy an NFS2/3 superblock
715 */
David Howellsf7b422b2006-06-09 09:34:33 -0400716static void nfs_kill_super(struct super_block *s)
717{
718 struct nfs_server *server = NFS_SB(s);
719
720 kill_anon_super(s);
David Howells54ceac42006-08-22 20:06:13 -0400721 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -0400722}
723
David Howells54ceac42006-08-22 20:06:13 -0400724/*
725 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
726 */
727static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
728 const char *dev_name, void *raw_data,
729 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -0400730{
731 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -0400732 struct super_block *s;
733 struct nfs_server *server;
734 struct dentry *mntroot;
735 int error;
736
737 dprintk("--> nfs_xdev_get_sb()\n");
738
739 /* create a new volume representation */
740 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
741 if (IS_ERR(server)) {
742 error = PTR_ERR(server);
743 goto out_err_noserver;
744 }
745
746 /* Get a superblock - note that we may end up sharing one that already exists */
747 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
748 if (IS_ERR(s)) {
749 error = PTR_ERR(s);
750 goto out_err_nosb;
751 }
752
753 if (s->s_fs_info != server) {
754 nfs_free_server(server);
755 server = NULL;
756 }
757
758 if (!s->s_root) {
759 /* initial superblock/root creation */
760 s->s_flags = flags;
761 nfs_clone_super(s, data->sb);
762 }
763
764 mntroot = nfs_get_root(s, data->fh);
765 if (IS_ERR(mntroot)) {
766 error = PTR_ERR(mntroot);
767 goto error_splat_super;
768 }
769
770 s->s_flags |= MS_ACTIVE;
771 mnt->mnt_sb = s;
772 mnt->mnt_root = mntroot;
773
774 dprintk("<-- nfs_xdev_get_sb() = 0\n");
775 return 0;
776
777out_err_nosb:
778 nfs_free_server(server);
779out_err_noserver:
780 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
781 return error;
782
783error_splat_super:
784 up_write(&s->s_umount);
785 deactivate_super(s);
786 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
787 return error;
David Howellsf7b422b2006-06-09 09:34:33 -0400788}
789
790#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -0400791
792/*
793 * Finish setting up a cloned NFS4 superblock
794 */
795static void nfs4_clone_super(struct super_block *sb,
796 const struct super_block *old_sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400797{
David Howells54ceac42006-08-22 20:06:13 -0400798 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
799 sb->s_blocksize = old_sb->s_blocksize;
800 sb->s_maxbytes = old_sb->s_maxbytes;
801 sb->s_time_gran = 1;
802 sb->s_op = old_sb->s_op;
803 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400804}
805
806/*
807 * Set up an NFS4 superblock
808 */
David Howells54ceac42006-08-22 20:06:13 -0400809static void nfs4_fill_super(struct super_block *sb)
David Howellsf7b422b2006-06-09 09:34:33 -0400810{
David Howellsf7b422b2006-06-09 09:34:33 -0400811 sb->s_time_gran = 1;
David Howellsf7b422b2006-06-09 09:34:33 -0400812 sb->s_op = &nfs4_sops;
David Howells54ceac42006-08-22 20:06:13 -0400813 nfs_initialise_sb(sb);
David Howellsf7b422b2006-06-09 09:34:33 -0400814}
815
David Howells54ceac42006-08-22 20:06:13 -0400816/*
Chuck Leverf0768eb2007-07-01 12:13:01 -0400817 * Validate NFSv4 mount options
818 */
819static int nfs4_validate_mount_data(struct nfs4_mount_data **options,
820 const char *dev_name,
821 struct sockaddr_in *addr,
822 rpc_authflavor_t *authflavour,
823 char **hostname,
824 char **mntpath,
825 char **ip_addr)
826{
827 struct nfs4_mount_data *data = *options;
828 char *c;
829
830 if (data == NULL)
831 goto out_no_data;
832
833 switch (data->version) {
834 case 1:
835 if (data->host_addrlen != sizeof(*addr))
836 goto out_no_address;
837 if (copy_from_user(addr, data->host_addr, sizeof(*addr)))
838 return -EFAULT;
839 if (addr->sin_port == 0)
840 addr->sin_port = htons(NFS_PORT);
841 if (!nfs_verify_server_address((struct sockaddr *) addr))
842 goto out_no_address;
843
844 switch (data->auth_flavourlen) {
845 case 0:
846 *authflavour = RPC_AUTH_UNIX;
847 break;
848 case 1:
849 if (copy_from_user(authflavour, data->auth_flavours,
850 sizeof(*authflavour)))
851 return -EFAULT;
852 break;
853 default:
854 goto out_inval_auth;
855 }
856
857 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
858 if (IS_ERR(c))
859 return PTR_ERR(c);
860 *hostname = c;
861
862 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
863 if (IS_ERR(c))
864 return PTR_ERR(c);
865 *mntpath = c;
866 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *mntpath);
867
868 c = strndup_user(data->client_addr.data, 16);
869 if (IS_ERR(c))
870 return PTR_ERR(c);
871 *ip_addr = c;
872
873 break;
874 default:
875 goto out_bad_version;
876 }
877
878 return 0;
879
880out_no_data:
881 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
882 return -EINVAL;
883
884out_inval_auth:
885 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
886 data->auth_flavourlen);
887 return -EINVAL;
888
889out_no_address:
890 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
891 return -EINVAL;
892
893out_bad_version:
894 dfprintk(MOUNT, "NFS4: bad nfs_mount_data version %d\n",
895 data->version);
896 return -EINVAL;
897}
898
899/*
David Howells54ceac42006-08-22 20:06:13 -0400900 * Get the superblock for an NFS4 mountpoint
901 */
Trond Myklebust816724e2006-06-24 08:41:41 -0400902static int nfs4_get_sb(struct file_system_type *fs_type,
903 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -0400904{
David Howellsf7b422b2006-06-09 09:34:33 -0400905 struct nfs4_mount_data *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -0400906 struct super_block *s;
907 struct nfs_server *server;
908 struct sockaddr_in addr;
909 rpc_authflavor_t authflavour;
910 struct nfs_fh mntfh;
911 struct dentry *mntroot;
Chuck Leverf0768eb2007-07-01 12:13:01 -0400912 char *mntpath = NULL, *hostname = NULL, *ip_addr = NULL;
David Howells54ceac42006-08-22 20:06:13 -0400913 int error;
David Howellsf7b422b2006-06-09 09:34:33 -0400914
Chuck Leverf0768eb2007-07-01 12:13:01 -0400915 /* Validate the mount data */
916 error = nfs4_validate_mount_data(&data, dev_name, &addr, &authflavour,
917 &hostname, &mntpath, &ip_addr);
918 if (error < 0)
919 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -0400920
David Howells54ceac42006-08-22 20:06:13 -0400921 /* Get a volume representation */
922 server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr,
923 authflavour, &mntfh);
924 if (IS_ERR(server)) {
925 error = PTR_ERR(server);
Chuck Lever29eb9812007-07-01 12:12:30 -0400926 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -0400927 }
928
David Howells54ceac42006-08-22 20:06:13 -0400929 /* Get a superblock - note that we may end up sharing one that already exists */
930 s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
Trond Myklebust816724e2006-06-24 08:41:41 -0400931 if (IS_ERR(s)) {
932 error = PTR_ERR(s);
David Howellsf7b422b2006-06-09 09:34:33 -0400933 goto out_free;
Trond Myklebust816724e2006-06-24 08:41:41 -0400934 }
935
Trond Myklebust5dd31772006-08-24 01:03:05 -0400936 if (s->s_fs_info != server) {
937 nfs_free_server(server);
938 server = NULL;
939 }
940
David Howells54ceac42006-08-22 20:06:13 -0400941 if (!s->s_root) {
942 /* initial superblock/root creation */
943 s->s_flags = flags;
David Howells54ceac42006-08-22 20:06:13 -0400944 nfs4_fill_super(s);
Trond Myklebust816724e2006-06-24 08:41:41 -0400945 }
David Howellsf7b422b2006-06-09 09:34:33 -0400946
David Howells54ceac42006-08-22 20:06:13 -0400947 mntroot = nfs4_get_root(s, &mntfh);
948 if (IS_ERR(mntroot)) {
949 error = PTR_ERR(mntroot);
950 goto error_splat_super;
David Howellsf7b422b2006-06-09 09:34:33 -0400951 }
David Howells54ceac42006-08-22 20:06:13 -0400952
David Howellsf7b422b2006-06-09 09:34:33 -0400953 s->s_flags |= MS_ACTIVE;
David Howells54ceac42006-08-22 20:06:13 -0400954 mnt->mnt_sb = s;
955 mnt->mnt_root = mntroot;
Chuck Lever29eb9812007-07-01 12:12:30 -0400956 error = 0;
David Howells54ceac42006-08-22 20:06:13 -0400957
Chuck Lever29eb9812007-07-01 12:12:30 -0400958out:
959 kfree(ip_addr);
David Howells54ceac42006-08-22 20:06:13 -0400960 kfree(mntpath);
961 kfree(hostname);
Trond Myklebust816724e2006-06-24 08:41:41 -0400962 return error;
David Howells54ceac42006-08-22 20:06:13 -0400963
Chuck Lever29eb9812007-07-01 12:12:30 -0400964out_free:
965 nfs_free_server(server);
966 goto out;
967
David Howells54ceac42006-08-22 20:06:13 -0400968error_splat_super:
969 up_write(&s->s_umount);
970 deactivate_super(s);
Chuck Lever29eb9812007-07-01 12:12:30 -0400971 goto out;
David Howellsf7b422b2006-06-09 09:34:33 -0400972}
973
974static void nfs4_kill_super(struct super_block *sb)
975{
976 struct nfs_server *server = NFS_SB(sb);
977
978 nfs_return_all_delegations(sb);
979 kill_anon_super(sb);
980
981 nfs4_renewd_prepare_shutdown(server);
David Howells54ceac42006-08-22 20:06:13 -0400982 nfs_free_server(server);
David Howellsf7b422b2006-06-09 09:34:33 -0400983}
984
985/*
David Howells54ceac42006-08-22 20:06:13 -0400986 * Clone an NFS4 server record on xdev traversal (FSID-change)
David Howellsf7b422b2006-06-09 09:34:33 -0400987 */
David Howells54ceac42006-08-22 20:06:13 -0400988static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
989 const char *dev_name, void *raw_data,
990 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -0400991{
992 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -0400993 struct super_block *s;
994 struct nfs_server *server;
995 struct dentry *mntroot;
996 int error;
997
998 dprintk("--> nfs4_xdev_get_sb()\n");
999
1000 /* create a new volume representation */
1001 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1002 if (IS_ERR(server)) {
1003 error = PTR_ERR(server);
1004 goto out_err_noserver;
1005 }
1006
1007 /* Get a superblock - note that we may end up sharing one that already exists */
1008 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1009 if (IS_ERR(s)) {
1010 error = PTR_ERR(s);
1011 goto out_err_nosb;
1012 }
1013
1014 if (s->s_fs_info != server) {
1015 nfs_free_server(server);
1016 server = NULL;
1017 }
1018
1019 if (!s->s_root) {
1020 /* initial superblock/root creation */
1021 s->s_flags = flags;
1022 nfs4_clone_super(s, data->sb);
1023 }
1024
1025 mntroot = nfs4_get_root(s, data->fh);
1026 if (IS_ERR(mntroot)) {
1027 error = PTR_ERR(mntroot);
1028 goto error_splat_super;
1029 }
1030
1031 s->s_flags |= MS_ACTIVE;
1032 mnt->mnt_sb = s;
1033 mnt->mnt_root = mntroot;
1034
1035 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1036 return 0;
1037
1038out_err_nosb:
1039 nfs_free_server(server);
1040out_err_noserver:
1041 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1042 return error;
1043
1044error_splat_super:
1045 up_write(&s->s_umount);
1046 deactivate_super(s);
1047 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1048 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001049}
1050
David Howells54ceac42006-08-22 20:06:13 -04001051/*
1052 * Create an NFS4 server record on referral traversal
1053 */
1054static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1055 const char *dev_name, void *raw_data,
1056 struct vfsmount *mnt)
David Howellsf7b422b2006-06-09 09:34:33 -04001057{
1058 struct nfs_clone_mount *data = raw_data;
David Howells54ceac42006-08-22 20:06:13 -04001059 struct super_block *s;
1060 struct nfs_server *server;
1061 struct dentry *mntroot;
1062 struct nfs_fh mntfh;
1063 int error;
1064
1065 dprintk("--> nfs4_referral_get_sb()\n");
1066
1067 /* create a new volume representation */
1068 server = nfs4_create_referral_server(data, &mntfh);
1069 if (IS_ERR(server)) {
1070 error = PTR_ERR(server);
1071 goto out_err_noserver;
1072 }
1073
1074 /* Get a superblock - note that we may end up sharing one that already exists */
1075 s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
1076 if (IS_ERR(s)) {
1077 error = PTR_ERR(s);
1078 goto out_err_nosb;
1079 }
1080
1081 if (s->s_fs_info != server) {
1082 nfs_free_server(server);
1083 server = NULL;
1084 }
1085
1086 if (!s->s_root) {
1087 /* initial superblock/root creation */
1088 s->s_flags = flags;
1089 nfs4_fill_super(s);
1090 }
1091
Trond Myklebustf2d0d852007-02-02 14:46:09 -08001092 mntroot = nfs4_get_root(s, &mntfh);
David Howells54ceac42006-08-22 20:06:13 -04001093 if (IS_ERR(mntroot)) {
1094 error = PTR_ERR(mntroot);
1095 goto error_splat_super;
1096 }
1097
1098 s->s_flags |= MS_ACTIVE;
1099 mnt->mnt_sb = s;
1100 mnt->mnt_root = mntroot;
1101
1102 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1103 return 0;
1104
1105out_err_nosb:
1106 nfs_free_server(server);
1107out_err_noserver:
1108 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1109 return error;
1110
1111error_splat_super:
1112 up_write(&s->s_umount);
1113 deactivate_super(s);
1114 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1115 return error;
David Howellsf7b422b2006-06-09 09:34:33 -04001116}
1117
David Howells54ceac42006-08-22 20:06:13 -04001118#endif /* CONFIG_NFS_V4 */