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