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