87f65ae07f323ab8998fa103ec0e1e165a242777
[pandora-kernel.git] / fs / nfs / super.c
1 /*
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@lxorguk.ukuu.org.uk>, 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  *
16  * - 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())
21  */
22
23 #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/sunrpc/xprtsock.h>
37 #include <linux/sunrpc/xprtrdma.h>
38 #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>
48 #include <linux/in6.h>
49 #include <net/ipv6.h>
50 #include <linux/netdevice.h>
51 #include <linux/nfs_xdr.h>
52 #include <linux/magic.h>
53 #include <linux/parser.h>
54
55 #include <asm/system.h>
56 #include <asm/uaccess.h>
57
58 #include "nfs4_fs.h"
59 #include "callback.h"
60 #include "delegation.h"
61 #include "iostat.h"
62 #include "internal.h"
63 #include "fscache.h"
64
65 #define NFSDBG_FACILITY         NFSDBG_VFS
66
67 enum {
68         /* Mount options that take no arguments */
69         Opt_soft, Opt_hard,
70         Opt_posix, Opt_noposix,
71         Opt_cto, Opt_nocto,
72         Opt_ac, Opt_noac,
73         Opt_lock, Opt_nolock,
74         Opt_v2, Opt_v3,
75         Opt_udp, Opt_tcp, Opt_rdma,
76         Opt_acl, Opt_noacl,
77         Opt_rdirplus, Opt_nordirplus,
78         Opt_sharecache, Opt_nosharecache,
79         Opt_resvport, Opt_noresvport,
80
81         /* Mount options that take integer arguments */
82         Opt_port,
83         Opt_rsize, Opt_wsize, Opt_bsize,
84         Opt_timeo, Opt_retrans,
85         Opt_acregmin, Opt_acregmax,
86         Opt_acdirmin, Opt_acdirmax,
87         Opt_actimeo,
88         Opt_namelen,
89         Opt_mountport,
90         Opt_mountvers,
91         Opt_nfsvers,
92
93         /* Mount options that take string arguments */
94         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
95         Opt_addr, Opt_mountaddr, Opt_clientaddr,
96         Opt_lookupcache,
97
98         /* Special mount options */
99         Opt_userspace, Opt_deprecated, Opt_sloppy,
100
101         Opt_err
102 };
103
104 static const match_table_t nfs_mount_option_tokens = {
105         { Opt_userspace, "bg" },
106         { Opt_userspace, "fg" },
107         { Opt_userspace, "retry=%s" },
108
109         { Opt_sloppy, "sloppy" },
110
111         { Opt_soft, "soft" },
112         { Opt_hard, "hard" },
113         { Opt_deprecated, "intr" },
114         { Opt_deprecated, "nointr" },
115         { Opt_posix, "posix" },
116         { Opt_noposix, "noposix" },
117         { Opt_cto, "cto" },
118         { Opt_nocto, "nocto" },
119         { Opt_ac, "ac" },
120         { Opt_noac, "noac" },
121         { Opt_lock, "lock" },
122         { Opt_nolock, "nolock" },
123         { Opt_v2, "v2" },
124         { Opt_v3, "v3" },
125         { Opt_udp, "udp" },
126         { Opt_tcp, "tcp" },
127         { Opt_rdma, "rdma" },
128         { Opt_acl, "acl" },
129         { Opt_noacl, "noacl" },
130         { Opt_rdirplus, "rdirplus" },
131         { Opt_nordirplus, "nordirplus" },
132         { Opt_sharecache, "sharecache" },
133         { Opt_nosharecache, "nosharecache" },
134         { Opt_resvport, "resvport" },
135         { Opt_noresvport, "noresvport" },
136
137         { Opt_port, "port=%u" },
138         { Opt_rsize, "rsize=%u" },
139         { Opt_wsize, "wsize=%u" },
140         { Opt_bsize, "bsize=%u" },
141         { Opt_timeo, "timeo=%u" },
142         { Opt_retrans, "retrans=%u" },
143         { Opt_acregmin, "acregmin=%u" },
144         { Opt_acregmax, "acregmax=%u" },
145         { Opt_acdirmin, "acdirmin=%u" },
146         { Opt_acdirmax, "acdirmax=%u" },
147         { Opt_actimeo, "actimeo=%u" },
148         { Opt_namelen, "namlen=%u" },
149         { Opt_mountport, "mountport=%u" },
150         { Opt_mountvers, "mountvers=%u" },
151         { Opt_nfsvers, "nfsvers=%u" },
152         { Opt_nfsvers, "vers=%u" },
153
154         { Opt_sec, "sec=%s" },
155         { Opt_proto, "proto=%s" },
156         { Opt_mountproto, "mountproto=%s" },
157         { Opt_addr, "addr=%s" },
158         { Opt_clientaddr, "clientaddr=%s" },
159         { Opt_mounthost, "mounthost=%s" },
160         { Opt_mountaddr, "mountaddr=%s" },
161
162         { Opt_lookupcache, "lookupcache=%s" },
163
164         { Opt_err, NULL }
165 };
166
167 enum {
168         Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
169
170         Opt_xprt_err
171 };
172
173 static const match_table_t nfs_xprt_protocol_tokens = {
174         { Opt_xprt_udp, "udp" },
175         { Opt_xprt_tcp, "tcp" },
176         { Opt_xprt_rdma, "rdma" },
177
178         { Opt_xprt_err, NULL }
179 };
180
181 enum {
182         Opt_sec_none, Opt_sec_sys,
183         Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
184         Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
185         Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
186
187         Opt_sec_err
188 };
189
190 static const match_table_t nfs_secflavor_tokens = {
191         { Opt_sec_none, "none" },
192         { Opt_sec_none, "null" },
193         { Opt_sec_sys, "sys" },
194
195         { Opt_sec_krb5, "krb5" },
196         { Opt_sec_krb5i, "krb5i" },
197         { Opt_sec_krb5p, "krb5p" },
198
199         { Opt_sec_lkey, "lkey" },
200         { Opt_sec_lkeyi, "lkeyi" },
201         { Opt_sec_lkeyp, "lkeyp" },
202
203         { Opt_sec_spkm, "spkm3" },
204         { Opt_sec_spkmi, "spkm3i" },
205         { Opt_sec_spkmp, "spkm3p" },
206
207         { Opt_sec_err, NULL }
208 };
209
210 enum {
211         Opt_lookupcache_all, Opt_lookupcache_positive,
212         Opt_lookupcache_none,
213
214         Opt_lookupcache_err
215 };
216
217 static match_table_t nfs_lookupcache_tokens = {
218         { Opt_lookupcache_all, "all" },
219         { Opt_lookupcache_positive, "pos" },
220         { Opt_lookupcache_positive, "positive" },
221         { Opt_lookupcache_none, "none" },
222
223         { Opt_lookupcache_err, NULL }
224 };
225
226
227 static void nfs_umount_begin(struct super_block *);
228 static int  nfs_statfs(struct dentry *, struct kstatfs *);
229 static int  nfs_show_options(struct seq_file *, struct vfsmount *);
230 static int  nfs_show_stats(struct seq_file *, struct vfsmount *);
231 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
232 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
233                 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
234 static void nfs_kill_super(struct super_block *);
235 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
236
237 static struct file_system_type nfs_fs_type = {
238         .owner          = THIS_MODULE,
239         .name           = "nfs",
240         .get_sb         = nfs_get_sb,
241         .kill_sb        = nfs_kill_super,
242         .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
243 };
244
245 struct file_system_type nfs_xdev_fs_type = {
246         .owner          = THIS_MODULE,
247         .name           = "nfs",
248         .get_sb         = nfs_xdev_get_sb,
249         .kill_sb        = nfs_kill_super,
250         .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
251 };
252
253 static const struct super_operations nfs_sops = {
254         .alloc_inode    = nfs_alloc_inode,
255         .destroy_inode  = nfs_destroy_inode,
256         .write_inode    = nfs_write_inode,
257         .statfs         = nfs_statfs,
258         .clear_inode    = nfs_clear_inode,
259         .umount_begin   = nfs_umount_begin,
260         .show_options   = nfs_show_options,
261         .show_stats     = nfs_show_stats,
262         .remount_fs     = nfs_remount,
263 };
264
265 #ifdef CONFIG_NFS_V4
266 static int nfs4_get_sb(struct file_system_type *fs_type,
267         int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
268 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
269         int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
270 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
271         int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
272 static void nfs4_kill_super(struct super_block *sb);
273
274 static struct file_system_type nfs4_fs_type = {
275         .owner          = THIS_MODULE,
276         .name           = "nfs4",
277         .get_sb         = nfs4_get_sb,
278         .kill_sb        = nfs4_kill_super,
279         .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
280 };
281
282 struct file_system_type nfs4_xdev_fs_type = {
283         .owner          = THIS_MODULE,
284         .name           = "nfs4",
285         .get_sb         = nfs4_xdev_get_sb,
286         .kill_sb        = nfs4_kill_super,
287         .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
288 };
289
290 struct file_system_type nfs4_referral_fs_type = {
291         .owner          = THIS_MODULE,
292         .name           = "nfs4",
293         .get_sb         = nfs4_referral_get_sb,
294         .kill_sb        = nfs4_kill_super,
295         .fs_flags       = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
296 };
297
298 static const struct super_operations nfs4_sops = {
299         .alloc_inode    = nfs_alloc_inode,
300         .destroy_inode  = nfs_destroy_inode,
301         .write_inode    = nfs_write_inode,
302         .statfs         = nfs_statfs,
303         .clear_inode    = nfs4_clear_inode,
304         .umount_begin   = nfs_umount_begin,
305         .show_options   = nfs_show_options,
306         .show_stats     = nfs_show_stats,
307         .remount_fs     = nfs_remount,
308 };
309 #endif
310
311 static struct shrinker acl_shrinker = {
312         .shrink         = nfs_access_cache_shrinker,
313         .seeks          = DEFAULT_SEEKS,
314 };
315
316 /*
317  * Register the NFS filesystems
318  */
319 int __init register_nfs_fs(void)
320 {
321         int ret;
322
323         ret = register_filesystem(&nfs_fs_type);
324         if (ret < 0)
325                 goto error_0;
326
327         ret = nfs_register_sysctl();
328         if (ret < 0)
329                 goto error_1;
330 #ifdef CONFIG_NFS_V4
331         ret = register_filesystem(&nfs4_fs_type);
332         if (ret < 0)
333                 goto error_2;
334 #endif
335         register_shrinker(&acl_shrinker);
336         return 0;
337
338 #ifdef CONFIG_NFS_V4
339 error_2:
340         nfs_unregister_sysctl();
341 #endif
342 error_1:
343         unregister_filesystem(&nfs_fs_type);
344 error_0:
345         return ret;
346 }
347
348 /*
349  * Unregister the NFS filesystems
350  */
351 void __exit unregister_nfs_fs(void)
352 {
353         unregister_shrinker(&acl_shrinker);
354 #ifdef CONFIG_NFS_V4
355         unregister_filesystem(&nfs4_fs_type);
356 #endif
357         nfs_unregister_sysctl();
358         unregister_filesystem(&nfs_fs_type);
359 }
360
361 void nfs_sb_active(struct super_block *sb)
362 {
363         struct nfs_server *server = NFS_SB(sb);
364
365         if (atomic_inc_return(&server->active) == 1)
366                 atomic_inc(&sb->s_active);
367 }
368
369 void nfs_sb_deactive(struct super_block *sb)
370 {
371         struct nfs_server *server = NFS_SB(sb);
372
373         if (atomic_dec_and_test(&server->active))
374                 deactivate_super(sb);
375 }
376
377 /*
378  * Deliver file system statistics to userspace
379  */
380 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
381 {
382         struct nfs_server *server = NFS_SB(dentry->d_sb);
383         unsigned char blockbits;
384         unsigned long blockres;
385         struct nfs_fh *fh = NFS_FH(dentry->d_inode);
386         struct nfs_fattr fattr;
387         struct nfs_fsstat res = {
388                         .fattr = &fattr,
389         };
390         int error;
391
392         error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
393         if (error < 0)
394                 goto out_err;
395         buf->f_type = NFS_SUPER_MAGIC;
396
397         /*
398          * Current versions of glibc do not correctly handle the
399          * case where f_frsize != f_bsize.  Eventually we want to
400          * report the value of wtmult in this field.
401          */
402         buf->f_frsize = dentry->d_sb->s_blocksize;
403
404         /*
405          * On most *nix systems, f_blocks, f_bfree, and f_bavail
406          * are reported in units of f_frsize.  Linux hasn't had
407          * an f_frsize field in its statfs struct until recently,
408          * thus historically Linux's sys_statfs reports these
409          * fields in units of f_bsize.
410          */
411         buf->f_bsize = dentry->d_sb->s_blocksize;
412         blockbits = dentry->d_sb->s_blocksize_bits;
413         blockres = (1 << blockbits) - 1;
414         buf->f_blocks = (res.tbytes + blockres) >> blockbits;
415         buf->f_bfree = (res.fbytes + blockres) >> blockbits;
416         buf->f_bavail = (res.abytes + blockres) >> blockbits;
417
418         buf->f_files = res.tfiles;
419         buf->f_ffree = res.afiles;
420
421         buf->f_namelen = server->namelen;
422
423         return 0;
424
425  out_err:
426         dprintk("%s: statfs error = %d\n", __func__, -error);
427         return error;
428 }
429
430 /*
431  * Map the security flavour number to a name
432  */
433 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
434 {
435         static const struct {
436                 rpc_authflavor_t flavour;
437                 const char *str;
438         } sec_flavours[] = {
439                 { RPC_AUTH_NULL, "null" },
440                 { RPC_AUTH_UNIX, "sys" },
441                 { RPC_AUTH_GSS_KRB5, "krb5" },
442                 { RPC_AUTH_GSS_KRB5I, "krb5i" },
443                 { RPC_AUTH_GSS_KRB5P, "krb5p" },
444                 { RPC_AUTH_GSS_LKEY, "lkey" },
445                 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
446                 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
447                 { RPC_AUTH_GSS_SPKM, "spkm" },
448                 { RPC_AUTH_GSS_SPKMI, "spkmi" },
449                 { RPC_AUTH_GSS_SPKMP, "spkmp" },
450                 { UINT_MAX, "unknown" }
451         };
452         int i;
453
454         for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
455                 if (sec_flavours[i].flavour == flavour)
456                         break;
457         }
458         return sec_flavours[i].str;
459 }
460
461 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
462                                     int showdefaults)
463 {
464         struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
465
466         switch (sap->sa_family) {
467         case AF_INET: {
468                 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
469                 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
470                 break;
471         }
472         case AF_INET6: {
473                 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
474                 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
475                 break;
476         }
477         default:
478                 if (showdefaults)
479                         seq_printf(m, ",mountaddr=unspecified");
480         }
481
482         if (nfss->mountd_version || showdefaults)
483                 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
484         if (nfss->mountd_port || showdefaults)
485                 seq_printf(m, ",mountport=%u", nfss->mountd_port);
486
487         switch (nfss->mountd_protocol) {
488         case IPPROTO_UDP:
489                 seq_printf(m, ",mountproto=udp");
490                 break;
491         case IPPROTO_TCP:
492                 seq_printf(m, ",mountproto=tcp");
493                 break;
494         default:
495                 if (showdefaults)
496                         seq_printf(m, ",mountproto=auto");
497         }
498 }
499
500 /*
501  * Describe the mount options in force on this server representation
502  */
503 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
504                                    int showdefaults)
505 {
506         static const struct proc_nfs_info {
507                 int flag;
508                 const char *str;
509                 const char *nostr;
510         } nfs_info[] = {
511                 { NFS_MOUNT_SOFT, ",soft", ",hard" },
512                 { NFS_MOUNT_INTR, ",intr", ",nointr" },
513                 { NFS_MOUNT_POSIX, ",posix", "" },
514                 { NFS_MOUNT_NOCTO, ",nocto", "" },
515                 { NFS_MOUNT_NOAC, ",noac", "" },
516                 { NFS_MOUNT_NONLM, ",nolock", "" },
517                 { NFS_MOUNT_NOACL, ",noacl", "" },
518                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
519                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
520                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
521                 { 0, NULL, NULL }
522         };
523         const struct proc_nfs_info *nfs_infop;
524         struct nfs_client *clp = nfss->nfs_client;
525         u32 version = clp->rpc_ops->version;
526
527         seq_printf(m, ",vers=%u", version);
528         seq_printf(m, ",rsize=%u", nfss->rsize);
529         seq_printf(m, ",wsize=%u", nfss->wsize);
530         if (nfss->bsize != 0)
531                 seq_printf(m, ",bsize=%u", nfss->bsize);
532         seq_printf(m, ",namlen=%u", nfss->namelen);
533         if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
534                 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
535         if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
536                 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
537         if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
538                 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
539         if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
540                 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
541         for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
542                 if (nfss->flags & nfs_infop->flag)
543                         seq_puts(m, nfs_infop->str);
544                 else
545                         seq_puts(m, nfs_infop->nostr);
546         }
547         seq_printf(m, ",proto=%s",
548                    rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
549         if (version == 4) {
550                 if (nfss->port != NFS_PORT)
551                         seq_printf(m, ",port=%u", nfss->port);
552         } else
553                 if (nfss->port)
554                         seq_printf(m, ",port=%u", nfss->port);
555
556         seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
557         seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
558         seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
559
560         if (version != 4)
561                 nfs_show_mountd_options(m, nfss, showdefaults);
562
563 #ifdef CONFIG_NFS_V4
564         if (clp->rpc_ops->version == 4)
565                 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
566 #endif
567 }
568
569 /*
570  * Describe the mount options on this VFS mountpoint
571  */
572 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
573 {
574         struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
575
576         nfs_show_mount_options(m, nfss, 0);
577
578         seq_printf(m, ",addr=%s",
579                         rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
580                                                         RPC_DISPLAY_ADDR));
581
582         return 0;
583 }
584
585 /*
586  * Present statistical information for this VFS mountpoint
587  */
588 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
589 {
590         int i, cpu;
591         struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
592         struct rpc_auth *auth = nfss->client->cl_auth;
593         struct nfs_iostats totals = { };
594
595         seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
596
597         /*
598          * Display all mount option settings
599          */
600         seq_printf(m, "\n\topts:\t");
601         seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
602         seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
603         seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
604         seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
605         nfs_show_mount_options(m, nfss, 1);
606
607         seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
608
609         seq_printf(m, "\n\tcaps:\t");
610         seq_printf(m, "caps=0x%x", nfss->caps);
611         seq_printf(m, ",wtmult=%u", nfss->wtmult);
612         seq_printf(m, ",dtsize=%u", nfss->dtsize);
613         seq_printf(m, ",bsize=%u", nfss->bsize);
614         seq_printf(m, ",namlen=%u", nfss->namelen);
615
616 #ifdef CONFIG_NFS_V4
617         if (nfss->nfs_client->rpc_ops->version == 4) {
618                 seq_printf(m, "\n\tnfsv4:\t");
619                 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
620                 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
621                 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
622         }
623 #endif
624
625         /*
626          * Display security flavor in effect for this mount
627          */
628         seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
629         if (auth->au_flavor)
630                 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
631
632         /*
633          * Display superblock I/O counters
634          */
635         for_each_possible_cpu(cpu) {
636                 struct nfs_iostats *stats;
637
638                 preempt_disable();
639                 stats = per_cpu_ptr(nfss->io_stats, cpu);
640
641                 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
642                         totals.events[i] += stats->events[i];
643                 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
644                         totals.bytes[i] += stats->bytes[i];
645
646                 preempt_enable();
647         }
648
649         seq_printf(m, "\n\tevents:\t");
650         for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
651                 seq_printf(m, "%lu ", totals.events[i]);
652         seq_printf(m, "\n\tbytes:\t");
653         for (i = 0; i < __NFSIOS_BYTESMAX; i++)
654                 seq_printf(m, "%Lu ", totals.bytes[i]);
655         seq_printf(m, "\n");
656
657         rpc_print_iostats(m, nfss->client);
658
659         return 0;
660 }
661
662 /*
663  * Begin unmount by attempting to remove all automounted mountpoints we added
664  * in response to xdev traversals and referrals
665  */
666 static void nfs_umount_begin(struct super_block *sb)
667 {
668         struct nfs_server *server = NFS_SB(sb);
669         struct rpc_clnt *rpc;
670
671         /* -EIO all pending I/O */
672         rpc = server->client_acl;
673         if (!IS_ERR(rpc))
674                 rpc_killall_tasks(rpc);
675         rpc = server->client;
676         if (!IS_ERR(rpc))
677                 rpc_killall_tasks(rpc);
678 }
679
680 /*
681  * Sanity-check a server address provided by the mount command.
682  *
683  * Address family must be initialized, and address must not be
684  * the ANY address for that family.
685  */
686 static int nfs_verify_server_address(struct sockaddr *addr)
687 {
688         switch (addr->sa_family) {
689         case AF_INET: {
690                 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
691                 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
692         }
693         case AF_INET6: {
694                 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
695                 return !ipv6_addr_any(sa);
696         }
697         }
698
699         return 0;
700 }
701
702 static void nfs_parse_ipv4_address(char *string, size_t str_len,
703                                    struct sockaddr *sap, size_t *addr_len)
704 {
705         struct sockaddr_in *sin = (struct sockaddr_in *)sap;
706         u8 *addr = (u8 *)&sin->sin_addr.s_addr;
707
708         if (str_len <= INET_ADDRSTRLEN) {
709                 dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n",
710                                 (int)str_len, string);
711
712                 sin->sin_family = AF_INET;
713                 *addr_len = sizeof(*sin);
714                 if (in4_pton(string, str_len, addr, '\0', NULL))
715                         return;
716         }
717
718         sap->sa_family = AF_UNSPEC;
719         *addr_len = 0;
720 }
721
722 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
723 static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len,
724                                    const char *delim,
725                                    struct sockaddr_in6 *sin6)
726 {
727         char *p;
728         size_t len;
729
730         if ((string + str_len) == delim)
731                 return 1;
732
733         if (*delim != IPV6_SCOPE_DELIMITER)
734                 return 0;
735
736         if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
737                 return 0;
738
739         len = (string + str_len) - delim - 1;
740         p = kstrndup(delim + 1, len, GFP_KERNEL);
741         if (p) {
742                 unsigned long scope_id = 0;
743                 struct net_device *dev;
744
745                 dev = dev_get_by_name(&init_net, p);
746                 if (dev != NULL) {
747                         scope_id = dev->ifindex;
748                         dev_put(dev);
749                 } else {
750                         if (strict_strtoul(p, 10, &scope_id) == 0) {
751                                 kfree(p);
752                                 return 0;
753                         }
754                 }
755
756                 kfree(p);
757
758                 sin6->sin6_scope_id = scope_id;
759                 dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id);
760                 return 1;
761         }
762
763         return 0;
764 }
765
766 static void nfs_parse_ipv6_address(char *string, size_t str_len,
767                                    struct sockaddr *sap, size_t *addr_len)
768 {
769         struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
770         u8 *addr = (u8 *)&sin6->sin6_addr.in6_u;
771         const char *delim;
772
773         if (str_len <= INET6_ADDRSTRLEN) {
774                 dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n",
775                                 (int)str_len, string);
776
777                 sin6->sin6_family = AF_INET6;
778                 *addr_len = sizeof(*sin6);
779                 if (in6_pton(string, str_len, addr,
780                                         IPV6_SCOPE_DELIMITER, &delim) != 0) {
781                         if (nfs_parse_ipv6_scope_id(string, str_len,
782                                                         delim, sin6) != 0)
783                                 return;
784                 }
785         }
786
787         sap->sa_family = AF_UNSPEC;
788         *addr_len = 0;
789 }
790 #else
791 static void nfs_parse_ipv6_address(char *string, size_t str_len,
792                                    struct sockaddr *sap, size_t *addr_len)
793 {
794         sap->sa_family = AF_UNSPEC;
795         *addr_len = 0;
796 }
797 #endif
798
799 /*
800  * Construct a sockaddr based on the contents of a string that contains
801  * an IP address in presentation format.
802  *
803  * If there is a problem constructing the new sockaddr, set the address
804  * family to AF_UNSPEC.
805  */
806 void nfs_parse_ip_address(char *string, size_t str_len,
807                                  struct sockaddr *sap, size_t *addr_len)
808 {
809         unsigned int i, colons;
810
811         colons = 0;
812         for (i = 0; i < str_len; i++)
813                 if (string[i] == ':')
814                         colons++;
815
816         if (colons >= 2)
817                 nfs_parse_ipv6_address(string, str_len, sap, addr_len);
818         else
819                 nfs_parse_ipv4_address(string, str_len, sap, addr_len);
820 }
821
822 /*
823  * Sanity check the NFS transport protocol.
824  *
825  */
826 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
827 {
828         switch (mnt->nfs_server.protocol) {
829         case XPRT_TRANSPORT_UDP:
830         case XPRT_TRANSPORT_TCP:
831         case XPRT_TRANSPORT_RDMA:
832                 break;
833         default:
834                 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
835         }
836 }
837
838 /*
839  * For text based NFSv2/v3 mounts, the mount protocol transport default
840  * settings should depend upon the specified NFS transport.
841  */
842 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
843 {
844         nfs_validate_transport_protocol(mnt);
845
846         if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
847             mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
848                         return;
849         switch (mnt->nfs_server.protocol) {
850         case XPRT_TRANSPORT_UDP:
851                 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
852                 break;
853         case XPRT_TRANSPORT_TCP:
854         case XPRT_TRANSPORT_RDMA:
855                 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
856         }
857 }
858
859 /*
860  * Parse the value of the 'sec=' option.
861  *
862  * The flavor_len setting is for v4 mounts.
863  */
864 static int nfs_parse_security_flavors(char *value,
865                                       struct nfs_parsed_mount_data *mnt)
866 {
867         substring_t args[MAX_OPT_ARGS];
868
869         dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
870
871         switch (match_token(value, nfs_secflavor_tokens, args)) {
872         case Opt_sec_none:
873                 mnt->auth_flavor_len = 0;
874                 mnt->auth_flavors[0] = RPC_AUTH_NULL;
875                 break;
876         case Opt_sec_sys:
877                 mnt->auth_flavor_len = 0;
878                 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
879                 break;
880         case Opt_sec_krb5:
881                 mnt->auth_flavor_len = 1;
882                 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
883                 break;
884         case Opt_sec_krb5i:
885                 mnt->auth_flavor_len = 1;
886                 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
887                 break;
888         case Opt_sec_krb5p:
889                 mnt->auth_flavor_len = 1;
890                 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
891                 break;
892         case Opt_sec_lkey:
893                 mnt->auth_flavor_len = 1;
894                 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
895                 break;
896         case Opt_sec_lkeyi:
897                 mnt->auth_flavor_len = 1;
898                 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
899                 break;
900         case Opt_sec_lkeyp:
901                 mnt->auth_flavor_len = 1;
902                 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
903                 break;
904         case Opt_sec_spkm:
905                 mnt->auth_flavor_len = 1;
906                 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
907                 break;
908         case Opt_sec_spkmi:
909                 mnt->auth_flavor_len = 1;
910                 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
911                 break;
912         case Opt_sec_spkmp:
913                 mnt->auth_flavor_len = 1;
914                 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
915                 break;
916         default:
917                 return 0;
918         }
919
920         return 1;
921 }
922
923 static void nfs_parse_invalid_value(const char *option)
924 {
925         dfprintk(MOUNT, "NFS:   bad value specified for %s option\n", option);
926 }
927
928 /*
929  * Error-check and convert a string of mount options from user space into
930  * a data structure.  The whole mount string is processed; bad options are
931  * skipped as they are encountered.  If there were no errors, return 1;
932  * otherwise return 0 (zero).
933  */
934 static int nfs_parse_mount_options(char *raw,
935                                    struct nfs_parsed_mount_data *mnt)
936 {
937         char *p, *string, *secdata;
938         int rc, sloppy = 0, errors = 0;
939
940         if (!raw) {
941                 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
942                 return 1;
943         }
944         dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
945
946         secdata = alloc_secdata();
947         if (!secdata)
948                 goto out_nomem;
949
950         rc = security_sb_copy_data(raw, secdata);
951         if (rc)
952                 goto out_security_failure;
953
954         rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
955         if (rc)
956                 goto out_security_failure;
957
958         free_secdata(secdata);
959
960         while ((p = strsep(&raw, ",")) != NULL) {
961                 substring_t args[MAX_OPT_ARGS];
962                 int option, token;
963
964                 if (!*p)
965                         continue;
966
967                 dfprintk(MOUNT, "NFS:   parsing nfs mount option '%s'\n", p);
968
969                 token = match_token(p, nfs_mount_option_tokens, args);
970                 switch (token) {
971
972                 /*
973                  * boolean options:  foo/nofoo
974                  */
975                 case Opt_soft:
976                         mnt->flags |= NFS_MOUNT_SOFT;
977                         break;
978                 case Opt_hard:
979                         mnt->flags &= ~NFS_MOUNT_SOFT;
980                         break;
981                 case Opt_posix:
982                         mnt->flags |= NFS_MOUNT_POSIX;
983                         break;
984                 case Opt_noposix:
985                         mnt->flags &= ~NFS_MOUNT_POSIX;
986                         break;
987                 case Opt_cto:
988                         mnt->flags &= ~NFS_MOUNT_NOCTO;
989                         break;
990                 case Opt_nocto:
991                         mnt->flags |= NFS_MOUNT_NOCTO;
992                         break;
993                 case Opt_ac:
994                         mnt->flags &= ~NFS_MOUNT_NOAC;
995                         break;
996                 case Opt_noac:
997                         mnt->flags |= NFS_MOUNT_NOAC;
998                         break;
999                 case Opt_lock:
1000                         mnt->flags &= ~NFS_MOUNT_NONLM;
1001                         break;
1002                 case Opt_nolock:
1003                         mnt->flags |= NFS_MOUNT_NONLM;
1004                         break;
1005                 case Opt_v2:
1006                         mnt->flags &= ~NFS_MOUNT_VER3;
1007                         break;
1008                 case Opt_v3:
1009                         mnt->flags |= NFS_MOUNT_VER3;
1010                         break;
1011                 case Opt_udp:
1012                         mnt->flags &= ~NFS_MOUNT_TCP;
1013                         mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1014                         break;
1015                 case Opt_tcp:
1016                         mnt->flags |= NFS_MOUNT_TCP;
1017                         mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1018                         break;
1019                 case Opt_rdma:
1020                         mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
1021                         mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1022                         xprt_load_transport(p);
1023                         break;
1024                 case Opt_acl:
1025                         mnt->flags &= ~NFS_MOUNT_NOACL;
1026                         break;
1027                 case Opt_noacl:
1028                         mnt->flags |= NFS_MOUNT_NOACL;
1029                         break;
1030                 case Opt_rdirplus:
1031                         mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
1032                         break;
1033                 case Opt_nordirplus:
1034                         mnt->flags |= NFS_MOUNT_NORDIRPLUS;
1035                         break;
1036                 case Opt_sharecache:
1037                         mnt->flags &= ~NFS_MOUNT_UNSHARED;
1038                         break;
1039                 case Opt_nosharecache:
1040                         mnt->flags |= NFS_MOUNT_UNSHARED;
1041                         break;
1042                 case Opt_resvport:
1043                         mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1044                         break;
1045                 case Opt_noresvport:
1046                         mnt->flags |= NFS_MOUNT_NORESVPORT;
1047                         break;
1048
1049                 /*
1050                  * options that take numeric values
1051                  */
1052                 case Opt_port:
1053                         if (match_int(args, &option) ||
1054                             option < 0 || option > USHORT_MAX) {
1055                                 errors++;
1056                                 nfs_parse_invalid_value("port");
1057                         } else
1058                                 mnt->nfs_server.port = option;
1059                         break;
1060                 case Opt_rsize:
1061                         if (match_int(args, &option) || option < 0) {
1062                                 errors++;
1063                                 nfs_parse_invalid_value("rsize");
1064                         } else
1065                                 mnt->rsize = option;
1066                         break;
1067                 case Opt_wsize:
1068                         if (match_int(args, &option) || option < 0) {
1069                                 errors++;
1070                                 nfs_parse_invalid_value("wsize");
1071                         } else
1072                                 mnt->wsize = option;
1073                         break;
1074                 case Opt_bsize:
1075                         if (match_int(args, &option) || option < 0) {
1076                                 errors++;
1077                                 nfs_parse_invalid_value("bsize");
1078                         } else
1079                                 mnt->bsize = option;
1080                         break;
1081                 case Opt_timeo:
1082                         if (match_int(args, &option) || option <= 0) {
1083                                 errors++;
1084                                 nfs_parse_invalid_value("timeo");
1085                         } else
1086                                 mnt->timeo = option;
1087                         break;
1088                 case Opt_retrans:
1089                         if (match_int(args, &option) || option <= 0) {
1090                                 errors++;
1091                                 nfs_parse_invalid_value("retrans");
1092                         } else
1093                                 mnt->retrans = option;
1094                         break;
1095                 case Opt_acregmin:
1096                         if (match_int(args, &option) || option < 0) {
1097                                 errors++;
1098                                 nfs_parse_invalid_value("acregmin");
1099                         } else
1100                                 mnt->acregmin = option;
1101                         break;
1102                 case Opt_acregmax:
1103                         if (match_int(args, &option) || option < 0) {
1104                                 errors++;
1105                                 nfs_parse_invalid_value("acregmax");
1106                         } else
1107                                 mnt->acregmax = option;
1108                         break;
1109                 case Opt_acdirmin:
1110                         if (match_int(args, &option) || option < 0) {
1111                                 errors++;
1112                                 nfs_parse_invalid_value("acdirmin");
1113                         } else
1114                                 mnt->acdirmin = option;
1115                         break;
1116                 case Opt_acdirmax:
1117                         if (match_int(args, &option) || option < 0) {
1118                                 errors++;
1119                                 nfs_parse_invalid_value("acdirmax");
1120                         } else
1121                                 mnt->acdirmax = option;
1122                         break;
1123                 case Opt_actimeo:
1124                         if (match_int(args, &option) || option < 0) {
1125                                 errors++;
1126                                 nfs_parse_invalid_value("actimeo");
1127                         } else
1128                                 mnt->acregmin = mnt->acregmax =
1129                                 mnt->acdirmin = mnt->acdirmax = option;
1130                         break;
1131                 case Opt_namelen:
1132                         if (match_int(args, &option) || option < 0) {
1133                                 errors++;
1134                                 nfs_parse_invalid_value("namlen");
1135                         } else
1136                                 mnt->namlen = option;
1137                         break;
1138                 case Opt_mountport:
1139                         if (match_int(args, &option) ||
1140                             option < 0 || option > USHORT_MAX) {
1141                                 errors++;
1142                                 nfs_parse_invalid_value("mountport");
1143                         } else
1144                                 mnt->mount_server.port = option;
1145                         break;
1146                 case Opt_mountvers:
1147                         if (match_int(args, &option) ||
1148                             option < NFS_MNT_VERSION ||
1149                             option > NFS_MNT3_VERSION) {
1150                                 errors++;
1151                                 nfs_parse_invalid_value("mountvers");
1152                         } else
1153                                 mnt->mount_server.version = option;
1154                         break;
1155                 case Opt_nfsvers:
1156                         if (match_int(args, &option)) {
1157                                 errors++;
1158                                 nfs_parse_invalid_value("nfsvers");
1159                                 break;
1160                         }
1161                         switch (option) {
1162                         case NFS2_VERSION:
1163                                 mnt->flags &= ~NFS_MOUNT_VER3;
1164                                 break;
1165                         case NFS3_VERSION:
1166                                 mnt->flags |= NFS_MOUNT_VER3;
1167                                 break;
1168                         default:
1169                                 errors++;
1170                                 nfs_parse_invalid_value("nfsvers");
1171                         }
1172                         break;
1173
1174                 /*
1175                  * options that take text values
1176                  */
1177                 case Opt_sec:
1178                         string = match_strdup(args);
1179                         if (string == NULL)
1180                                 goto out_nomem;
1181                         rc = nfs_parse_security_flavors(string, mnt);
1182                         kfree(string);
1183                         if (!rc) {
1184                                 errors++;
1185                                 dfprintk(MOUNT, "NFS:   unrecognized "
1186                                                 "security flavor\n");
1187                         }
1188                         break;
1189                 case Opt_proto:
1190                         string = match_strdup(args);
1191                         if (string == NULL)
1192                                 goto out_nomem;
1193                         token = match_token(string,
1194                                             nfs_xprt_protocol_tokens, args);
1195                         kfree(string);
1196
1197                         switch (token) {
1198                         case Opt_xprt_udp:
1199                                 mnt->flags &= ~NFS_MOUNT_TCP;
1200                                 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1201                                 break;
1202                         case Opt_xprt_tcp:
1203                                 mnt->flags |= NFS_MOUNT_TCP;
1204                                 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1205                                 break;
1206                         case Opt_xprt_rdma:
1207                                 /* vector side protocols to TCP */
1208                                 mnt->flags |= NFS_MOUNT_TCP;
1209                                 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1210                                 xprt_load_transport(string);
1211                                 break;
1212                         default:
1213                                 errors++;
1214                                 dfprintk(MOUNT, "NFS:   unrecognized "
1215                                                 "transport protocol\n");
1216                         }
1217                         kfree(string);
1218                         break;
1219                 case Opt_mountproto:
1220                         string = match_strdup(args);
1221                         if (string == NULL)
1222                                 goto out_nomem;
1223                         token = match_token(string,
1224                                             nfs_xprt_protocol_tokens, args);
1225
1226                         switch (token) {
1227                         case Opt_xprt_udp:
1228                                 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1229                                 break;
1230                         case Opt_xprt_tcp:
1231                                 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1232                                 break;
1233                         case Opt_xprt_rdma: /* not used for side protocols */
1234                         default:
1235                                 errors++;
1236                                 dfprintk(MOUNT, "NFS:   unrecognized "
1237                                                 "transport protocol\n");
1238                         }
1239                         break;
1240                 case Opt_addr:
1241                         string = match_strdup(args);
1242                         if (string == NULL)
1243                                 goto out_nomem;
1244                         nfs_parse_ip_address(string, strlen(string),
1245                                              (struct sockaddr *)
1246                                                 &mnt->nfs_server.address,
1247                                              &mnt->nfs_server.addrlen);
1248                         kfree(string);
1249                         break;
1250                 case Opt_clientaddr:
1251                         string = match_strdup(args);
1252                         if (string == NULL)
1253                                 goto out_nomem;
1254                         kfree(mnt->client_address);
1255                         mnt->client_address = string;
1256                         break;
1257                 case Opt_mounthost:
1258                         string = match_strdup(args);
1259                         if (string == NULL)
1260                                 goto out_nomem;
1261                         kfree(mnt->mount_server.hostname);
1262                         mnt->mount_server.hostname = string;
1263                         break;
1264                 case Opt_mountaddr:
1265                         string = match_strdup(args);
1266                         if (string == NULL)
1267                                 goto out_nomem;
1268                         nfs_parse_ip_address(string, strlen(string),
1269                                              (struct sockaddr *)
1270                                                 &mnt->mount_server.address,
1271                                              &mnt->mount_server.addrlen);
1272                         kfree(string);
1273                         break;
1274                 case Opt_lookupcache:
1275                         string = match_strdup(args);
1276                         if (string == NULL)
1277                                 goto out_nomem;
1278                         token = match_token(string,
1279                                         nfs_lookupcache_tokens, args);
1280                         kfree(string);
1281                         switch (token) {
1282                                 case Opt_lookupcache_all:
1283                                         mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1284                                         break;
1285                                 case Opt_lookupcache_positive:
1286                                         mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1287                                         mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1288                                         break;
1289                                 case Opt_lookupcache_none:
1290                                         mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1291                                         break;
1292                                 default:
1293                                         errors++;
1294                                         dfprintk(MOUNT, "NFS:   invalid "
1295                                                         "lookupcache argument\n");
1296                         };
1297                         break;
1298
1299                 /*
1300                  * Special options
1301                  */
1302                 case Opt_sloppy:
1303                         sloppy = 1;
1304                         dfprintk(MOUNT, "NFS:   relaxing parsing rules\n");
1305                         break;
1306                 case Opt_userspace:
1307                 case Opt_deprecated:
1308                         dfprintk(MOUNT, "NFS:   ignoring mount option "
1309                                         "'%s'\n", p);
1310                         break;
1311
1312                 default:
1313                         errors++;
1314                         dfprintk(MOUNT, "NFS:   unrecognized mount option "
1315                                         "'%s'\n", p);
1316                 }
1317         }
1318
1319         if (errors > 0) {
1320                 dfprintk(MOUNT, "NFS: parsing encountered %d error%s\n",
1321                                 errors, (errors == 1 ? "" : "s"));
1322                 if (!sloppy)
1323                         return 0;
1324         }
1325         return 1;
1326
1327 out_nomem:
1328         printk(KERN_INFO "NFS: not enough memory to parse option\n");
1329         return 0;
1330 out_security_failure:
1331         free_secdata(secdata);
1332         printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1333         return 0;
1334 }
1335
1336 /*
1337  * Use the remote server's MOUNT service to request the NFS file handle
1338  * corresponding to the provided path.
1339  */
1340 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1341                          struct nfs_fh *root_fh)
1342 {
1343         struct nfs_mount_request request = {
1344                 .sap            = (struct sockaddr *)
1345                                                 &args->mount_server.address,
1346                 .dirpath        = args->nfs_server.export_path,
1347                 .protocol       = args->mount_server.protocol,
1348                 .fh             = root_fh,
1349                 .noresvport     = args->flags & NFS_MOUNT_NORESVPORT,
1350         };
1351         int status;
1352
1353         if (args->mount_server.version == 0) {
1354                 if (args->flags & NFS_MOUNT_VER3)
1355                         args->mount_server.version = NFS_MNT3_VERSION;
1356                 else
1357                         args->mount_server.version = NFS_MNT_VERSION;
1358         }
1359         request.version = args->mount_server.version;
1360
1361         if (args->mount_server.hostname)
1362                 request.hostname = args->mount_server.hostname;
1363         else
1364                 request.hostname = args->nfs_server.hostname;
1365
1366         /*
1367          * Construct the mount server's address.
1368          */
1369         if (args->mount_server.address.ss_family == AF_UNSPEC) {
1370                 memcpy(request.sap, &args->nfs_server.address,
1371                        args->nfs_server.addrlen);
1372                 args->mount_server.addrlen = args->nfs_server.addrlen;
1373         }
1374         request.salen = args->mount_server.addrlen;
1375
1376         /*
1377          * autobind will be used if mount_server.port == 0
1378          */
1379         nfs_set_port(request.sap, args->mount_server.port);
1380
1381         /*
1382          * Now ask the mount server to map our export path
1383          * to a file handle.
1384          */
1385         status = nfs_mount(&request);
1386         if (status == 0)
1387                 return 0;
1388
1389         dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1390                         request.hostname, status);
1391         return status;
1392 }
1393
1394 static int nfs_parse_simple_hostname(const char *dev_name,
1395                                      char **hostname, size_t maxnamlen,
1396                                      char **export_path, size_t maxpathlen)
1397 {
1398         size_t len;
1399         char *colon, *comma;
1400
1401         colon = strchr(dev_name, ':');
1402         if (colon == NULL)
1403                 goto out_bad_devname;
1404
1405         len = colon - dev_name;
1406         if (len > maxnamlen)
1407                 goto out_hostname;
1408
1409         /* N.B. caller will free nfs_server.hostname in all cases */
1410         *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1411         if (!*hostname)
1412                 goto out_nomem;
1413
1414         /* kill possible hostname list: not supported */
1415         comma = strchr(*hostname, ',');
1416         if (comma != NULL) {
1417                 if (comma == *hostname)
1418                         goto out_bad_devname;
1419                 *comma = '\0';
1420         }
1421
1422         colon++;
1423         len = strlen(colon);
1424         if (len > maxpathlen)
1425                 goto out_path;
1426         *export_path = kstrndup(colon, len, GFP_KERNEL);
1427         if (!*export_path)
1428                 goto out_nomem;
1429
1430         dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1431         return 0;
1432
1433 out_bad_devname:
1434         dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1435         return -EINVAL;
1436
1437 out_nomem:
1438         dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1439         return -ENOMEM;
1440
1441 out_hostname:
1442         dfprintk(MOUNT, "NFS: server hostname too long\n");
1443         return -ENAMETOOLONG;
1444
1445 out_path:
1446         dfprintk(MOUNT, "NFS: export pathname too long\n");
1447         return -ENAMETOOLONG;
1448 }
1449
1450 /*
1451  * Hostname has square brackets around it because it contains one or
1452  * more colons.  We look for the first closing square bracket, and a
1453  * colon must follow it.
1454  */
1455 static int nfs_parse_protected_hostname(const char *dev_name,
1456                                         char **hostname, size_t maxnamlen,
1457                                         char **export_path, size_t maxpathlen)
1458 {
1459         size_t len;
1460         char *start, *end;
1461
1462         start = (char *)(dev_name + 1);
1463
1464         end = strchr(start, ']');
1465         if (end == NULL)
1466                 goto out_bad_devname;
1467         if (*(end + 1) != ':')
1468                 goto out_bad_devname;
1469
1470         len = end - start;
1471         if (len > maxnamlen)
1472                 goto out_hostname;
1473
1474         /* N.B. caller will free nfs_server.hostname in all cases */
1475         *hostname = kstrndup(start, len, GFP_KERNEL);
1476         if (*hostname == NULL)
1477                 goto out_nomem;
1478
1479         end += 2;
1480         len = strlen(end);
1481         if (len > maxpathlen)
1482                 goto out_path;
1483         *export_path = kstrndup(end, len, GFP_KERNEL);
1484         if (!*export_path)
1485                 goto out_nomem;
1486
1487         return 0;
1488
1489 out_bad_devname:
1490         dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1491         return -EINVAL;
1492
1493 out_nomem:
1494         dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1495         return -ENOMEM;
1496
1497 out_hostname:
1498         dfprintk(MOUNT, "NFS: server hostname too long\n");
1499         return -ENAMETOOLONG;
1500
1501 out_path:
1502         dfprintk(MOUNT, "NFS: export pathname too long\n");
1503         return -ENAMETOOLONG;
1504 }
1505
1506 /*
1507  * Split "dev_name" into "hostname:export_path".
1508  *
1509  * The leftmost colon demarks the split between the server's hostname
1510  * and the export path.  If the hostname starts with a left square
1511  * bracket, then it may contain colons.
1512  *
1513  * Note: caller frees hostname and export path, even on error.
1514  */
1515 static int nfs_parse_devname(const char *dev_name,
1516                              char **hostname, size_t maxnamlen,
1517                              char **export_path, size_t maxpathlen)
1518 {
1519         if (*dev_name == '[')
1520                 return nfs_parse_protected_hostname(dev_name,
1521                                                     hostname, maxnamlen,
1522                                                     export_path, maxpathlen);
1523
1524         return nfs_parse_simple_hostname(dev_name,
1525                                          hostname, maxnamlen,
1526                                          export_path, maxpathlen);
1527 }
1528
1529 /*
1530  * Validate the NFS2/NFS3 mount data
1531  * - fills in the mount root filehandle
1532  *
1533  * For option strings, user space handles the following behaviors:
1534  *
1535  * + DNS: mapping server host name to IP address ("addr=" option)
1536  *
1537  * + failure mode: how to behave if a mount request can't be handled
1538  *   immediately ("fg/bg" option)
1539  *
1540  * + retry: how often to retry a mount request ("retry=" option)
1541  *
1542  * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1543  *   mountproto=tcp after mountproto=udp, and so on
1544  */
1545 static int nfs_validate_mount_data(void *options,
1546                                    struct nfs_parsed_mount_data *args,
1547                                    struct nfs_fh *mntfh,
1548                                    const char *dev_name)
1549 {
1550         struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1551
1552         if (data == NULL)
1553                 goto out_no_data;
1554
1555         args->flags             = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1556         args->rsize             = NFS_MAX_FILE_IO_SIZE;
1557         args->wsize             = NFS_MAX_FILE_IO_SIZE;
1558         args->acregmin          = NFS_DEF_ACREGMIN;
1559         args->acregmax          = NFS_DEF_ACREGMAX;
1560         args->acdirmin          = NFS_DEF_ACDIRMIN;
1561         args->acdirmax          = NFS_DEF_ACDIRMAX;
1562         args->mount_server.port = 0;    /* autobind unless user sets port */
1563         args->nfs_server.port   = 0;    /* autobind unless user sets port */
1564         args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1565         args->auth_flavors[0]   = RPC_AUTH_UNIX;
1566
1567         switch (data->version) {
1568         case 1:
1569                 data->namlen = 0;
1570         case 2:
1571                 data->bsize = 0;
1572         case 3:
1573                 if (data->flags & NFS_MOUNT_VER3)
1574                         goto out_no_v3;
1575                 data->root.size = NFS2_FHSIZE;
1576                 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1577         case 4:
1578                 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1579                         goto out_no_sec;
1580         case 5:
1581                 memset(data->context, 0, sizeof(data->context));
1582         case 6:
1583                 if (data->flags & NFS_MOUNT_VER3) {
1584                         if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1585                                 goto out_invalid_fh;
1586                         mntfh->size = data->root.size;
1587                 } else
1588                         mntfh->size = NFS2_FHSIZE;
1589
1590
1591                 memcpy(mntfh->data, data->root.data, mntfh->size);
1592                 if (mntfh->size < sizeof(mntfh->data))
1593                         memset(mntfh->data + mntfh->size, 0,
1594                                sizeof(mntfh->data) - mntfh->size);
1595
1596                 /*
1597                  * Translate to nfs_parsed_mount_data, which nfs_fill_super
1598                  * can deal with.
1599                  */
1600                 args->flags             = data->flags & NFS_MOUNT_FLAGMASK;
1601                 args->rsize             = data->rsize;
1602                 args->wsize             = data->wsize;
1603                 args->timeo             = data->timeo;
1604                 args->retrans           = data->retrans;
1605                 args->acregmin          = data->acregmin;
1606                 args->acregmax          = data->acregmax;
1607                 args->acdirmin          = data->acdirmin;
1608                 args->acdirmax          = data->acdirmax;
1609
1610                 memcpy(&args->nfs_server.address, &data->addr,
1611                        sizeof(data->addr));
1612                 args->nfs_server.addrlen = sizeof(data->addr);
1613                 if (!nfs_verify_server_address((struct sockaddr *)
1614                                                 &args->nfs_server.address))
1615                         goto out_no_address;
1616
1617                 if (!(data->flags & NFS_MOUNT_TCP))
1618                         args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1619                 /* N.B. caller will free nfs_server.hostname in all cases */
1620                 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1621                 args->namlen            = data->namlen;
1622                 args->bsize             = data->bsize;
1623
1624                 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1625                         args->auth_flavors[0] = data->pseudoflavor;
1626                 if (!args->nfs_server.hostname)
1627                         goto out_nomem;
1628
1629                 /*
1630                  * The legacy version 6 binary mount data from userspace has a
1631                  * field used only to transport selinux information into the
1632                  * the kernel.  To continue to support that functionality we
1633                  * have a touch of selinux knowledge here in the NFS code. The
1634                  * userspace code converted context=blah to just blah so we are
1635                  * converting back to the full string selinux understands.
1636                  */
1637                 if (data->context[0]){
1638 #ifdef CONFIG_SECURITY_SELINUX
1639                         int rc;
1640                         char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1641                         if (!opts_str)
1642                                 return -ENOMEM;
1643                         strcpy(opts_str, "context=");
1644                         data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1645                         strcat(opts_str, &data->context[0]);
1646                         rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1647                         kfree(opts_str);
1648                         if (rc)
1649                                 return rc;
1650 #else
1651                         return -EINVAL;
1652 #endif
1653                 }
1654
1655                 break;
1656         default: {
1657                 int status;
1658
1659                 if (nfs_parse_mount_options((char *)options, args) == 0)
1660                         return -EINVAL;
1661
1662                 if (!nfs_verify_server_address((struct sockaddr *)
1663                                                 &args->nfs_server.address))
1664                         goto out_no_address;
1665
1666                 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
1667                                 args->nfs_server.port);
1668
1669                 nfs_set_mount_transport_protocol(args);
1670
1671                 status = nfs_parse_devname(dev_name,
1672                                            &args->nfs_server.hostname,
1673                                            PAGE_SIZE,
1674                                            &args->nfs_server.export_path,
1675                                            NFS_MAXPATHLEN);
1676                 if (!status)
1677                         status = nfs_try_mount(args, mntfh);
1678
1679                 kfree(args->nfs_server.export_path);
1680                 args->nfs_server.export_path = NULL;
1681
1682                 if (status)
1683                         return status;
1684
1685                 break;
1686                 }
1687         }
1688
1689 #ifndef CONFIG_NFS_V3
1690         if (args->flags & NFS_MOUNT_VER3)
1691                 goto out_v3_not_compiled;
1692 #endif /* !CONFIG_NFS_V3 */
1693
1694         return 0;
1695
1696 out_no_data:
1697         dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1698         return -EINVAL;
1699
1700 out_no_v3:
1701         dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1702                  data->version);
1703         return -EINVAL;
1704
1705 out_no_sec:
1706         dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1707         return -EINVAL;
1708
1709 #ifndef CONFIG_NFS_V3
1710 out_v3_not_compiled:
1711         dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1712         return -EPROTONOSUPPORT;
1713 #endif /* !CONFIG_NFS_V3 */
1714
1715 out_nomem:
1716         dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1717         return -ENOMEM;
1718
1719 out_no_address:
1720         dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1721         return -EINVAL;
1722
1723 out_invalid_fh:
1724         dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1725         return -EINVAL;
1726 }
1727
1728 static int
1729 nfs_compare_remount_data(struct nfs_server *nfss,
1730                          struct nfs_parsed_mount_data *data)
1731 {
1732         if (data->flags != nfss->flags ||
1733             data->rsize != nfss->rsize ||
1734             data->wsize != nfss->wsize ||
1735             data->retrans != nfss->client->cl_timeout->to_retries ||
1736             data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1737             data->acregmin != nfss->acregmin / HZ ||
1738             data->acregmax != nfss->acregmax / HZ ||
1739             data->acdirmin != nfss->acdirmin / HZ ||
1740             data->acdirmax != nfss->acdirmax / HZ ||
1741             data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1742             data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1743             memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1744                    data->nfs_server.addrlen) != 0)
1745                 return -EINVAL;
1746
1747         return 0;
1748 }
1749
1750 static int
1751 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1752 {
1753         int error;
1754         struct nfs_server *nfss = sb->s_fs_info;
1755         struct nfs_parsed_mount_data *data;
1756         struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1757         struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1758         u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1759
1760         /*
1761          * Userspace mount programs that send binary options generally send
1762          * them populated with default values. We have no way to know which
1763          * ones were explicitly specified. Fall back to legacy behavior and
1764          * just return success.
1765          */
1766         if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1767             (nfsvers <= 3 && (!options || (options->version >= 1 &&
1768                                            options->version <= 6))))
1769                 return 0;
1770
1771         data = kzalloc(sizeof(*data), GFP_KERNEL);
1772         if (data == NULL)
1773                 return -ENOMEM;
1774
1775         /* fill out struct with values from existing mount */
1776         data->flags = nfss->flags;
1777         data->rsize = nfss->rsize;
1778         data->wsize = nfss->wsize;
1779         data->retrans = nfss->client->cl_timeout->to_retries;
1780         data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1781         data->acregmin = nfss->acregmin / HZ;
1782         data->acregmax = nfss->acregmax / HZ;
1783         data->acdirmin = nfss->acdirmin / HZ;
1784         data->acdirmax = nfss->acdirmax / HZ;
1785         data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1786         data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1787         memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1788                 data->nfs_server.addrlen);
1789
1790         /* overwrite those values with any that were specified */
1791         error = nfs_parse_mount_options((char *)options, data);
1792         if (error < 0)
1793                 goto out;
1794
1795         /* compare new mount options with old ones */
1796         error = nfs_compare_remount_data(nfss, data);
1797 out:
1798         kfree(data);
1799         return error;
1800 }
1801
1802 /*
1803  * Initialise the common bits of the superblock
1804  */
1805 static inline void nfs_initialise_sb(struct super_block *sb)
1806 {
1807         struct nfs_server *server = NFS_SB(sb);
1808
1809         sb->s_magic = NFS_SUPER_MAGIC;
1810
1811         /* We probably want something more informative here */
1812         snprintf(sb->s_id, sizeof(sb->s_id),
1813                  "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1814
1815         if (sb->s_blocksize == 0)
1816                 sb->s_blocksize = nfs_block_bits(server->wsize,
1817                                                  &sb->s_blocksize_bits);
1818
1819         if (server->flags & NFS_MOUNT_NOAC)
1820                 sb->s_flags |= MS_SYNCHRONOUS;
1821
1822         nfs_super_set_maxbytes(sb, server->maxfilesize);
1823 }
1824
1825 /*
1826  * Finish setting up an NFS2/3 superblock
1827  */
1828 static void nfs_fill_super(struct super_block *sb,
1829                            struct nfs_parsed_mount_data *data)
1830 {
1831         struct nfs_server *server = NFS_SB(sb);
1832
1833         sb->s_blocksize_bits = 0;
1834         sb->s_blocksize = 0;
1835         if (data->bsize)
1836                 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1837
1838         if (server->flags & NFS_MOUNT_VER3) {
1839                 /* The VFS shouldn't apply the umask to mode bits. We will do
1840                  * so ourselves when necessary.
1841                  */
1842                 sb->s_flags |= MS_POSIXACL;
1843                 sb->s_time_gran = 1;
1844         }
1845
1846         sb->s_op = &nfs_sops;
1847         nfs_initialise_sb(sb);
1848 }
1849
1850 /*
1851  * Finish setting up a cloned NFS2/3 superblock
1852  */
1853 static void nfs_clone_super(struct super_block *sb,
1854                             const struct super_block *old_sb)
1855 {
1856         struct nfs_server *server = NFS_SB(sb);
1857
1858         sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1859         sb->s_blocksize = old_sb->s_blocksize;
1860         sb->s_maxbytes = old_sb->s_maxbytes;
1861
1862         if (server->flags & NFS_MOUNT_VER3) {
1863                 /* The VFS shouldn't apply the umask to mode bits. We will do
1864                  * so ourselves when necessary.
1865                  */
1866                 sb->s_flags |= MS_POSIXACL;
1867                 sb->s_time_gran = 1;
1868         }
1869
1870         sb->s_op = old_sb->s_op;
1871         nfs_initialise_sb(sb);
1872 }
1873
1874 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1875 {
1876         const struct nfs_server *a = s->s_fs_info;
1877         const struct rpc_clnt *clnt_a = a->client;
1878         const struct rpc_clnt *clnt_b = b->client;
1879
1880         if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1881                 goto Ebusy;
1882         if (a->nfs_client != b->nfs_client)
1883                 goto Ebusy;
1884         if (a->flags != b->flags)
1885                 goto Ebusy;
1886         if (a->wsize != b->wsize)
1887                 goto Ebusy;
1888         if (a->rsize != b->rsize)
1889                 goto Ebusy;
1890         if (a->acregmin != b->acregmin)
1891                 goto Ebusy;
1892         if (a->acregmax != b->acregmax)
1893                 goto Ebusy;
1894         if (a->acdirmin != b->acdirmin)
1895                 goto Ebusy;
1896         if (a->acdirmax != b->acdirmax)
1897                 goto Ebusy;
1898         if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1899                 goto Ebusy;
1900         return 1;
1901 Ebusy:
1902         return 0;
1903 }
1904
1905 struct nfs_sb_mountdata {
1906         struct nfs_server *server;
1907         int mntflags;
1908 };
1909
1910 static int nfs_set_super(struct super_block *s, void *data)
1911 {
1912         struct nfs_sb_mountdata *sb_mntdata = data;
1913         struct nfs_server *server = sb_mntdata->server;
1914         int ret;
1915
1916         s->s_flags = sb_mntdata->mntflags;
1917         s->s_fs_info = server;
1918         ret = set_anon_super(s, server);
1919         if (ret == 0)
1920                 server->s_dev = s->s_dev;
1921         return ret;
1922 }
1923
1924 static int nfs_compare_super_address(struct nfs_server *server1,
1925                                      struct nfs_server *server2)
1926 {
1927         struct sockaddr *sap1, *sap2;
1928
1929         sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
1930         sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
1931
1932         if (sap1->sa_family != sap2->sa_family)
1933                 return 0;
1934
1935         switch (sap1->sa_family) {
1936         case AF_INET: {
1937                 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
1938                 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
1939                 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
1940                         return 0;
1941                 if (sin1->sin_port != sin2->sin_port)
1942                         return 0;
1943                 break;
1944         }
1945         case AF_INET6: {
1946                 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
1947                 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
1948                 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
1949                         return 0;
1950                 if (sin1->sin6_port != sin2->sin6_port)
1951                         return 0;
1952                 break;
1953         }
1954         default:
1955                 return 0;
1956         }
1957
1958         return 1;
1959 }
1960
1961 static int nfs_compare_super(struct super_block *sb, void *data)
1962 {
1963         struct nfs_sb_mountdata *sb_mntdata = data;
1964         struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1965         int mntflags = sb_mntdata->mntflags;
1966
1967         if (!nfs_compare_super_address(old, server))
1968                 return 0;
1969         /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1970         if (old->flags & NFS_MOUNT_UNSHARED)
1971                 return 0;
1972         if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1973                 return 0;
1974         return nfs_compare_mount_options(sb, server, mntflags);
1975 }
1976
1977 static int nfs_bdi_register(struct nfs_server *server)
1978 {
1979         return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1980 }
1981
1982 static int nfs_get_sb(struct file_system_type *fs_type,
1983         int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1984 {
1985         struct nfs_server *server = NULL;
1986         struct super_block *s;
1987         struct nfs_parsed_mount_data *data;
1988         struct nfs_fh *mntfh;
1989         struct dentry *mntroot;
1990         int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1991         struct nfs_sb_mountdata sb_mntdata = {
1992                 .mntflags = flags,
1993         };
1994         int error = -ENOMEM;
1995
1996         data = kzalloc(sizeof(*data), GFP_KERNEL);
1997         mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
1998         if (data == NULL || mntfh == NULL)
1999                 goto out_free_fh;
2000
2001         security_init_mnt_opts(&data->lsm_opts);
2002
2003         /* Validate the mount data */
2004         error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2005         if (error < 0)
2006                 goto out;
2007
2008         /* Get a volume representation */
2009         server = nfs_create_server(data, mntfh);
2010         if (IS_ERR(server)) {
2011                 error = PTR_ERR(server);
2012                 goto out;
2013         }
2014         sb_mntdata.server = server;
2015
2016         if (server->flags & NFS_MOUNT_UNSHARED)
2017                 compare_super = NULL;
2018
2019         /* Get a superblock - note that we may end up sharing one that already exists */
2020         s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2021         if (IS_ERR(s)) {
2022                 error = PTR_ERR(s);
2023                 goto out_err_nosb;
2024         }
2025
2026         if (s->s_fs_info != server) {
2027                 nfs_free_server(server);
2028                 server = NULL;
2029         } else {
2030                 error = nfs_bdi_register(server);
2031                 if (error)
2032                         goto error_splat_super;
2033         }
2034
2035         if (!s->s_root) {
2036                 /* initial superblock/root creation */
2037                 nfs_fill_super(s, data);
2038                 nfs_fscache_get_super_cookie(s, data);
2039         }
2040
2041         mntroot = nfs_get_root(s, mntfh);
2042         if (IS_ERR(mntroot)) {
2043                 error = PTR_ERR(mntroot);
2044                 goto error_splat_super;
2045         }
2046
2047         error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2048         if (error)
2049                 goto error_splat_root;
2050
2051         s->s_flags |= MS_ACTIVE;
2052         mnt->mnt_sb = s;
2053         mnt->mnt_root = mntroot;
2054         error = 0;
2055
2056 out:
2057         kfree(data->nfs_server.hostname);
2058         kfree(data->mount_server.hostname);
2059         kfree(data->fscache_uniq);
2060         security_free_mnt_opts(&data->lsm_opts);
2061 out_free_fh:
2062         kfree(mntfh);
2063         kfree(data);
2064         return error;
2065
2066 out_err_nosb:
2067         nfs_free_server(server);
2068         goto out;
2069
2070 error_splat_root:
2071         dput(mntroot);
2072 error_splat_super:
2073         up_write(&s->s_umount);
2074         deactivate_super(s);
2075         goto out;
2076 }
2077
2078 /*
2079  * Destroy an NFS2/3 superblock
2080  */
2081 static void nfs_kill_super(struct super_block *s)
2082 {
2083         struct nfs_server *server = NFS_SB(s);
2084
2085         bdi_unregister(&server->backing_dev_info);
2086         kill_anon_super(s);
2087         nfs_fscache_release_super_cookie(s);
2088         nfs_free_server(server);
2089 }
2090
2091 /*
2092  * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2093  */
2094 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2095                            const char *dev_name, void *raw_data,
2096                            struct vfsmount *mnt)
2097 {
2098         struct nfs_clone_mount *data = raw_data;
2099         struct super_block *s;
2100         struct nfs_server *server;
2101         struct dentry *mntroot;
2102         int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2103         struct nfs_sb_mountdata sb_mntdata = {
2104                 .mntflags = flags,
2105         };
2106         int error;
2107
2108         dprintk("--> nfs_xdev_get_sb()\n");
2109
2110         /* create a new volume representation */
2111         server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2112         if (IS_ERR(server)) {
2113                 error = PTR_ERR(server);
2114                 goto out_err_noserver;
2115         }
2116         sb_mntdata.server = server;
2117
2118         if (server->flags & NFS_MOUNT_UNSHARED)
2119                 compare_super = NULL;
2120
2121         /* Get a superblock - note that we may end up sharing one that already exists */
2122         s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2123         if (IS_ERR(s)) {
2124                 error = PTR_ERR(s);
2125                 goto out_err_nosb;
2126         }
2127
2128         if (s->s_fs_info != server) {
2129                 nfs_free_server(server);
2130                 server = NULL;
2131         } else {
2132                 error = nfs_bdi_register(server);
2133                 if (error)
2134                         goto error_splat_super;
2135         }
2136
2137         if (!s->s_root) {
2138                 /* initial superblock/root creation */
2139                 nfs_clone_super(s, data->sb);
2140         }
2141
2142         mntroot = nfs_get_root(s, data->fh);
2143         if (IS_ERR(mntroot)) {
2144                 error = PTR_ERR(mntroot);
2145                 goto error_splat_super;
2146         }
2147         if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2148                 dput(mntroot);
2149                 error = -ESTALE;
2150                 goto error_splat_super;
2151         }
2152
2153         s->s_flags |= MS_ACTIVE;
2154         mnt->mnt_sb = s;
2155         mnt->mnt_root = mntroot;
2156
2157         /* clone any lsm security options from the parent to the new sb */
2158         security_sb_clone_mnt_opts(data->sb, s);
2159
2160         dprintk("<-- nfs_xdev_get_sb() = 0\n");
2161         return 0;
2162
2163 out_err_nosb:
2164         nfs_free_server(server);
2165 out_err_noserver:
2166         dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2167         return error;
2168
2169 error_splat_super:
2170         up_write(&s->s_umount);
2171         deactivate_super(s);
2172         dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2173         return error;
2174 }
2175
2176 #ifdef CONFIG_NFS_V4
2177
2178 /*
2179  * Finish setting up a cloned NFS4 superblock
2180  */
2181 static void nfs4_clone_super(struct super_block *sb,
2182                             const struct super_block *old_sb)
2183 {
2184         sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2185         sb->s_blocksize = old_sb->s_blocksize;
2186         sb->s_maxbytes = old_sb->s_maxbytes;
2187         sb->s_time_gran = 1;
2188         sb->s_op = old_sb->s_op;
2189         nfs_initialise_sb(sb);
2190 }
2191
2192 /*
2193  * Set up an NFS4 superblock
2194  */
2195 static void nfs4_fill_super(struct super_block *sb)
2196 {
2197         sb->s_time_gran = 1;
2198         sb->s_op = &nfs4_sops;
2199         nfs_initialise_sb(sb);
2200 }
2201
2202 /*
2203  * Validate NFSv4 mount options
2204  */
2205 static int nfs4_validate_mount_data(void *options,
2206                                     struct nfs_parsed_mount_data *args,
2207                                     const char *dev_name)
2208 {
2209         struct sockaddr_in *ap;
2210         struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2211         char *c;
2212
2213         if (data == NULL)
2214                 goto out_no_data;
2215
2216         args->rsize             = NFS_MAX_FILE_IO_SIZE;
2217         args->wsize             = NFS_MAX_FILE_IO_SIZE;
2218         args->acregmin          = NFS_DEF_ACREGMIN;
2219         args->acregmax          = NFS_DEF_ACREGMAX;
2220         args->acdirmin          = NFS_DEF_ACDIRMIN;
2221         args->acdirmax          = NFS_DEF_ACDIRMAX;
2222         args->nfs_server.port   = NFS_PORT; /* 2049 unless user set port= */
2223         args->auth_flavors[0]   = RPC_AUTH_UNIX;
2224         args->auth_flavor_len   = 0;
2225
2226         switch (data->version) {
2227         case 1:
2228                 ap = (struct sockaddr_in *)&args->nfs_server.address;
2229                 if (data->host_addrlen > sizeof(args->nfs_server.address))
2230                         goto out_no_address;
2231                 if (data->host_addrlen == 0)
2232                         goto out_no_address;
2233                 args->nfs_server.addrlen = data->host_addrlen;
2234                 if (copy_from_user(ap, data->host_addr, data->host_addrlen))
2235                         return -EFAULT;
2236                 if (!nfs_verify_server_address((struct sockaddr *)
2237                                                 &args->nfs_server.address))
2238                         goto out_no_address;
2239
2240                 if (data->auth_flavourlen) {
2241                         if (data->auth_flavourlen > 1)
2242                                 goto out_inval_auth;
2243                         if (copy_from_user(&args->auth_flavors[0],
2244                                            data->auth_flavours,
2245                                            sizeof(args->auth_flavors[0])))
2246                                 return -EFAULT;
2247                 }
2248
2249                 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2250                 if (IS_ERR(c))
2251                         return PTR_ERR(c);
2252                 args->nfs_server.hostname = c;
2253
2254                 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2255                 if (IS_ERR(c))
2256                         return PTR_ERR(c);
2257                 args->nfs_server.export_path = c;
2258                 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2259
2260                 c = strndup_user(data->client_addr.data, 16);
2261                 if (IS_ERR(c))
2262                         return PTR_ERR(c);
2263                 args->client_address = c;
2264
2265                 /*
2266                  * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2267                  * can deal with.
2268                  */
2269
2270                 args->flags     = data->flags & NFS4_MOUNT_FLAGMASK;
2271                 args->rsize     = data->rsize;
2272                 args->wsize     = data->wsize;
2273                 args->timeo     = data->timeo;
2274                 args->retrans   = data->retrans;
2275                 args->acregmin  = data->acregmin;
2276                 args->acregmax  = data->acregmax;
2277                 args->acdirmin  = data->acdirmin;
2278                 args->acdirmax  = data->acdirmax;
2279                 args->nfs_server.protocol = data->proto;
2280                 nfs_validate_transport_protocol(args);
2281
2282                 break;
2283         default: {
2284                 int status;
2285
2286                 if (nfs_parse_mount_options((char *)options, args) == 0)
2287                         return -EINVAL;
2288
2289                 if (!nfs_verify_server_address((struct sockaddr *)
2290                                                 &args->nfs_server.address))
2291                         return -EINVAL;
2292
2293                 nfs_set_port((struct sockaddr *)&args->nfs_server.address,
2294                                 args->nfs_server.port);
2295
2296                 nfs_validate_transport_protocol(args);
2297
2298                 if (args->auth_flavor_len > 1)
2299                         goto out_inval_auth;
2300
2301                 if (args->client_address == NULL)
2302                         goto out_no_client_address;
2303
2304                 status = nfs_parse_devname(dev_name,
2305                                            &args->nfs_server.hostname,
2306                                            NFS4_MAXNAMLEN,
2307                                            &args->nfs_server.export_path,
2308                                            NFS4_MAXPATHLEN);
2309                 if (status < 0)
2310                         return status;
2311
2312                 break;
2313                 }
2314         }
2315
2316         return 0;
2317
2318 out_no_data:
2319         dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2320         return -EINVAL;
2321
2322 out_inval_auth:
2323         dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2324                  data->auth_flavourlen);
2325         return -EINVAL;
2326
2327 out_no_address:
2328         dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2329         return -EINVAL;
2330
2331 out_no_client_address:
2332         dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
2333         return -EINVAL;
2334 }
2335
2336 /*
2337  * Get the superblock for an NFS4 mountpoint
2338  */
2339 static int nfs4_get_sb(struct file_system_type *fs_type,
2340         int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2341 {
2342         struct nfs_parsed_mount_data *data;
2343         struct super_block *s;
2344         struct nfs_server *server;
2345         struct nfs_fh *mntfh;
2346         struct dentry *mntroot;
2347         int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2348         struct nfs_sb_mountdata sb_mntdata = {
2349                 .mntflags = flags,
2350         };
2351         int error = -ENOMEM;
2352
2353         data = kzalloc(sizeof(*data), GFP_KERNEL);
2354         mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2355         if (data == NULL || mntfh == NULL)
2356                 goto out_free_fh;
2357
2358         security_init_mnt_opts(&data->lsm_opts);
2359
2360         /* Validate the mount data */
2361         error = nfs4_validate_mount_data(raw_data, data, dev_name);
2362         if (error < 0)
2363                 goto out;
2364
2365         /* Get a volume representation */
2366         server = nfs4_create_server(data, mntfh);
2367         if (IS_ERR(server)) {
2368                 error = PTR_ERR(server);
2369                 goto out;
2370         }
2371         sb_mntdata.server = server;
2372
2373         if (server->flags & NFS4_MOUNT_UNSHARED)
2374                 compare_super = NULL;
2375
2376         /* Get a superblock - note that we may end up sharing one that already exists */
2377         s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2378         if (IS_ERR(s)) {
2379                 error = PTR_ERR(s);
2380                 goto out_free;
2381         }
2382
2383         if (s->s_fs_info != server) {
2384                 nfs_free_server(server);
2385                 server = NULL;
2386         } else {
2387                 error = nfs_bdi_register(server);
2388                 if (error)
2389                         goto error_splat_super;
2390         }
2391
2392         if (!s->s_root) {
2393                 /* initial superblock/root creation */
2394                 nfs4_fill_super(s);
2395                 nfs_fscache_get_super_cookie(s, data);
2396         }
2397
2398         mntroot = nfs4_get_root(s, mntfh);
2399         if (IS_ERR(mntroot)) {
2400                 error = PTR_ERR(mntroot);
2401                 goto error_splat_super;
2402         }
2403
2404         error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2405         if (error)
2406                 goto error_splat_root;
2407
2408         s->s_flags |= MS_ACTIVE;
2409         mnt->mnt_sb = s;
2410         mnt->mnt_root = mntroot;
2411         error = 0;
2412
2413 out:
2414         kfree(data->client_address);
2415         kfree(data->nfs_server.export_path);
2416         kfree(data->nfs_server.hostname);
2417         kfree(data->fscache_uniq);
2418         security_free_mnt_opts(&data->lsm_opts);
2419 out_free_fh:
2420         kfree(mntfh);
2421         kfree(data);
2422         return error;
2423
2424 out_free:
2425         nfs_free_server(server);
2426         goto out;
2427
2428 error_splat_root:
2429         dput(mntroot);
2430 error_splat_super:
2431         up_write(&s->s_umount);
2432         deactivate_super(s);
2433         goto out;
2434 }
2435
2436 static void nfs4_kill_super(struct super_block *sb)
2437 {
2438         struct nfs_server *server = NFS_SB(sb);
2439
2440         nfs_super_return_all_delegations(sb);
2441         kill_anon_super(sb);
2442
2443         nfs4_renewd_prepare_shutdown(server);
2444         nfs_fscache_release_super_cookie(sb);
2445         nfs_free_server(server);
2446 }
2447
2448 /*
2449  * Clone an NFS4 server record on xdev traversal (FSID-change)
2450  */
2451 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2452                             const char *dev_name, void *raw_data,
2453                             struct vfsmount *mnt)
2454 {
2455         struct nfs_clone_mount *data = raw_data;
2456         struct super_block *s;
2457         struct nfs_server *server;
2458         struct dentry *mntroot;
2459         int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2460         struct nfs_sb_mountdata sb_mntdata = {
2461                 .mntflags = flags,
2462         };
2463         int error;
2464
2465         dprintk("--> nfs4_xdev_get_sb()\n");
2466
2467         /* create a new volume representation */
2468         server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2469         if (IS_ERR(server)) {
2470                 error = PTR_ERR(server);
2471                 goto out_err_noserver;
2472         }
2473         sb_mntdata.server = server;
2474
2475         if (server->flags & NFS4_MOUNT_UNSHARED)
2476                 compare_super = NULL;
2477
2478         /* Get a superblock - note that we may end up sharing one that already exists */
2479         s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2480         if (IS_ERR(s)) {
2481                 error = PTR_ERR(s);
2482                 goto out_err_nosb;
2483         }
2484
2485         if (s->s_fs_info != server) {
2486                 nfs_free_server(server);
2487                 server = NULL;
2488         } else {
2489                 error = nfs_bdi_register(server);
2490                 if (error)
2491                         goto error_splat_super;
2492         }
2493
2494         if (!s->s_root) {
2495                 /* initial superblock/root creation */
2496                 nfs4_clone_super(s, data->sb);
2497         }
2498
2499         mntroot = nfs4_get_root(s, data->fh);
2500         if (IS_ERR(mntroot)) {
2501                 error = PTR_ERR(mntroot);
2502                 goto error_splat_super;
2503         }
2504         if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2505                 dput(mntroot);
2506                 error = -ESTALE;
2507                 goto error_splat_super;
2508         }
2509
2510         s->s_flags |= MS_ACTIVE;
2511         mnt->mnt_sb = s;
2512         mnt->mnt_root = mntroot;
2513
2514         security_sb_clone_mnt_opts(data->sb, s);
2515
2516         dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2517         return 0;
2518
2519 out_err_nosb:
2520         nfs_free_server(server);
2521 out_err_noserver:
2522         dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2523         return error;
2524
2525 error_splat_super:
2526         up_write(&s->s_umount);
2527         deactivate_super(s);
2528         dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2529         return error;
2530 }
2531
2532 /*
2533  * Create an NFS4 server record on referral traversal
2534  */
2535 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2536                                 const char *dev_name, void *raw_data,
2537                                 struct vfsmount *mnt)
2538 {
2539         struct nfs_clone_mount *data = raw_data;
2540         struct super_block *s;
2541         struct nfs_server *server;
2542         struct dentry *mntroot;
2543         struct nfs_fh mntfh;
2544         int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2545         struct nfs_sb_mountdata sb_mntdata = {
2546                 .mntflags = flags,
2547         };
2548         int error;
2549
2550         dprintk("--> nfs4_referral_get_sb()\n");
2551
2552         /* create a new volume representation */
2553         server = nfs4_create_referral_server(data, &mntfh);
2554         if (IS_ERR(server)) {
2555                 error = PTR_ERR(server);
2556                 goto out_err_noserver;
2557         }
2558         sb_mntdata.server = server;
2559
2560         if (server->flags & NFS4_MOUNT_UNSHARED)
2561                 compare_super = NULL;
2562
2563         /* Get a superblock - note that we may end up sharing one that already exists */
2564         s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2565         if (IS_ERR(s)) {
2566                 error = PTR_ERR(s);
2567                 goto out_err_nosb;
2568         }
2569
2570         if (s->s_fs_info != server) {
2571                 nfs_free_server(server);
2572                 server = NULL;
2573         } else {
2574                 error = nfs_bdi_register(server);
2575                 if (error)
2576                         goto error_splat_super;
2577         }
2578
2579         if (!s->s_root) {
2580                 /* initial superblock/root creation */
2581                 nfs4_fill_super(s);
2582         }
2583
2584         mntroot = nfs4_get_root(s, &mntfh);
2585         if (IS_ERR(mntroot)) {
2586                 error = PTR_ERR(mntroot);
2587                 goto error_splat_super;
2588         }
2589         if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2590                 dput(mntroot);
2591                 error = -ESTALE;
2592                 goto error_splat_super;
2593         }
2594
2595         s->s_flags |= MS_ACTIVE;
2596         mnt->mnt_sb = s;
2597         mnt->mnt_root = mntroot;
2598
2599         security_sb_clone_mnt_opts(data->sb, s);
2600
2601         dprintk("<-- nfs4_referral_get_sb() = 0\n");
2602         return 0;
2603
2604 out_err_nosb:
2605         nfs_free_server(server);
2606 out_err_noserver:
2607         dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2608         return error;
2609
2610 error_splat_super:
2611         up_write(&s->s_umount);
2612         deactivate_super(s);
2613         dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2614         return error;
2615 }
2616
2617 #endif /* CONFIG_NFS_V4 */