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