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