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