netfilter: xt_recent: fix regression in rules using a zero hit_count
[linux-2.6/mini2440.git] / fs / nfs / super.c
blob4bf23f6f93cf7b72833e4c2a6872e46ba6c15da6
1 /*
2 * linux/fs/nfs/super.c
4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
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())
23 #include <linux/module.h>
24 #include <linux/init.h>
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/mnt_namespace.h>
46 #include <linux/namei.h>
47 #include <linux/nfs_idmap.h>
48 #include <linux/vfs.h>
49 #include <linux/inet.h>
50 #include <linux/in6.h>
51 #include <net/ipv6.h>
52 #include <linux/netdevice.h>
53 #include <linux/nfs_xdr.h>
54 #include <linux/magic.h>
55 #include <linux/parser.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
60 #include "nfs4_fs.h"
61 #include "callback.h"
62 #include "delegation.h"
63 #include "iostat.h"
64 #include "internal.h"
65 #include "fscache.h"
67 #define NFSDBG_FACILITY NFSDBG_VFS
69 enum {
70 /* Mount options that take no arguments */
71 Opt_soft, Opt_hard,
72 Opt_posix, Opt_noposix,
73 Opt_cto, Opt_nocto,
74 Opt_ac, Opt_noac,
75 Opt_lock, Opt_nolock,
76 Opt_v2, Opt_v3, Opt_v4,
77 Opt_udp, Opt_tcp, Opt_rdma,
78 Opt_acl, Opt_noacl,
79 Opt_rdirplus, Opt_nordirplus,
80 Opt_sharecache, Opt_nosharecache,
81 Opt_resvport, Opt_noresvport,
82 Opt_fscache, Opt_nofscache,
84 /* Mount options that take integer arguments */
85 Opt_port,
86 Opt_rsize, Opt_wsize, Opt_bsize,
87 Opt_timeo, Opt_retrans,
88 Opt_acregmin, Opt_acregmax,
89 Opt_acdirmin, Opt_acdirmax,
90 Opt_actimeo,
91 Opt_namelen,
92 Opt_mountport,
93 Opt_mountvers,
94 Opt_nfsvers,
95 Opt_minorversion,
97 /* Mount options that take string arguments */
98 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
99 Opt_addr, Opt_mountaddr, Opt_clientaddr,
100 Opt_lookupcache,
101 Opt_fscache_uniq,
103 /* Special mount options */
104 Opt_userspace, Opt_deprecated, Opt_sloppy,
106 Opt_err
109 static const match_table_t nfs_mount_option_tokens = {
110 { Opt_userspace, "bg" },
111 { Opt_userspace, "fg" },
112 { Opt_userspace, "retry=%s" },
114 { Opt_sloppy, "sloppy" },
116 { Opt_soft, "soft" },
117 { Opt_hard, "hard" },
118 { Opt_deprecated, "intr" },
119 { Opt_deprecated, "nointr" },
120 { Opt_posix, "posix" },
121 { Opt_noposix, "noposix" },
122 { Opt_cto, "cto" },
123 { Opt_nocto, "nocto" },
124 { Opt_ac, "ac" },
125 { Opt_noac, "noac" },
126 { Opt_lock, "lock" },
127 { Opt_nolock, "nolock" },
128 { Opt_v2, "v2" },
129 { Opt_v3, "v3" },
130 { Opt_v4, "v4" },
131 { Opt_udp, "udp" },
132 { Opt_tcp, "tcp" },
133 { Opt_rdma, "rdma" },
134 { Opt_acl, "acl" },
135 { Opt_noacl, "noacl" },
136 { Opt_rdirplus, "rdirplus" },
137 { Opt_nordirplus, "nordirplus" },
138 { Opt_sharecache, "sharecache" },
139 { Opt_nosharecache, "nosharecache" },
140 { Opt_resvport, "resvport" },
141 { Opt_noresvport, "noresvport" },
142 { Opt_fscache, "fsc" },
143 { Opt_fscache_uniq, "fsc=%s" },
144 { Opt_nofscache, "nofsc" },
146 { Opt_port, "port=%s" },
147 { Opt_rsize, "rsize=%s" },
148 { Opt_wsize, "wsize=%s" },
149 { Opt_bsize, "bsize=%s" },
150 { Opt_timeo, "timeo=%s" },
151 { Opt_retrans, "retrans=%s" },
152 { Opt_acregmin, "acregmin=%s" },
153 { Opt_acregmax, "acregmax=%s" },
154 { Opt_acdirmin, "acdirmin=%s" },
155 { Opt_acdirmax, "acdirmax=%s" },
156 { Opt_actimeo, "actimeo=%s" },
157 { Opt_namelen, "namlen=%s" },
158 { Opt_mountport, "mountport=%s" },
159 { Opt_mountvers, "mountvers=%s" },
160 { Opt_nfsvers, "nfsvers=%s" },
161 { Opt_nfsvers, "vers=%s" },
162 { Opt_minorversion, "minorversion=%s" },
164 { Opt_sec, "sec=%s" },
165 { Opt_proto, "proto=%s" },
166 { Opt_mountproto, "mountproto=%s" },
167 { Opt_addr, "addr=%s" },
168 { Opt_clientaddr, "clientaddr=%s" },
169 { Opt_mounthost, "mounthost=%s" },
170 { Opt_mountaddr, "mountaddr=%s" },
172 { Opt_lookupcache, "lookupcache=%s" },
174 { Opt_err, NULL }
177 enum {
178 Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma,
180 Opt_xprt_err
183 static const match_table_t nfs_xprt_protocol_tokens = {
184 { Opt_xprt_udp, "udp" },
185 { Opt_xprt_tcp, "tcp" },
186 { Opt_xprt_rdma, "rdma" },
188 { Opt_xprt_err, NULL }
191 enum {
192 Opt_sec_none, Opt_sec_sys,
193 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
194 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
195 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
197 Opt_sec_err
200 static const match_table_t nfs_secflavor_tokens = {
201 { Opt_sec_none, "none" },
202 { Opt_sec_none, "null" },
203 { Opt_sec_sys, "sys" },
205 { Opt_sec_krb5, "krb5" },
206 { Opt_sec_krb5i, "krb5i" },
207 { Opt_sec_krb5p, "krb5p" },
209 { Opt_sec_lkey, "lkey" },
210 { Opt_sec_lkeyi, "lkeyi" },
211 { Opt_sec_lkeyp, "lkeyp" },
213 { Opt_sec_spkm, "spkm3" },
214 { Opt_sec_spkmi, "spkm3i" },
215 { Opt_sec_spkmp, "spkm3p" },
217 { Opt_sec_err, NULL }
220 enum {
221 Opt_lookupcache_all, Opt_lookupcache_positive,
222 Opt_lookupcache_none,
224 Opt_lookupcache_err
227 static match_table_t nfs_lookupcache_tokens = {
228 { Opt_lookupcache_all, "all" },
229 { Opt_lookupcache_positive, "pos" },
230 { Opt_lookupcache_positive, "positive" },
231 { Opt_lookupcache_none, "none" },
233 { Opt_lookupcache_err, NULL }
237 static void nfs_umount_begin(struct super_block *);
238 static int nfs_statfs(struct dentry *, struct kstatfs *);
239 static int nfs_show_options(struct seq_file *, struct vfsmount *);
240 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
241 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
242 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
243 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
244 static void nfs_put_super(struct super_block *);
245 static void nfs_kill_super(struct super_block *);
246 static int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
248 static struct file_system_type nfs_fs_type = {
249 .owner = THIS_MODULE,
250 .name = "nfs",
251 .get_sb = nfs_get_sb,
252 .kill_sb = nfs_kill_super,
253 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
256 struct file_system_type nfs_xdev_fs_type = {
257 .owner = THIS_MODULE,
258 .name = "nfs",
259 .get_sb = nfs_xdev_get_sb,
260 .kill_sb = nfs_kill_super,
261 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
264 static const struct super_operations nfs_sops = {
265 .alloc_inode = nfs_alloc_inode,
266 .destroy_inode = nfs_destroy_inode,
267 .write_inode = nfs_write_inode,
268 .put_super = nfs_put_super,
269 .statfs = nfs_statfs,
270 .clear_inode = nfs_clear_inode,
271 .umount_begin = nfs_umount_begin,
272 .show_options = nfs_show_options,
273 .show_stats = nfs_show_stats,
274 .remount_fs = nfs_remount,
277 #ifdef CONFIG_NFS_V4
278 static int nfs4_validate_text_mount_data(void *options,
279 struct nfs_parsed_mount_data *args, const char *dev_name);
280 static int nfs4_try_mount(int flags, const char *dev_name,
281 struct nfs_parsed_mount_data *data, struct vfsmount *mnt);
282 static int nfs4_get_sb(struct file_system_type *fs_type,
283 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
284 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
285 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
286 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
287 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
288 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
289 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
290 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
291 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
292 static void nfs4_kill_super(struct super_block *sb);
294 static struct file_system_type nfs4_fs_type = {
295 .owner = THIS_MODULE,
296 .name = "nfs4",
297 .get_sb = nfs4_get_sb,
298 .kill_sb = nfs4_kill_super,
299 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
302 static struct file_system_type nfs4_remote_fs_type = {
303 .owner = THIS_MODULE,
304 .name = "nfs4",
305 .get_sb = nfs4_remote_get_sb,
306 .kill_sb = nfs4_kill_super,
307 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
310 struct file_system_type nfs4_xdev_fs_type = {
311 .owner = THIS_MODULE,
312 .name = "nfs4",
313 .get_sb = nfs4_xdev_get_sb,
314 .kill_sb = nfs4_kill_super,
315 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
318 static struct file_system_type nfs4_remote_referral_fs_type = {
319 .owner = THIS_MODULE,
320 .name = "nfs4",
321 .get_sb = nfs4_remote_referral_get_sb,
322 .kill_sb = nfs4_kill_super,
323 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
326 struct file_system_type nfs4_referral_fs_type = {
327 .owner = THIS_MODULE,
328 .name = "nfs4",
329 .get_sb = nfs4_referral_get_sb,
330 .kill_sb = nfs4_kill_super,
331 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
334 static const struct super_operations nfs4_sops = {
335 .alloc_inode = nfs_alloc_inode,
336 .destroy_inode = nfs_destroy_inode,
337 .write_inode = nfs_write_inode,
338 .put_super = nfs_put_super,
339 .statfs = nfs_statfs,
340 .clear_inode = nfs4_clear_inode,
341 .umount_begin = nfs_umount_begin,
342 .show_options = nfs_show_options,
343 .show_stats = nfs_show_stats,
344 .remount_fs = nfs_remount,
346 #endif
348 static struct shrinker acl_shrinker = {
349 .shrink = nfs_access_cache_shrinker,
350 .seeks = DEFAULT_SEEKS,
354 * Register the NFS filesystems
356 int __init register_nfs_fs(void)
358 int ret;
360 ret = register_filesystem(&nfs_fs_type);
361 if (ret < 0)
362 goto error_0;
364 ret = nfs_register_sysctl();
365 if (ret < 0)
366 goto error_1;
367 #ifdef CONFIG_NFS_V4
368 ret = register_filesystem(&nfs4_fs_type);
369 if (ret < 0)
370 goto error_2;
371 #endif
372 register_shrinker(&acl_shrinker);
373 return 0;
375 #ifdef CONFIG_NFS_V4
376 error_2:
377 nfs_unregister_sysctl();
378 #endif
379 error_1:
380 unregister_filesystem(&nfs_fs_type);
381 error_0:
382 return ret;
386 * Unregister the NFS filesystems
388 void __exit unregister_nfs_fs(void)
390 unregister_shrinker(&acl_shrinker);
391 #ifdef CONFIG_NFS_V4
392 unregister_filesystem(&nfs4_fs_type);
393 #endif
394 nfs_unregister_sysctl();
395 unregister_filesystem(&nfs_fs_type);
398 void nfs_sb_active(struct super_block *sb)
400 struct nfs_server *server = NFS_SB(sb);
402 if (atomic_inc_return(&server->active) == 1)
403 atomic_inc(&sb->s_active);
406 void nfs_sb_deactive(struct super_block *sb)
408 struct nfs_server *server = NFS_SB(sb);
410 if (atomic_dec_and_test(&server->active))
411 deactivate_super(sb);
415 * Deliver file system statistics to userspace
417 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
419 struct nfs_server *server = NFS_SB(dentry->d_sb);
420 unsigned char blockbits;
421 unsigned long blockres;
422 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
423 struct nfs_fattr fattr;
424 struct nfs_fsstat res = {
425 .fattr = &fattr,
427 int error;
429 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
430 if (error < 0)
431 goto out_err;
432 buf->f_type = NFS_SUPER_MAGIC;
435 * Current versions of glibc do not correctly handle the
436 * case where f_frsize != f_bsize. Eventually we want to
437 * report the value of wtmult in this field.
439 buf->f_frsize = dentry->d_sb->s_blocksize;
442 * On most *nix systems, f_blocks, f_bfree, and f_bavail
443 * are reported in units of f_frsize. Linux hasn't had
444 * an f_frsize field in its statfs struct until recently,
445 * thus historically Linux's sys_statfs reports these
446 * fields in units of f_bsize.
448 buf->f_bsize = dentry->d_sb->s_blocksize;
449 blockbits = dentry->d_sb->s_blocksize_bits;
450 blockres = (1 << blockbits) - 1;
451 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
452 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
453 buf->f_bavail = (res.abytes + blockres) >> blockbits;
455 buf->f_files = res.tfiles;
456 buf->f_ffree = res.afiles;
458 buf->f_namelen = server->namelen;
460 return 0;
462 out_err:
463 dprintk("%s: statfs error = %d\n", __func__, -error);
464 return error;
468 * Map the security flavour number to a name
470 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
472 static const struct {
473 rpc_authflavor_t flavour;
474 const char *str;
475 } sec_flavours[] = {
476 { RPC_AUTH_NULL, "null" },
477 { RPC_AUTH_UNIX, "sys" },
478 { RPC_AUTH_GSS_KRB5, "krb5" },
479 { RPC_AUTH_GSS_KRB5I, "krb5i" },
480 { RPC_AUTH_GSS_KRB5P, "krb5p" },
481 { RPC_AUTH_GSS_LKEY, "lkey" },
482 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
483 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
484 { RPC_AUTH_GSS_SPKM, "spkm" },
485 { RPC_AUTH_GSS_SPKMI, "spkmi" },
486 { RPC_AUTH_GSS_SPKMP, "spkmp" },
487 { UINT_MAX, "unknown" }
489 int i;
491 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
492 if (sec_flavours[i].flavour == flavour)
493 break;
495 return sec_flavours[i].str;
498 static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
499 int showdefaults)
501 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
503 switch (sap->sa_family) {
504 case AF_INET: {
505 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
506 seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
507 break;
509 case AF_INET6: {
510 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
511 seq_printf(m, ",mountaddr=%pI6", &sin6->sin6_addr);
512 break;
514 default:
515 if (showdefaults)
516 seq_printf(m, ",mountaddr=unspecified");
519 if (nfss->mountd_version || showdefaults)
520 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
521 if (nfss->mountd_port || showdefaults)
522 seq_printf(m, ",mountport=%u", nfss->mountd_port);
524 switch (nfss->mountd_protocol) {
525 case IPPROTO_UDP:
526 seq_printf(m, ",mountproto=udp");
527 break;
528 case IPPROTO_TCP:
529 seq_printf(m, ",mountproto=tcp");
530 break;
531 default:
532 if (showdefaults)
533 seq_printf(m, ",mountproto=auto");
538 * Describe the mount options in force on this server representation
540 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
541 int showdefaults)
543 static const struct proc_nfs_info {
544 int flag;
545 const char *str;
546 const char *nostr;
547 } nfs_info[] = {
548 { NFS_MOUNT_SOFT, ",soft", ",hard" },
549 { NFS_MOUNT_POSIX, ",posix", "" },
550 { NFS_MOUNT_NOCTO, ",nocto", "" },
551 { NFS_MOUNT_NOAC, ",noac", "" },
552 { NFS_MOUNT_NONLM, ",nolock", "" },
553 { NFS_MOUNT_NOACL, ",noacl", "" },
554 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
555 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
556 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
557 { 0, NULL, NULL }
559 const struct proc_nfs_info *nfs_infop;
560 struct nfs_client *clp = nfss->nfs_client;
561 u32 version = clp->rpc_ops->version;
563 seq_printf(m, ",vers=%u", version);
564 seq_printf(m, ",rsize=%u", nfss->rsize);
565 seq_printf(m, ",wsize=%u", nfss->wsize);
566 if (nfss->bsize != 0)
567 seq_printf(m, ",bsize=%u", nfss->bsize);
568 seq_printf(m, ",namlen=%u", nfss->namelen);
569 if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
570 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
571 if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
572 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
573 if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
574 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
575 if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
576 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
577 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
578 if (nfss->flags & nfs_infop->flag)
579 seq_puts(m, nfs_infop->str);
580 else
581 seq_puts(m, nfs_infop->nostr);
583 seq_printf(m, ",proto=%s",
584 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
585 if (version == 4) {
586 if (nfss->port != NFS_PORT)
587 seq_printf(m, ",port=%u", nfss->port);
588 } else
589 if (nfss->port)
590 seq_printf(m, ",port=%u", nfss->port);
592 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
593 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
594 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
596 if (version != 4)
597 nfs_show_mountd_options(m, nfss, showdefaults);
599 #ifdef CONFIG_NFS_V4
600 if (clp->rpc_ops->version == 4)
601 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
602 #endif
603 if (nfss->options & NFS_OPTION_FSCACHE)
604 seq_printf(m, ",fsc");
608 * Describe the mount options on this VFS mountpoint
610 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
612 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
614 nfs_show_mount_options(m, nfss, 0);
616 seq_printf(m, ",addr=%s",
617 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
618 RPC_DISPLAY_ADDR));
620 return 0;
624 * Present statistical information for this VFS mountpoint
626 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
628 int i, cpu;
629 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
630 struct rpc_auth *auth = nfss->client->cl_auth;
631 struct nfs_iostats totals = { };
633 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
636 * Display all mount option settings
638 seq_printf(m, "\n\topts:\t");
639 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
640 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
641 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
642 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
643 nfs_show_mount_options(m, nfss, 1);
645 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
647 seq_printf(m, "\n\tcaps:\t");
648 seq_printf(m, "caps=0x%x", nfss->caps);
649 seq_printf(m, ",wtmult=%u", nfss->wtmult);
650 seq_printf(m, ",dtsize=%u", nfss->dtsize);
651 seq_printf(m, ",bsize=%u", nfss->bsize);
652 seq_printf(m, ",namlen=%u", nfss->namelen);
654 #ifdef CONFIG_NFS_V4
655 if (nfss->nfs_client->rpc_ops->version == 4) {
656 seq_printf(m, "\n\tnfsv4:\t");
657 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
658 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
659 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
661 #endif
664 * Display security flavor in effect for this mount
666 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
667 if (auth->au_flavor)
668 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
671 * Display superblock I/O counters
673 for_each_possible_cpu(cpu) {
674 struct nfs_iostats *stats;
676 preempt_disable();
677 stats = per_cpu_ptr(nfss->io_stats, cpu);
679 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
680 totals.events[i] += stats->events[i];
681 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
682 totals.bytes[i] += stats->bytes[i];
683 #ifdef CONFIG_NFS_FSCACHE
684 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
685 totals.fscache[i] += stats->fscache[i];
686 #endif
688 preempt_enable();
691 seq_printf(m, "\n\tevents:\t");
692 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
693 seq_printf(m, "%lu ", totals.events[i]);
694 seq_printf(m, "\n\tbytes:\t");
695 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
696 seq_printf(m, "%Lu ", totals.bytes[i]);
697 #ifdef CONFIG_NFS_FSCACHE
698 if (nfss->options & NFS_OPTION_FSCACHE) {
699 seq_printf(m, "\n\tfsc:\t");
700 for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
701 seq_printf(m, "%Lu ", totals.bytes[i]);
703 #endif
704 seq_printf(m, "\n");
706 rpc_print_iostats(m, nfss->client);
708 return 0;
712 * Begin unmount by attempting to remove all automounted mountpoints we added
713 * in response to xdev traversals and referrals
715 static void nfs_umount_begin(struct super_block *sb)
717 struct nfs_server *server;
718 struct rpc_clnt *rpc;
720 lock_kernel();
722 server = NFS_SB(sb);
723 /* -EIO all pending I/O */
724 rpc = server->client_acl;
725 if (!IS_ERR(rpc))
726 rpc_killall_tasks(rpc);
727 rpc = server->client;
728 if (!IS_ERR(rpc))
729 rpc_killall_tasks(rpc);
731 unlock_kernel();
734 static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int version)
736 struct nfs_parsed_mount_data *data;
738 data = kzalloc(sizeof(*data), GFP_KERNEL);
739 if (data) {
740 data->acregmin = NFS_DEF_ACREGMIN;
741 data->acregmax = NFS_DEF_ACREGMAX;
742 data->acdirmin = NFS_DEF_ACDIRMIN;
743 data->acdirmax = NFS_DEF_ACDIRMAX;
744 data->mount_server.port = NFS_UNSPEC_PORT;
745 data->nfs_server.port = NFS_UNSPEC_PORT;
746 data->nfs_server.protocol = XPRT_TRANSPORT_TCP;
747 data->auth_flavors[0] = RPC_AUTH_UNIX;
748 data->auth_flavor_len = 1;
749 data->version = version;
750 data->minorversion = 0;
752 return data;
756 * Sanity-check a server address provided by the mount command.
758 * Address family must be initialized, and address must not be
759 * the ANY address for that family.
761 static int nfs_verify_server_address(struct sockaddr *addr)
763 switch (addr->sa_family) {
764 case AF_INET: {
765 struct sockaddr_in *sa = (struct sockaddr_in *)addr;
766 return sa->sin_addr.s_addr != htonl(INADDR_ANY);
768 case AF_INET6: {
769 struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr;
770 return !ipv6_addr_any(sa);
774 dfprintk(MOUNT, "NFS: Invalid IP address specified\n");
775 return 0;
779 * Select between a default port value and a user-specified port value.
780 * If a zero value is set, then autobind will be used.
782 static void nfs_set_port(struct sockaddr *sap, int *port,
783 const unsigned short default_port)
785 if (*port == NFS_UNSPEC_PORT)
786 *port = default_port;
788 rpc_set_port(sap, *port);
792 * Sanity check the NFS transport protocol.
795 static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt)
797 switch (mnt->nfs_server.protocol) {
798 case XPRT_TRANSPORT_UDP:
799 case XPRT_TRANSPORT_TCP:
800 case XPRT_TRANSPORT_RDMA:
801 break;
802 default:
803 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
808 * For text based NFSv2/v3 mounts, the mount protocol transport default
809 * settings should depend upon the specified NFS transport.
811 static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt)
813 nfs_validate_transport_protocol(mnt);
815 if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP ||
816 mnt->mount_server.protocol == XPRT_TRANSPORT_TCP)
817 return;
818 switch (mnt->nfs_server.protocol) {
819 case XPRT_TRANSPORT_UDP:
820 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
821 break;
822 case XPRT_TRANSPORT_TCP:
823 case XPRT_TRANSPORT_RDMA:
824 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
829 * Parse the value of the 'sec=' option.
831 static int nfs_parse_security_flavors(char *value,
832 struct nfs_parsed_mount_data *mnt)
834 substring_t args[MAX_OPT_ARGS];
836 dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value);
838 switch (match_token(value, nfs_secflavor_tokens, args)) {
839 case Opt_sec_none:
840 mnt->auth_flavors[0] = RPC_AUTH_NULL;
841 break;
842 case Opt_sec_sys:
843 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
844 break;
845 case Opt_sec_krb5:
846 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
847 break;
848 case Opt_sec_krb5i:
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
850 break;
851 case Opt_sec_krb5p:
852 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
853 break;
854 case Opt_sec_lkey:
855 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
856 break;
857 case Opt_sec_lkeyi:
858 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
859 break;
860 case Opt_sec_lkeyp:
861 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
862 break;
863 case Opt_sec_spkm:
864 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
865 break;
866 case Opt_sec_spkmi:
867 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
868 break;
869 case Opt_sec_spkmp:
870 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
871 break;
872 default:
873 return 0;
876 mnt->auth_flavor_len = 1;
877 return 1;
881 * Error-check and convert a string of mount options from user space into
882 * a data structure. The whole mount string is processed; bad options are
883 * skipped as they are encountered. If there were no errors, return 1;
884 * otherwise return 0 (zero).
886 static int nfs_parse_mount_options(char *raw,
887 struct nfs_parsed_mount_data *mnt)
889 char *p, *string, *secdata;
890 int rc, sloppy = 0, invalid_option = 0;
892 if (!raw) {
893 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
894 return 1;
896 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
898 secdata = alloc_secdata();
899 if (!secdata)
900 goto out_nomem;
902 rc = security_sb_copy_data(raw, secdata);
903 if (rc)
904 goto out_security_failure;
906 rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts);
907 if (rc)
908 goto out_security_failure;
910 free_secdata(secdata);
912 while ((p = strsep(&raw, ",")) != NULL) {
913 substring_t args[MAX_OPT_ARGS];
914 unsigned long option;
915 int token;
917 if (!*p)
918 continue;
920 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
922 token = match_token(p, nfs_mount_option_tokens, args);
923 switch (token) {
926 * boolean options: foo/nofoo
928 case Opt_soft:
929 mnt->flags |= NFS_MOUNT_SOFT;
930 break;
931 case Opt_hard:
932 mnt->flags &= ~NFS_MOUNT_SOFT;
933 break;
934 case Opt_posix:
935 mnt->flags |= NFS_MOUNT_POSIX;
936 break;
937 case Opt_noposix:
938 mnt->flags &= ~NFS_MOUNT_POSIX;
939 break;
940 case Opt_cto:
941 mnt->flags &= ~NFS_MOUNT_NOCTO;
942 break;
943 case Opt_nocto:
944 mnt->flags |= NFS_MOUNT_NOCTO;
945 break;
946 case Opt_ac:
947 mnt->flags &= ~NFS_MOUNT_NOAC;
948 break;
949 case Opt_noac:
950 mnt->flags |= NFS_MOUNT_NOAC;
951 break;
952 case Opt_lock:
953 mnt->flags &= ~NFS_MOUNT_NONLM;
954 break;
955 case Opt_nolock:
956 mnt->flags |= NFS_MOUNT_NONLM;
957 break;
958 case Opt_v2:
959 mnt->flags &= ~NFS_MOUNT_VER3;
960 mnt->version = 2;
961 break;
962 case Opt_v3:
963 mnt->flags |= NFS_MOUNT_VER3;
964 mnt->version = 3;
965 break;
966 #ifdef CONFIG_NFS_V4
967 case Opt_v4:
968 mnt->flags &= ~NFS_MOUNT_VER3;
969 mnt->version = 4;
970 break;
971 #endif
972 case Opt_udp:
973 mnt->flags &= ~NFS_MOUNT_TCP;
974 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
975 break;
976 case Opt_tcp:
977 mnt->flags |= NFS_MOUNT_TCP;
978 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
979 break;
980 case Opt_rdma:
981 mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */
982 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
983 xprt_load_transport(p);
984 break;
985 case Opt_acl:
986 mnt->flags &= ~NFS_MOUNT_NOACL;
987 break;
988 case Opt_noacl:
989 mnt->flags |= NFS_MOUNT_NOACL;
990 break;
991 case Opt_rdirplus:
992 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
993 break;
994 case Opt_nordirplus:
995 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
996 break;
997 case Opt_sharecache:
998 mnt->flags &= ~NFS_MOUNT_UNSHARED;
999 break;
1000 case Opt_nosharecache:
1001 mnt->flags |= NFS_MOUNT_UNSHARED;
1002 break;
1003 case Opt_resvport:
1004 mnt->flags &= ~NFS_MOUNT_NORESVPORT;
1005 break;
1006 case Opt_noresvport:
1007 mnt->flags |= NFS_MOUNT_NORESVPORT;
1008 break;
1009 case Opt_fscache:
1010 mnt->options |= NFS_OPTION_FSCACHE;
1011 kfree(mnt->fscache_uniq);
1012 mnt->fscache_uniq = NULL;
1013 break;
1014 case Opt_nofscache:
1015 mnt->options &= ~NFS_OPTION_FSCACHE;
1016 kfree(mnt->fscache_uniq);
1017 mnt->fscache_uniq = NULL;
1018 break;
1019 case Opt_fscache_uniq:
1020 string = match_strdup(args);
1021 if (!string)
1022 goto out_nomem;
1023 kfree(mnt->fscache_uniq);
1024 mnt->fscache_uniq = string;
1025 mnt->options |= NFS_OPTION_FSCACHE;
1026 break;
1029 * options that take numeric values
1031 case Opt_port:
1032 string = match_strdup(args);
1033 if (string == NULL)
1034 goto out_nomem;
1035 rc = strict_strtoul(string, 10, &option);
1036 kfree(string);
1037 if (rc != 0 || option > USHORT_MAX)
1038 goto out_invalid_value;
1039 mnt->nfs_server.port = option;
1040 break;
1041 case Opt_rsize:
1042 string = match_strdup(args);
1043 if (string == NULL)
1044 goto out_nomem;
1045 rc = strict_strtoul(string, 10, &option);
1046 kfree(string);
1047 if (rc != 0)
1048 goto out_invalid_value;
1049 mnt->rsize = option;
1050 break;
1051 case Opt_wsize:
1052 string = match_strdup(args);
1053 if (string == NULL)
1054 goto out_nomem;
1055 rc = strict_strtoul(string, 10, &option);
1056 kfree(string);
1057 if (rc != 0)
1058 goto out_invalid_value;
1059 mnt->wsize = option;
1060 break;
1061 case Opt_bsize:
1062 string = match_strdup(args);
1063 if (string == NULL)
1064 goto out_nomem;
1065 rc = strict_strtoul(string, 10, &option);
1066 kfree(string);
1067 if (rc != 0)
1068 goto out_invalid_value;
1069 mnt->bsize = option;
1070 break;
1071 case Opt_timeo:
1072 string = match_strdup(args);
1073 if (string == NULL)
1074 goto out_nomem;
1075 rc = strict_strtoul(string, 10, &option);
1076 kfree(string);
1077 if (rc != 0 || option == 0)
1078 goto out_invalid_value;
1079 mnt->timeo = option;
1080 break;
1081 case Opt_retrans:
1082 string = match_strdup(args);
1083 if (string == NULL)
1084 goto out_nomem;
1085 rc = strict_strtoul(string, 10, &option);
1086 kfree(string);
1087 if (rc != 0 || option == 0)
1088 goto out_invalid_value;
1089 mnt->retrans = option;
1090 break;
1091 case Opt_acregmin:
1092 string = match_strdup(args);
1093 if (string == NULL)
1094 goto out_nomem;
1095 rc = strict_strtoul(string, 10, &option);
1096 kfree(string);
1097 if (rc != 0)
1098 goto out_invalid_value;
1099 mnt->acregmin = option;
1100 break;
1101 case Opt_acregmax:
1102 string = match_strdup(args);
1103 if (string == NULL)
1104 goto out_nomem;
1105 rc = strict_strtoul(string, 10, &option);
1106 kfree(string);
1107 if (rc != 0)
1108 goto out_invalid_value;
1109 mnt->acregmax = option;
1110 break;
1111 case Opt_acdirmin:
1112 string = match_strdup(args);
1113 if (string == NULL)
1114 goto out_nomem;
1115 rc = strict_strtoul(string, 10, &option);
1116 kfree(string);
1117 if (rc != 0)
1118 goto out_invalid_value;
1119 mnt->acdirmin = option;
1120 break;
1121 case Opt_acdirmax:
1122 string = match_strdup(args);
1123 if (string == NULL)
1124 goto out_nomem;
1125 rc = strict_strtoul(string, 10, &option);
1126 kfree(string);
1127 if (rc != 0)
1128 goto out_invalid_value;
1129 mnt->acdirmax = option;
1130 break;
1131 case Opt_actimeo:
1132 string = match_strdup(args);
1133 if (string == NULL)
1134 goto out_nomem;
1135 rc = strict_strtoul(string, 10, &option);
1136 kfree(string);
1137 if (rc != 0)
1138 goto out_invalid_value;
1139 mnt->acregmin = mnt->acregmax =
1140 mnt->acdirmin = mnt->acdirmax = option;
1141 break;
1142 case Opt_namelen:
1143 string = match_strdup(args);
1144 if (string == NULL)
1145 goto out_nomem;
1146 rc = strict_strtoul(string, 10, &option);
1147 kfree(string);
1148 if (rc != 0)
1149 goto out_invalid_value;
1150 mnt->namlen = option;
1151 break;
1152 case Opt_mountport:
1153 string = match_strdup(args);
1154 if (string == NULL)
1155 goto out_nomem;
1156 rc = strict_strtoul(string, 10, &option);
1157 kfree(string);
1158 if (rc != 0 || option > USHORT_MAX)
1159 goto out_invalid_value;
1160 mnt->mount_server.port = option;
1161 break;
1162 case Opt_mountvers:
1163 string = match_strdup(args);
1164 if (string == NULL)
1165 goto out_nomem;
1166 rc = strict_strtoul(string, 10, &option);
1167 kfree(string);
1168 if (rc != 0 ||
1169 option < NFS_MNT_VERSION ||
1170 option > NFS_MNT3_VERSION)
1171 goto out_invalid_value;
1172 mnt->mount_server.version = option;
1173 break;
1174 case Opt_nfsvers:
1175 string = match_strdup(args);
1176 if (string == NULL)
1177 goto out_nomem;
1178 rc = strict_strtoul(string, 10, &option);
1179 kfree(string);
1180 if (rc != 0)
1181 goto out_invalid_value;
1182 switch (option) {
1183 case NFS2_VERSION:
1184 mnt->flags &= ~NFS_MOUNT_VER3;
1185 mnt->version = 2;
1186 break;
1187 case NFS3_VERSION:
1188 mnt->flags |= NFS_MOUNT_VER3;
1189 mnt->version = 3;
1190 break;
1191 #ifdef CONFIG_NFS_V4
1192 case NFS4_VERSION:
1193 mnt->flags &= ~NFS_MOUNT_VER3;
1194 mnt->version = 4;
1195 break;
1196 #endif
1197 default:
1198 goto out_invalid_value;
1200 break;
1201 case Opt_minorversion:
1202 string = match_strdup(args);
1203 if (string == NULL)
1204 goto out_nomem;
1205 rc = strict_strtoul(string, 10, &option);
1206 kfree(string);
1207 if (rc != 0)
1208 goto out_invalid_value;
1209 if (option > NFS4_MAX_MINOR_VERSION)
1210 goto out_invalid_value;
1211 mnt->minorversion = option;
1212 break;
1215 * options that take text values
1217 case Opt_sec:
1218 string = match_strdup(args);
1219 if (string == NULL)
1220 goto out_nomem;
1221 rc = nfs_parse_security_flavors(string, mnt);
1222 kfree(string);
1223 if (!rc) {
1224 dfprintk(MOUNT, "NFS: unrecognized "
1225 "security flavor\n");
1226 return 0;
1228 break;
1229 case Opt_proto:
1230 string = match_strdup(args);
1231 if (string == NULL)
1232 goto out_nomem;
1233 token = match_token(string,
1234 nfs_xprt_protocol_tokens, args);
1236 switch (token) {
1237 case Opt_xprt_udp:
1238 mnt->flags &= ~NFS_MOUNT_TCP;
1239 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1240 kfree(string);
1241 break;
1242 case Opt_xprt_tcp:
1243 mnt->flags |= NFS_MOUNT_TCP;
1244 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1245 kfree(string);
1246 break;
1247 case Opt_xprt_rdma:
1248 /* vector side protocols to TCP */
1249 mnt->flags |= NFS_MOUNT_TCP;
1250 mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA;
1251 xprt_load_transport(string);
1252 kfree(string);
1253 break;
1254 default:
1255 dfprintk(MOUNT, "NFS: unrecognized "
1256 "transport protocol\n");
1257 kfree(string);
1258 return 0;
1260 break;
1261 case Opt_mountproto:
1262 string = match_strdup(args);
1263 if (string == NULL)
1264 goto out_nomem;
1265 token = match_token(string,
1266 nfs_xprt_protocol_tokens, args);
1267 kfree(string);
1269 switch (token) {
1270 case Opt_xprt_udp:
1271 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
1272 break;
1273 case Opt_xprt_tcp:
1274 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
1275 break;
1276 case Opt_xprt_rdma: /* not used for side protocols */
1277 default:
1278 dfprintk(MOUNT, "NFS: unrecognized "
1279 "transport protocol\n");
1280 return 0;
1282 break;
1283 case Opt_addr:
1284 string = match_strdup(args);
1285 if (string == NULL)
1286 goto out_nomem;
1287 mnt->nfs_server.addrlen =
1288 rpc_pton(string, strlen(string),
1289 (struct sockaddr *)
1290 &mnt->nfs_server.address,
1291 sizeof(mnt->nfs_server.address));
1292 kfree(string);
1293 if (mnt->nfs_server.addrlen == 0)
1294 goto out_invalid_address;
1295 break;
1296 case Opt_clientaddr:
1297 string = match_strdup(args);
1298 if (string == NULL)
1299 goto out_nomem;
1300 kfree(mnt->client_address);
1301 mnt->client_address = string;
1302 break;
1303 case Opt_mounthost:
1304 string = match_strdup(args);
1305 if (string == NULL)
1306 goto out_nomem;
1307 kfree(mnt->mount_server.hostname);
1308 mnt->mount_server.hostname = string;
1309 break;
1310 case Opt_mountaddr:
1311 string = match_strdup(args);
1312 if (string == NULL)
1313 goto out_nomem;
1314 mnt->mount_server.addrlen =
1315 rpc_pton(string, strlen(string),
1316 (struct sockaddr *)
1317 &mnt->mount_server.address,
1318 sizeof(mnt->mount_server.address));
1319 kfree(string);
1320 if (mnt->mount_server.addrlen == 0)
1321 goto out_invalid_address;
1322 break;
1323 case Opt_lookupcache:
1324 string = match_strdup(args);
1325 if (string == NULL)
1326 goto out_nomem;
1327 token = match_token(string,
1328 nfs_lookupcache_tokens, args);
1329 kfree(string);
1330 switch (token) {
1331 case Opt_lookupcache_all:
1332 mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE);
1333 break;
1334 case Opt_lookupcache_positive:
1335 mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE;
1336 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG;
1337 break;
1338 case Opt_lookupcache_none:
1339 mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE;
1340 break;
1341 default:
1342 dfprintk(MOUNT, "NFS: invalid "
1343 "lookupcache argument\n");
1344 return 0;
1346 break;
1349 * Special options
1351 case Opt_sloppy:
1352 sloppy = 1;
1353 dfprintk(MOUNT, "NFS: relaxing parsing rules\n");
1354 break;
1355 case Opt_userspace:
1356 case Opt_deprecated:
1357 dfprintk(MOUNT, "NFS: ignoring mount option "
1358 "'%s'\n", p);
1359 break;
1361 default:
1362 invalid_option = 1;
1363 dfprintk(MOUNT, "NFS: unrecognized mount option "
1364 "'%s'\n", p);
1368 if (!sloppy && invalid_option)
1369 return 0;
1371 return 1;
1373 out_invalid_address:
1374 printk(KERN_INFO "NFS: bad IP address specified: %s\n", p);
1375 return 0;
1376 out_invalid_value:
1377 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1378 return 0;
1379 out_nomem:
1380 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1381 return 0;
1382 out_security_failure:
1383 free_secdata(secdata);
1384 printk(KERN_INFO "NFS: security options invalid: %d\n", rc);
1385 return 0;
1389 * Match the requested auth flavors with the list returned by
1390 * the server. Returns zero and sets the mount's authentication
1391 * flavor on success; returns -EACCES if server does not support
1392 * the requested flavor.
1394 static int nfs_walk_authlist(struct nfs_parsed_mount_data *args,
1395 struct nfs_mount_request *request)
1397 unsigned int i, j, server_authlist_len = *(request->auth_flav_len);
1400 * Certain releases of Linux's mountd return an empty
1401 * flavor list. To prevent behavioral regression with
1402 * these servers (ie. rejecting mounts that used to
1403 * succeed), revert to pre-2.6.32 behavior (no checking)
1404 * if the returned flavor list is empty.
1406 if (server_authlist_len == 0)
1407 return 0;
1410 * We avoid sophisticated negotiating here, as there are
1411 * plenty of cases where we can get it wrong, providing
1412 * either too little or too much security.
1414 * RFC 2623, section 2.7 suggests we SHOULD prefer the
1415 * flavor listed first. However, some servers list
1416 * AUTH_NULL first. Our caller plants AUTH_SYS, the
1417 * preferred default, in args->auth_flavors[0] if user
1418 * didn't specify sec= mount option.
1420 for (i = 0; i < args->auth_flavor_len; i++)
1421 for (j = 0; j < server_authlist_len; j++)
1422 if (args->auth_flavors[i] == request->auth_flavs[j]) {
1423 dfprintk(MOUNT, "NFS: using auth flavor %d\n",
1424 request->auth_flavs[j]);
1425 args->auth_flavors[0] = request->auth_flavs[j];
1426 return 0;
1429 dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n");
1430 nfs_umount(request);
1431 return -EACCES;
1435 * Use the remote server's MOUNT service to request the NFS file handle
1436 * corresponding to the provided path.
1438 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1439 struct nfs_fh *root_fh)
1441 rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS];
1442 unsigned int server_authlist_len = ARRAY_SIZE(server_authlist);
1443 struct nfs_mount_request request = {
1444 .sap = (struct sockaddr *)
1445 &args->mount_server.address,
1446 .dirpath = args->nfs_server.export_path,
1447 .protocol = args->mount_server.protocol,
1448 .fh = root_fh,
1449 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1450 .auth_flav_len = &server_authlist_len,
1451 .auth_flavs = server_authlist,
1453 int status;
1455 if (args->mount_server.version == 0) {
1456 switch (args->version) {
1457 default:
1458 args->mount_server.version = NFS_MNT3_VERSION;
1459 break;
1460 case 2:
1461 args->mount_server.version = NFS_MNT_VERSION;
1464 request.version = args->mount_server.version;
1466 if (args->mount_server.hostname)
1467 request.hostname = args->mount_server.hostname;
1468 else
1469 request.hostname = args->nfs_server.hostname;
1472 * Construct the mount server's address.
1474 if (args->mount_server.address.ss_family == AF_UNSPEC) {
1475 memcpy(request.sap, &args->nfs_server.address,
1476 args->nfs_server.addrlen);
1477 args->mount_server.addrlen = args->nfs_server.addrlen;
1479 request.salen = args->mount_server.addrlen;
1480 nfs_set_port(request.sap, &args->mount_server.port, 0);
1483 * Now ask the mount server to map our export path
1484 * to a file handle.
1486 status = nfs_mount(&request);
1487 if (status != 0) {
1488 dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
1489 request.hostname, status);
1490 return status;
1494 * MNTv1 (NFSv2) does not support auth flavor negotiation.
1496 if (args->mount_server.version != NFS_MNT3_VERSION)
1497 return 0;
1498 return nfs_walk_authlist(args, &request);
1501 static int nfs_parse_simple_hostname(const char *dev_name,
1502 char **hostname, size_t maxnamlen,
1503 char **export_path, size_t maxpathlen)
1505 size_t len;
1506 char *colon, *comma;
1508 colon = strchr(dev_name, ':');
1509 if (colon == NULL)
1510 goto out_bad_devname;
1512 len = colon - dev_name;
1513 if (len > maxnamlen)
1514 goto out_hostname;
1516 /* N.B. caller will free nfs_server.hostname in all cases */
1517 *hostname = kstrndup(dev_name, len, GFP_KERNEL);
1518 if (!*hostname)
1519 goto out_nomem;
1521 /* kill possible hostname list: not supported */
1522 comma = strchr(*hostname, ',');
1523 if (comma != NULL) {
1524 if (comma == *hostname)
1525 goto out_bad_devname;
1526 *comma = '\0';
1529 colon++;
1530 len = strlen(colon);
1531 if (len > maxpathlen)
1532 goto out_path;
1533 *export_path = kstrndup(colon, len, GFP_KERNEL);
1534 if (!*export_path)
1535 goto out_nomem;
1537 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path);
1538 return 0;
1540 out_bad_devname:
1541 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1542 return -EINVAL;
1544 out_nomem:
1545 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1546 return -ENOMEM;
1548 out_hostname:
1549 dfprintk(MOUNT, "NFS: server hostname too long\n");
1550 return -ENAMETOOLONG;
1552 out_path:
1553 dfprintk(MOUNT, "NFS: export pathname too long\n");
1554 return -ENAMETOOLONG;
1558 * Hostname has square brackets around it because it contains one or
1559 * more colons. We look for the first closing square bracket, and a
1560 * colon must follow it.
1562 static int nfs_parse_protected_hostname(const char *dev_name,
1563 char **hostname, size_t maxnamlen,
1564 char **export_path, size_t maxpathlen)
1566 size_t len;
1567 char *start, *end;
1569 start = (char *)(dev_name + 1);
1571 end = strchr(start, ']');
1572 if (end == NULL)
1573 goto out_bad_devname;
1574 if (*(end + 1) != ':')
1575 goto out_bad_devname;
1577 len = end - start;
1578 if (len > maxnamlen)
1579 goto out_hostname;
1581 /* N.B. caller will free nfs_server.hostname in all cases */
1582 *hostname = kstrndup(start, len, GFP_KERNEL);
1583 if (*hostname == NULL)
1584 goto out_nomem;
1586 end += 2;
1587 len = strlen(end);
1588 if (len > maxpathlen)
1589 goto out_path;
1590 *export_path = kstrndup(end, len, GFP_KERNEL);
1591 if (!*export_path)
1592 goto out_nomem;
1594 return 0;
1596 out_bad_devname:
1597 dfprintk(MOUNT, "NFS: device name not in host:path format\n");
1598 return -EINVAL;
1600 out_nomem:
1601 dfprintk(MOUNT, "NFS: not enough memory to parse device name\n");
1602 return -ENOMEM;
1604 out_hostname:
1605 dfprintk(MOUNT, "NFS: server hostname too long\n");
1606 return -ENAMETOOLONG;
1608 out_path:
1609 dfprintk(MOUNT, "NFS: export pathname too long\n");
1610 return -ENAMETOOLONG;
1614 * Split "dev_name" into "hostname:export_path".
1616 * The leftmost colon demarks the split between the server's hostname
1617 * and the export path. If the hostname starts with a left square
1618 * bracket, then it may contain colons.
1620 * Note: caller frees hostname and export path, even on error.
1622 static int nfs_parse_devname(const char *dev_name,
1623 char **hostname, size_t maxnamlen,
1624 char **export_path, size_t maxpathlen)
1626 if (*dev_name == '[')
1627 return nfs_parse_protected_hostname(dev_name,
1628 hostname, maxnamlen,
1629 export_path, maxpathlen);
1631 return nfs_parse_simple_hostname(dev_name,
1632 hostname, maxnamlen,
1633 export_path, maxpathlen);
1637 * Validate the NFS2/NFS3 mount data
1638 * - fills in the mount root filehandle
1640 * For option strings, user space handles the following behaviors:
1642 * + DNS: mapping server host name to IP address ("addr=" option)
1644 * + failure mode: how to behave if a mount request can't be handled
1645 * immediately ("fg/bg" option)
1647 * + retry: how often to retry a mount request ("retry=" option)
1649 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1650 * mountproto=tcp after mountproto=udp, and so on
1652 static int nfs_validate_mount_data(void *options,
1653 struct nfs_parsed_mount_data *args,
1654 struct nfs_fh *mntfh,
1655 const char *dev_name)
1657 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1658 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
1660 if (data == NULL)
1661 goto out_no_data;
1663 switch (data->version) {
1664 case 1:
1665 data->namlen = 0;
1666 case 2:
1667 data->bsize = 0;
1668 case 3:
1669 if (data->flags & NFS_MOUNT_VER3)
1670 goto out_no_v3;
1671 data->root.size = NFS2_FHSIZE;
1672 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1673 case 4:
1674 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1675 goto out_no_sec;
1676 case 5:
1677 memset(data->context, 0, sizeof(data->context));
1678 case 6:
1679 if (data->flags & NFS_MOUNT_VER3) {
1680 if (data->root.size > NFS3_FHSIZE || data->root.size == 0)
1681 goto out_invalid_fh;
1682 mntfh->size = data->root.size;
1683 args->version = 3;
1684 } else {
1685 mntfh->size = NFS2_FHSIZE;
1686 args->version = 2;
1690 memcpy(mntfh->data, data->root.data, mntfh->size);
1691 if (mntfh->size < sizeof(mntfh->data))
1692 memset(mntfh->data + mntfh->size, 0,
1693 sizeof(mntfh->data) - mntfh->size);
1696 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1697 * can deal with.
1699 args->flags = data->flags & NFS_MOUNT_FLAGMASK;
1700 args->rsize = data->rsize;
1701 args->wsize = data->wsize;
1702 args->timeo = data->timeo;
1703 args->retrans = data->retrans;
1704 args->acregmin = data->acregmin;
1705 args->acregmax = data->acregmax;
1706 args->acdirmin = data->acdirmin;
1707 args->acdirmax = data->acdirmax;
1709 memcpy(sap, &data->addr, sizeof(data->addr));
1710 args->nfs_server.addrlen = sizeof(data->addr);
1711 if (!nfs_verify_server_address(sap))
1712 goto out_no_address;
1714 if (!(data->flags & NFS_MOUNT_TCP))
1715 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1716 /* N.B. caller will free nfs_server.hostname in all cases */
1717 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1718 args->namlen = data->namlen;
1719 args->bsize = data->bsize;
1721 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1722 args->auth_flavors[0] = data->pseudoflavor;
1723 if (!args->nfs_server.hostname)
1724 goto out_nomem;
1727 * The legacy version 6 binary mount data from userspace has a
1728 * field used only to transport selinux information into the
1729 * the kernel. To continue to support that functionality we
1730 * have a touch of selinux knowledge here in the NFS code. The
1731 * userspace code converted context=blah to just blah so we are
1732 * converting back to the full string selinux understands.
1734 if (data->context[0]){
1735 #ifdef CONFIG_SECURITY_SELINUX
1736 int rc;
1737 char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL);
1738 if (!opts_str)
1739 return -ENOMEM;
1740 strcpy(opts_str, "context=");
1741 data->context[NFS_MAX_CONTEXT_LEN] = '\0';
1742 strcat(opts_str, &data->context[0]);
1743 rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts);
1744 kfree(opts_str);
1745 if (rc)
1746 return rc;
1747 #else
1748 return -EINVAL;
1749 #endif
1752 break;
1753 default: {
1754 int status;
1756 if (nfs_parse_mount_options((char *)options, args) == 0)
1757 return -EINVAL;
1759 if (!nfs_verify_server_address(sap))
1760 goto out_no_address;
1762 if (args->version == 4)
1763 #ifdef CONFIG_NFS_V4
1764 return nfs4_validate_text_mount_data(options,
1765 args, dev_name);
1766 #else
1767 goto out_v4_not_compiled;
1768 #endif
1770 nfs_set_port(sap, &args->nfs_server.port, 0);
1772 nfs_set_mount_transport_protocol(args);
1774 status = nfs_parse_devname(dev_name,
1775 &args->nfs_server.hostname,
1776 PAGE_SIZE,
1777 &args->nfs_server.export_path,
1778 NFS_MAXPATHLEN);
1779 if (!status)
1780 status = nfs_try_mount(args, mntfh);
1782 kfree(args->nfs_server.export_path);
1783 args->nfs_server.export_path = NULL;
1785 if (status)
1786 return status;
1788 break;
1792 #ifndef CONFIG_NFS_V3
1793 if (args->version == 3)
1794 goto out_v3_not_compiled;
1795 #endif /* !CONFIG_NFS_V3 */
1797 return 0;
1799 out_no_data:
1800 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1801 return -EINVAL;
1803 out_no_v3:
1804 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1805 data->version);
1806 return -EINVAL;
1808 out_no_sec:
1809 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1810 return -EINVAL;
1812 #ifndef CONFIG_NFS_V3
1813 out_v3_not_compiled:
1814 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1815 return -EPROTONOSUPPORT;
1816 #endif /* !CONFIG_NFS_V3 */
1818 #ifndef CONFIG_NFS_V4
1819 out_v4_not_compiled:
1820 dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n");
1821 return -EPROTONOSUPPORT;
1822 #endif /* !CONFIG_NFS_V4 */
1824 out_nomem:
1825 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1826 return -ENOMEM;
1828 out_no_address:
1829 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1830 return -EINVAL;
1832 out_invalid_fh:
1833 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1834 return -EINVAL;
1837 static int
1838 nfs_compare_remount_data(struct nfs_server *nfss,
1839 struct nfs_parsed_mount_data *data)
1841 if (data->flags != nfss->flags ||
1842 data->rsize != nfss->rsize ||
1843 data->wsize != nfss->wsize ||
1844 data->retrans != nfss->client->cl_timeout->to_retries ||
1845 data->auth_flavors[0] != nfss->client->cl_auth->au_flavor ||
1846 data->acregmin != nfss->acregmin / HZ ||
1847 data->acregmax != nfss->acregmax / HZ ||
1848 data->acdirmin != nfss->acdirmin / HZ ||
1849 data->acdirmax != nfss->acdirmax / HZ ||
1850 data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
1851 data->nfs_server.port != nfss->port ||
1852 data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
1853 !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
1854 (struct sockaddr *)&nfss->nfs_client->cl_addr))
1855 return -EINVAL;
1857 return 0;
1860 static int
1861 nfs_remount(struct super_block *sb, int *flags, char *raw_data)
1863 int error;
1864 struct nfs_server *nfss = sb->s_fs_info;
1865 struct nfs_parsed_mount_data *data;
1866 struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data;
1867 struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data;
1868 u32 nfsvers = nfss->nfs_client->rpc_ops->version;
1871 * Userspace mount programs that send binary options generally send
1872 * them populated with default values. We have no way to know which
1873 * ones were explicitly specified. Fall back to legacy behavior and
1874 * just return success.
1876 if ((nfsvers == 4 && (!options4 || options4->version == 1)) ||
1877 (nfsvers <= 3 && (!options || (options->version >= 1 &&
1878 options->version <= 6))))
1879 return 0;
1881 data = kzalloc(sizeof(*data), GFP_KERNEL);
1882 if (data == NULL)
1883 return -ENOMEM;
1885 lock_kernel();
1886 /* fill out struct with values from existing mount */
1887 data->flags = nfss->flags;
1888 data->rsize = nfss->rsize;
1889 data->wsize = nfss->wsize;
1890 data->retrans = nfss->client->cl_timeout->to_retries;
1891 data->auth_flavors[0] = nfss->client->cl_auth->au_flavor;
1892 data->acregmin = nfss->acregmin / HZ;
1893 data->acregmax = nfss->acregmax / HZ;
1894 data->acdirmin = nfss->acdirmin / HZ;
1895 data->acdirmax = nfss->acdirmax / HZ;
1896 data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ;
1897 data->nfs_server.port = nfss->port;
1898 data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen;
1899 memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr,
1900 data->nfs_server.addrlen);
1902 /* overwrite those values with any that were specified */
1903 error = nfs_parse_mount_options((char *)options, data);
1904 if (error < 0)
1905 goto out;
1907 /* compare new mount options with old ones */
1908 error = nfs_compare_remount_data(nfss, data);
1909 out:
1910 kfree(data);
1911 unlock_kernel();
1912 return error;
1916 * Initialise the common bits of the superblock
1918 static inline void nfs_initialise_sb(struct super_block *sb)
1920 struct nfs_server *server = NFS_SB(sb);
1922 sb->s_magic = NFS_SUPER_MAGIC;
1924 /* We probably want something more informative here */
1925 snprintf(sb->s_id, sizeof(sb->s_id),
1926 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1928 if (sb->s_blocksize == 0)
1929 sb->s_blocksize = nfs_block_bits(server->wsize,
1930 &sb->s_blocksize_bits);
1932 if (server->flags & NFS_MOUNT_NOAC)
1933 sb->s_flags |= MS_SYNCHRONOUS;
1935 sb->s_bdi = &server->backing_dev_info;
1937 nfs_super_set_maxbytes(sb, server->maxfilesize);
1941 * Finish setting up an NFS2/3 superblock
1943 static void nfs_fill_super(struct super_block *sb,
1944 struct nfs_parsed_mount_data *data)
1946 struct nfs_server *server = NFS_SB(sb);
1948 sb->s_blocksize_bits = 0;
1949 sb->s_blocksize = 0;
1950 if (data->bsize)
1951 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1953 if (server->nfs_client->rpc_ops->version == 3) {
1954 /* The VFS shouldn't apply the umask to mode bits. We will do
1955 * so ourselves when necessary.
1957 sb->s_flags |= MS_POSIXACL;
1958 sb->s_time_gran = 1;
1961 sb->s_op = &nfs_sops;
1962 nfs_initialise_sb(sb);
1966 * Finish setting up a cloned NFS2/3 superblock
1968 static void nfs_clone_super(struct super_block *sb,
1969 const struct super_block *old_sb)
1971 struct nfs_server *server = NFS_SB(sb);
1973 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1974 sb->s_blocksize = old_sb->s_blocksize;
1975 sb->s_maxbytes = old_sb->s_maxbytes;
1977 if (server->nfs_client->rpc_ops->version == 3) {
1978 /* The VFS shouldn't apply the umask to mode bits. We will do
1979 * so ourselves when necessary.
1981 sb->s_flags |= MS_POSIXACL;
1982 sb->s_time_gran = 1;
1985 sb->s_op = old_sb->s_op;
1986 nfs_initialise_sb(sb);
1989 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1991 const struct nfs_server *a = s->s_fs_info;
1992 const struct rpc_clnt *clnt_a = a->client;
1993 const struct rpc_clnt *clnt_b = b->client;
1995 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1996 goto Ebusy;
1997 if (a->nfs_client != b->nfs_client)
1998 goto Ebusy;
1999 if (a->flags != b->flags)
2000 goto Ebusy;
2001 if (a->wsize != b->wsize)
2002 goto Ebusy;
2003 if (a->rsize != b->rsize)
2004 goto Ebusy;
2005 if (a->acregmin != b->acregmin)
2006 goto Ebusy;
2007 if (a->acregmax != b->acregmax)
2008 goto Ebusy;
2009 if (a->acdirmin != b->acdirmin)
2010 goto Ebusy;
2011 if (a->acdirmax != b->acdirmax)
2012 goto Ebusy;
2013 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
2014 goto Ebusy;
2015 return 1;
2016 Ebusy:
2017 return 0;
2020 struct nfs_sb_mountdata {
2021 struct nfs_server *server;
2022 int mntflags;
2025 static int nfs_set_super(struct super_block *s, void *data)
2027 struct nfs_sb_mountdata *sb_mntdata = data;
2028 struct nfs_server *server = sb_mntdata->server;
2029 int ret;
2031 s->s_flags = sb_mntdata->mntflags;
2032 s->s_fs_info = server;
2033 ret = set_anon_super(s, server);
2034 if (ret == 0)
2035 server->s_dev = s->s_dev;
2036 return ret;
2039 static int nfs_compare_super_address(struct nfs_server *server1,
2040 struct nfs_server *server2)
2042 struct sockaddr *sap1, *sap2;
2044 sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
2045 sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
2047 if (sap1->sa_family != sap2->sa_family)
2048 return 0;
2050 switch (sap1->sa_family) {
2051 case AF_INET: {
2052 struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
2053 struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
2054 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
2055 return 0;
2056 if (sin1->sin_port != sin2->sin_port)
2057 return 0;
2058 break;
2060 case AF_INET6: {
2061 struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
2062 struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
2063 if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
2064 return 0;
2065 if (sin1->sin6_port != sin2->sin6_port)
2066 return 0;
2067 break;
2069 default:
2070 return 0;
2073 return 1;
2076 static int nfs_compare_super(struct super_block *sb, void *data)
2078 struct nfs_sb_mountdata *sb_mntdata = data;
2079 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
2080 int mntflags = sb_mntdata->mntflags;
2082 if (!nfs_compare_super_address(old, server))
2083 return 0;
2084 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
2085 if (old->flags & NFS_MOUNT_UNSHARED)
2086 return 0;
2087 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
2088 return 0;
2089 return nfs_compare_mount_options(sb, server, mntflags);
2092 static int nfs_bdi_register(struct nfs_server *server)
2094 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
2097 static int nfs_get_sb(struct file_system_type *fs_type,
2098 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2100 struct nfs_server *server = NULL;
2101 struct super_block *s;
2102 struct nfs_parsed_mount_data *data;
2103 struct nfs_fh *mntfh;
2104 struct dentry *mntroot;
2105 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2106 struct nfs_sb_mountdata sb_mntdata = {
2107 .mntflags = flags,
2109 int error = -ENOMEM;
2111 data = nfs_alloc_parsed_mount_data(3);
2112 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2113 if (data == NULL || mntfh == NULL)
2114 goto out_free_fh;
2116 security_init_mnt_opts(&data->lsm_opts);
2118 /* Validate the mount data */
2119 error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name);
2120 if (error < 0)
2121 goto out;
2123 #ifdef CONFIG_NFS_V4
2124 if (data->version == 4) {
2125 error = nfs4_try_mount(flags, dev_name, data, mnt);
2126 kfree(data->client_address);
2127 goto out;
2129 #endif /* CONFIG_NFS_V4 */
2131 /* Get a volume representation */
2132 server = nfs_create_server(data, mntfh);
2133 if (IS_ERR(server)) {
2134 error = PTR_ERR(server);
2135 goto out;
2137 sb_mntdata.server = server;
2139 if (server->flags & NFS_MOUNT_UNSHARED)
2140 compare_super = NULL;
2142 /* Get a superblock - note that we may end up sharing one that already exists */
2143 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
2144 if (IS_ERR(s)) {
2145 error = PTR_ERR(s);
2146 goto out_err_nosb;
2149 if (s->s_fs_info != server) {
2150 nfs_free_server(server);
2151 server = NULL;
2152 } else {
2153 error = nfs_bdi_register(server);
2154 if (error)
2155 goto error_splat_super;
2158 if (!s->s_root) {
2159 /* initial superblock/root creation */
2160 nfs_fill_super(s, data);
2161 nfs_fscache_get_super_cookie(
2162 s, data ? data->fscache_uniq : NULL, NULL);
2165 mntroot = nfs_get_root(s, mntfh);
2166 if (IS_ERR(mntroot)) {
2167 error = PTR_ERR(mntroot);
2168 goto error_splat_super;
2171 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2172 if (error)
2173 goto error_splat_root;
2175 s->s_flags |= MS_ACTIVE;
2176 mnt->mnt_sb = s;
2177 mnt->mnt_root = mntroot;
2178 error = 0;
2180 out:
2181 kfree(data->nfs_server.hostname);
2182 kfree(data->mount_server.hostname);
2183 kfree(data->fscache_uniq);
2184 security_free_mnt_opts(&data->lsm_opts);
2185 out_free_fh:
2186 kfree(mntfh);
2187 kfree(data);
2188 return error;
2190 out_err_nosb:
2191 nfs_free_server(server);
2192 goto out;
2194 error_splat_root:
2195 dput(mntroot);
2196 error_splat_super:
2197 deactivate_locked_super(s);
2198 goto out;
2202 * Ensure that we unregister the bdi before kill_anon_super
2203 * releases the device name
2205 static void nfs_put_super(struct super_block *s)
2207 struct nfs_server *server = NFS_SB(s);
2209 bdi_unregister(&server->backing_dev_info);
2213 * Destroy an NFS2/3 superblock
2215 static void nfs_kill_super(struct super_block *s)
2217 struct nfs_server *server = NFS_SB(s);
2219 kill_anon_super(s);
2220 nfs_fscache_release_super_cookie(s);
2221 nfs_free_server(server);
2225 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
2227 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
2228 const char *dev_name, void *raw_data,
2229 struct vfsmount *mnt)
2231 struct nfs_clone_mount *data = raw_data;
2232 struct super_block *s;
2233 struct nfs_server *server;
2234 struct dentry *mntroot;
2235 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2236 struct nfs_sb_mountdata sb_mntdata = {
2237 .mntflags = flags,
2239 int error;
2241 dprintk("--> nfs_xdev_get_sb()\n");
2243 /* create a new volume representation */
2244 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2245 if (IS_ERR(server)) {
2246 error = PTR_ERR(server);
2247 goto out_err_noserver;
2249 sb_mntdata.server = server;
2251 if (server->flags & NFS_MOUNT_UNSHARED)
2252 compare_super = NULL;
2254 /* Get a superblock - note that we may end up sharing one that already exists */
2255 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2256 if (IS_ERR(s)) {
2257 error = PTR_ERR(s);
2258 goto out_err_nosb;
2261 if (s->s_fs_info != server) {
2262 nfs_free_server(server);
2263 server = NULL;
2264 } else {
2265 error = nfs_bdi_register(server);
2266 if (error)
2267 goto error_splat_super;
2270 if (!s->s_root) {
2271 /* initial superblock/root creation */
2272 nfs_clone_super(s, data->sb);
2273 nfs_fscache_get_super_cookie(s, NULL, data);
2276 mntroot = nfs_get_root(s, data->fh);
2277 if (IS_ERR(mntroot)) {
2278 error = PTR_ERR(mntroot);
2279 goto error_splat_super;
2281 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2282 dput(mntroot);
2283 error = -ESTALE;
2284 goto error_splat_super;
2287 s->s_flags |= MS_ACTIVE;
2288 mnt->mnt_sb = s;
2289 mnt->mnt_root = mntroot;
2291 /* clone any lsm security options from the parent to the new sb */
2292 security_sb_clone_mnt_opts(data->sb, s);
2294 dprintk("<-- nfs_xdev_get_sb() = 0\n");
2295 return 0;
2297 out_err_nosb:
2298 nfs_free_server(server);
2299 out_err_noserver:
2300 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
2301 return error;
2303 error_splat_super:
2304 deactivate_locked_super(s);
2305 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
2306 return error;
2309 #ifdef CONFIG_NFS_V4
2312 * Finish setting up a cloned NFS4 superblock
2314 static void nfs4_clone_super(struct super_block *sb,
2315 const struct super_block *old_sb)
2317 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
2318 sb->s_blocksize = old_sb->s_blocksize;
2319 sb->s_maxbytes = old_sb->s_maxbytes;
2320 sb->s_time_gran = 1;
2321 sb->s_op = old_sb->s_op;
2322 nfs_initialise_sb(sb);
2326 * Set up an NFS4 superblock
2328 static void nfs4_fill_super(struct super_block *sb)
2330 sb->s_time_gran = 1;
2331 sb->s_op = &nfs4_sops;
2332 nfs_initialise_sb(sb);
2335 static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args)
2337 args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3);
2340 static int nfs4_validate_text_mount_data(void *options,
2341 struct nfs_parsed_mount_data *args,
2342 const char *dev_name)
2344 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2346 nfs_set_port(sap, &args->nfs_server.port, NFS_PORT);
2348 nfs_validate_transport_protocol(args);
2350 nfs4_validate_mount_flags(args);
2352 if (args->version != 4) {
2353 dfprintk(MOUNT,
2354 "NFS4: Illegal mount version\n");
2355 return -EINVAL;
2358 if (args->auth_flavor_len > 1) {
2359 dfprintk(MOUNT,
2360 "NFS4: Too many RPC auth flavours specified\n");
2361 return -EINVAL;
2364 if (args->client_address == NULL) {
2365 dfprintk(MOUNT,
2366 "NFS4: mount program didn't pass callback address\n");
2367 return -EINVAL;
2370 return nfs_parse_devname(dev_name,
2371 &args->nfs_server.hostname,
2372 NFS4_MAXNAMLEN,
2373 &args->nfs_server.export_path,
2374 NFS4_MAXPATHLEN);
2378 * Validate NFSv4 mount options
2380 static int nfs4_validate_mount_data(void *options,
2381 struct nfs_parsed_mount_data *args,
2382 const char *dev_name)
2384 struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address;
2385 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
2386 char *c;
2388 if (data == NULL)
2389 goto out_no_data;
2391 switch (data->version) {
2392 case 1:
2393 if (data->host_addrlen > sizeof(args->nfs_server.address))
2394 goto out_no_address;
2395 if (data->host_addrlen == 0)
2396 goto out_no_address;
2397 args->nfs_server.addrlen = data->host_addrlen;
2398 if (copy_from_user(sap, data->host_addr, data->host_addrlen))
2399 return -EFAULT;
2400 if (!nfs_verify_server_address(sap))
2401 goto out_no_address;
2403 if (data->auth_flavourlen) {
2404 if (data->auth_flavourlen > 1)
2405 goto out_inval_auth;
2406 if (copy_from_user(&args->auth_flavors[0],
2407 data->auth_flavours,
2408 sizeof(args->auth_flavors[0])))
2409 return -EFAULT;
2412 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
2413 if (IS_ERR(c))
2414 return PTR_ERR(c);
2415 args->nfs_server.hostname = c;
2417 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
2418 if (IS_ERR(c))
2419 return PTR_ERR(c);
2420 args->nfs_server.export_path = c;
2421 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
2423 c = strndup_user(data->client_addr.data, 16);
2424 if (IS_ERR(c))
2425 return PTR_ERR(c);
2426 args->client_address = c;
2429 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
2430 * can deal with.
2433 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
2434 args->rsize = data->rsize;
2435 args->wsize = data->wsize;
2436 args->timeo = data->timeo;
2437 args->retrans = data->retrans;
2438 args->acregmin = data->acregmin;
2439 args->acregmax = data->acregmax;
2440 args->acdirmin = data->acdirmin;
2441 args->acdirmax = data->acdirmax;
2442 args->nfs_server.protocol = data->proto;
2443 nfs_validate_transport_protocol(args);
2445 break;
2446 default:
2447 if (nfs_parse_mount_options((char *)options, args) == 0)
2448 return -EINVAL;
2450 if (!nfs_verify_server_address(sap))
2451 return -EINVAL;
2453 return nfs4_validate_text_mount_data(options, args, dev_name);
2456 return 0;
2458 out_no_data:
2459 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
2460 return -EINVAL;
2462 out_inval_auth:
2463 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
2464 data->auth_flavourlen);
2465 return -EINVAL;
2467 out_no_address:
2468 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
2469 return -EINVAL;
2473 * Get the superblock for the NFS4 root partition
2475 static int nfs4_remote_get_sb(struct file_system_type *fs_type,
2476 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2478 struct nfs_parsed_mount_data *data = raw_data;
2479 struct super_block *s;
2480 struct nfs_server *server;
2481 struct nfs_fh *mntfh;
2482 struct dentry *mntroot;
2483 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2484 struct nfs_sb_mountdata sb_mntdata = {
2485 .mntflags = flags,
2487 int error = -ENOMEM;
2489 mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
2490 if (data == NULL || mntfh == NULL)
2491 goto out_free_fh;
2493 security_init_mnt_opts(&data->lsm_opts);
2495 /* Get a volume representation */
2496 server = nfs4_create_server(data, mntfh);
2497 if (IS_ERR(server)) {
2498 error = PTR_ERR(server);
2499 goto out;
2501 sb_mntdata.server = server;
2503 if (server->flags & NFS4_MOUNT_UNSHARED)
2504 compare_super = NULL;
2506 /* Get a superblock - note that we may end up sharing one that already exists */
2507 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2508 if (IS_ERR(s)) {
2509 error = PTR_ERR(s);
2510 goto out_free;
2513 if (s->s_fs_info != server) {
2514 nfs_free_server(server);
2515 server = NULL;
2516 } else {
2517 error = nfs_bdi_register(server);
2518 if (error)
2519 goto error_splat_super;
2522 if (!s->s_root) {
2523 /* initial superblock/root creation */
2524 nfs4_fill_super(s);
2525 nfs_fscache_get_super_cookie(
2526 s, data ? data->fscache_uniq : NULL, NULL);
2529 mntroot = nfs4_get_root(s, mntfh);
2530 if (IS_ERR(mntroot)) {
2531 error = PTR_ERR(mntroot);
2532 goto error_splat_super;
2535 error = security_sb_set_mnt_opts(s, &data->lsm_opts);
2536 if (error)
2537 goto error_splat_root;
2539 s->s_flags |= MS_ACTIVE;
2540 mnt->mnt_sb = s;
2541 mnt->mnt_root = mntroot;
2542 error = 0;
2544 out:
2545 security_free_mnt_opts(&data->lsm_opts);
2546 out_free_fh:
2547 kfree(mntfh);
2548 return error;
2550 out_free:
2551 nfs_free_server(server);
2552 goto out;
2554 error_splat_root:
2555 dput(mntroot);
2556 error_splat_super:
2557 deactivate_locked_super(s);
2558 goto out;
2561 static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2562 int flags, void *data, const char *hostname)
2564 struct vfsmount *root_mnt;
2565 char *root_devname;
2566 size_t len;
2568 len = strlen(hostname) + 3;
2569 root_devname = kmalloc(len, GFP_KERNEL);
2570 if (root_devname == NULL)
2571 return ERR_PTR(-ENOMEM);
2572 snprintf(root_devname, len, "%s:/", hostname);
2573 root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
2574 kfree(root_devname);
2575 return root_mnt;
2578 static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt)
2580 char *page = (char *) __get_free_page(GFP_KERNEL);
2581 char *devname, *tmp;
2583 if (page == NULL)
2584 return;
2585 devname = nfs_path(path->mnt->mnt_devname,
2586 path->mnt->mnt_root, path->dentry,
2587 page, PAGE_SIZE);
2588 if (devname == NULL)
2589 goto out_freepage;
2590 tmp = kstrdup(devname, GFP_KERNEL);
2591 if (tmp == NULL)
2592 goto out_freepage;
2593 kfree(mnt->mnt_devname);
2594 mnt->mnt_devname = tmp;
2595 out_freepage:
2596 free_page((unsigned long)page);
2599 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2600 const char *export_path, struct vfsmount *mnt_target)
2602 struct mnt_namespace *ns_private;
2603 struct nameidata nd;
2604 struct super_block *s;
2605 int ret;
2607 ns_private = create_mnt_ns(root_mnt);
2608 ret = PTR_ERR(ns_private);
2609 if (IS_ERR(ns_private))
2610 goto out_mntput;
2612 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
2613 export_path, LOOKUP_FOLLOW, &nd);
2615 put_mnt_ns(ns_private);
2617 if (ret != 0)
2618 goto out_err;
2620 s = nd.path.mnt->mnt_sb;
2621 atomic_inc(&s->s_active);
2622 mnt_target->mnt_sb = s;
2623 mnt_target->mnt_root = dget(nd.path.dentry);
2625 /* Correct the device pathname */
2626 nfs_fix_devname(&nd.path, mnt_target);
2628 path_put(&nd.path);
2629 down_write(&s->s_umount);
2630 return 0;
2631 out_mntput:
2632 mntput(root_mnt);
2633 out_err:
2634 return ret;
2637 static int nfs4_try_mount(int flags, const char *dev_name,
2638 struct nfs_parsed_mount_data *data,
2639 struct vfsmount *mnt)
2641 char *export_path;
2642 struct vfsmount *root_mnt;
2643 int error;
2645 dfprintk(MOUNT, "--> nfs4_try_mount()\n");
2647 export_path = data->nfs_server.export_path;
2648 data->nfs_server.export_path = "/";
2649 root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data,
2650 data->nfs_server.hostname);
2651 data->nfs_server.export_path = export_path;
2653 error = PTR_ERR(root_mnt);
2654 if (IS_ERR(root_mnt))
2655 goto out;
2657 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2659 out:
2660 dfprintk(MOUNT, "<-- nfs4_try_mount() = %d%s\n", error,
2661 error != 0 ? " [error]" : "");
2662 return error;
2666 * Get the superblock for an NFS4 mountpoint
2668 static int nfs4_get_sb(struct file_system_type *fs_type,
2669 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
2671 struct nfs_parsed_mount_data *data;
2672 int error = -ENOMEM;
2674 data = nfs_alloc_parsed_mount_data(4);
2675 if (data == NULL)
2676 goto out_free_data;
2678 /* Validate the mount data */
2679 error = nfs4_validate_mount_data(raw_data, data, dev_name);
2680 if (error < 0)
2681 goto out;
2683 error = nfs4_try_mount(flags, dev_name, data, mnt);
2685 out:
2686 kfree(data->client_address);
2687 kfree(data->nfs_server.export_path);
2688 kfree(data->nfs_server.hostname);
2689 kfree(data->fscache_uniq);
2690 out_free_data:
2691 kfree(data);
2692 dprintk("<-- nfs4_get_sb() = %d%s\n", error,
2693 error != 0 ? " [error]" : "");
2694 return error;
2697 static void nfs4_kill_super(struct super_block *sb)
2699 struct nfs_server *server = NFS_SB(sb);
2701 dprintk("--> %s\n", __func__);
2702 nfs_super_return_all_delegations(sb);
2703 kill_anon_super(sb);
2704 nfs_fscache_release_super_cookie(sb);
2705 nfs_free_server(server);
2706 dprintk("<-- %s\n", __func__);
2710 * Clone an NFS4 server record on xdev traversal (FSID-change)
2712 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2713 const char *dev_name, void *raw_data,
2714 struct vfsmount *mnt)
2716 struct nfs_clone_mount *data = raw_data;
2717 struct super_block *s;
2718 struct nfs_server *server;
2719 struct dentry *mntroot;
2720 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2721 struct nfs_sb_mountdata sb_mntdata = {
2722 .mntflags = flags,
2724 int error;
2726 dprintk("--> nfs4_xdev_get_sb()\n");
2728 /* create a new volume representation */
2729 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
2730 if (IS_ERR(server)) {
2731 error = PTR_ERR(server);
2732 goto out_err_noserver;
2734 sb_mntdata.server = server;
2736 if (server->flags & NFS4_MOUNT_UNSHARED)
2737 compare_super = NULL;
2739 /* Get a superblock - note that we may end up sharing one that already exists */
2740 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2741 if (IS_ERR(s)) {
2742 error = PTR_ERR(s);
2743 goto out_err_nosb;
2746 if (s->s_fs_info != server) {
2747 nfs_free_server(server);
2748 server = NULL;
2749 } else {
2750 error = nfs_bdi_register(server);
2751 if (error)
2752 goto error_splat_super;
2755 if (!s->s_root) {
2756 /* initial superblock/root creation */
2757 nfs4_clone_super(s, data->sb);
2758 nfs_fscache_get_super_cookie(s, NULL, data);
2761 mntroot = nfs4_get_root(s, data->fh);
2762 if (IS_ERR(mntroot)) {
2763 error = PTR_ERR(mntroot);
2764 goto error_splat_super;
2766 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2767 dput(mntroot);
2768 error = -ESTALE;
2769 goto error_splat_super;
2772 s->s_flags |= MS_ACTIVE;
2773 mnt->mnt_sb = s;
2774 mnt->mnt_root = mntroot;
2776 security_sb_clone_mnt_opts(data->sb, s);
2778 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
2779 return 0;
2781 out_err_nosb:
2782 nfs_free_server(server);
2783 out_err_noserver:
2784 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
2785 return error;
2787 error_splat_super:
2788 deactivate_locked_super(s);
2789 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
2790 return error;
2793 static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
2794 int flags, const char *dev_name, void *raw_data,
2795 struct vfsmount *mnt)
2797 struct nfs_clone_mount *data = raw_data;
2798 struct super_block *s;
2799 struct nfs_server *server;
2800 struct dentry *mntroot;
2801 struct nfs_fh mntfh;
2802 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
2803 struct nfs_sb_mountdata sb_mntdata = {
2804 .mntflags = flags,
2806 int error;
2808 dprintk("--> nfs4_referral_get_sb()\n");
2810 /* create a new volume representation */
2811 server = nfs4_create_referral_server(data, &mntfh);
2812 if (IS_ERR(server)) {
2813 error = PTR_ERR(server);
2814 goto out_err_noserver;
2816 sb_mntdata.server = server;
2818 if (server->flags & NFS4_MOUNT_UNSHARED)
2819 compare_super = NULL;
2821 /* Get a superblock - note that we may end up sharing one that already exists */
2822 s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata);
2823 if (IS_ERR(s)) {
2824 error = PTR_ERR(s);
2825 goto out_err_nosb;
2828 if (s->s_fs_info != server) {
2829 nfs_free_server(server);
2830 server = NULL;
2831 } else {
2832 error = nfs_bdi_register(server);
2833 if (error)
2834 goto error_splat_super;
2837 if (!s->s_root) {
2838 /* initial superblock/root creation */
2839 nfs4_fill_super(s);
2840 nfs_fscache_get_super_cookie(s, NULL, data);
2843 mntroot = nfs4_get_root(s, &mntfh);
2844 if (IS_ERR(mntroot)) {
2845 error = PTR_ERR(mntroot);
2846 goto error_splat_super;
2848 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
2849 dput(mntroot);
2850 error = -ESTALE;
2851 goto error_splat_super;
2854 s->s_flags |= MS_ACTIVE;
2855 mnt->mnt_sb = s;
2856 mnt->mnt_root = mntroot;
2858 security_sb_clone_mnt_opts(data->sb, s);
2860 dprintk("<-- nfs4_referral_get_sb() = 0\n");
2861 return 0;
2863 out_err_nosb:
2864 nfs_free_server(server);
2865 out_err_noserver:
2866 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
2867 return error;
2869 error_splat_super:
2870 deactivate_locked_super(s);
2871 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
2872 return error;
2876 * Create an NFS4 server record on referral traversal
2878 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
2879 int flags, const char *dev_name, void *raw_data,
2880 struct vfsmount *mnt)
2882 struct nfs_clone_mount *data = raw_data;
2883 char *export_path;
2884 struct vfsmount *root_mnt;
2885 int error;
2887 dprintk("--> nfs4_referral_get_sb()\n");
2889 export_path = data->mnt_path;
2890 data->mnt_path = "/";
2892 root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type,
2893 flags, data, data->hostname);
2894 data->mnt_path = export_path;
2896 error = PTR_ERR(root_mnt);
2897 if (IS_ERR(root_mnt))
2898 goto out;
2900 error = nfs_follow_remote_path(root_mnt, export_path, mnt);
2901 out:
2902 dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error,
2903 error != 0 ? " [error]" : "");
2904 return error;
2907 #endif /* CONFIG_NFS_V4 */