4 * Copyright (C) 1992 Rick Sladkey
6 * nfs superblock handling functions
8 * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
9 * experimental NFS changes. Modularisation taken straight from SYS5 fs.
11 * Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
12 * J.S.Peatfield@damtp.cam.ac.uk
14 * Split from inode.c by David Howells <dhowells@redhat.com>
16 * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
17 * particular server are held in the same superblock
18 * - NFS superblocks can have several effective roots to the dentry tree
19 * - directory type roots are spliced into the tree when a path from one root reaches the root
20 * of another (see nfs_lookup())
23 #include <linux/module.h>
24 #include <linux/init.h>
26 #include <linux/time.h>
27 #include <linux/kernel.h>
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/nfs_fs.h>
38 #include <linux/nfs_mount.h>
39 #include <linux/nfs4_mount.h>
40 #include <linux/lockd/bind.h>
41 #include <linux/smp_lock.h>
42 #include <linux/seq_file.h>
43 #include <linux/mount.h>
44 #include <linux/nfs_idmap.h>
45 #include <linux/vfs.h>
46 #include <linux/inet.h>
47 #include <linux/nfs_xdr.h>
48 #include <linux/magic.h>
49 #include <linux/parser.h>
51 #include <asm/system.h>
52 #include <asm/uaccess.h>
56 #include "delegation.h"
60 #define NFSDBG_FACILITY NFSDBG_VFS
63 /* Mount options that take no arguments */
66 Opt_posix, Opt_noposix,
73 Opt_rdirplus, Opt_nordirplus,
74 Opt_sharecache, Opt_nosharecache,
76 /* Mount options that take integer arguments */
78 Opt_rsize, Opt_wsize, Opt_bsize,
79 Opt_timeo, Opt_retrans,
80 Opt_acregmin, Opt_acregmax,
81 Opt_acdirmin, Opt_acdirmax,
85 Opt_mountprog, Opt_mountvers,
86 Opt_nfsprog, Opt_nfsvers,
88 /* Mount options that take string arguments */
89 Opt_sec, Opt_proto, Opt_mountproto,
90 Opt_addr, Opt_mountaddr, Opt_clientaddr,
92 /* Mount options that are ignored */
93 Opt_userspace, Opt_deprecated,
98 static match_table_t nfs_mount_option_tokens = {
99 { Opt_userspace, "bg" },
100 { Opt_userspace, "fg" },
101 { Opt_soft, "soft" },
102 { Opt_hard, "hard" },
103 { Opt_intr, "intr" },
104 { Opt_nointr, "nointr" },
105 { Opt_posix, "posix" },
106 { Opt_noposix, "noposix" },
108 { Opt_nocto, "nocto" },
110 { Opt_noac, "noac" },
111 { Opt_lock, "lock" },
112 { Opt_nolock, "nolock" },
118 { Opt_noacl, "noacl" },
119 { Opt_rdirplus, "rdirplus" },
120 { Opt_nordirplus, "nordirplus" },
121 { Opt_sharecache, "sharecache" },
122 { Opt_nosharecache, "nosharecache" },
124 { Opt_port, "port=%u" },
125 { Opt_rsize, "rsize=%u" },
126 { Opt_wsize, "wsize=%u" },
127 { Opt_bsize, "bsize=%u" },
128 { Opt_timeo, "timeo=%u" },
129 { Opt_retrans, "retrans=%u" },
130 { Opt_acregmin, "acregmin=%u" },
131 { Opt_acregmax, "acregmax=%u" },
132 { Opt_acdirmin, "acdirmin=%u" },
133 { Opt_acdirmax, "acdirmax=%u" },
134 { Opt_actimeo, "actimeo=%u" },
135 { Opt_userspace, "retry=%u" },
136 { Opt_namelen, "namlen=%u" },
137 { Opt_mountport, "mountport=%u" },
138 { Opt_mountprog, "mountprog=%u" },
139 { Opt_mountvers, "mountvers=%u" },
140 { Opt_nfsprog, "nfsprog=%u" },
141 { Opt_nfsvers, "nfsvers=%u" },
142 { Opt_nfsvers, "vers=%u" },
144 { Opt_sec, "sec=%s" },
145 { Opt_proto, "proto=%s" },
146 { Opt_mountproto, "mountproto=%s" },
147 { Opt_addr, "addr=%s" },
148 { Opt_clientaddr, "clientaddr=%s" },
149 { Opt_userspace, "mounthost=%s" },
150 { Opt_mountaddr, "mountaddr=%s" },
156 Opt_xprt_udp, Opt_xprt_tcp,
161 static match_table_t nfs_xprt_protocol_tokens = {
162 { Opt_xprt_udp, "udp" },
163 { Opt_xprt_tcp, "tcp" },
165 { Opt_xprt_err, NULL }
169 Opt_sec_none, Opt_sec_sys,
170 Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p,
171 Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp,
172 Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp,
177 static match_table_t nfs_secflavor_tokens = {
178 { Opt_sec_none, "none" },
179 { Opt_sec_none, "null" },
180 { Opt_sec_sys, "sys" },
182 { Opt_sec_krb5, "krb5" },
183 { Opt_sec_krb5i, "krb5i" },
184 { Opt_sec_krb5p, "krb5p" },
186 { Opt_sec_lkey, "lkey" },
187 { Opt_sec_lkeyi, "lkeyi" },
188 { Opt_sec_lkeyp, "lkeyp" },
190 { Opt_sec_err, NULL }
194 static void nfs_umount_begin(struct vfsmount *, int);
195 static int nfs_statfs(struct dentry *, struct kstatfs *);
196 static int nfs_show_options(struct seq_file *, struct vfsmount *);
197 static int nfs_show_stats(struct seq_file *, struct vfsmount *);
198 static int nfs_get_sb(struct file_system_type *, int, const char *, void *, struct vfsmount *);
199 static int nfs_xdev_get_sb(struct file_system_type *fs_type,
200 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
201 static void nfs_kill_super(struct super_block *);
203 static struct file_system_type nfs_fs_type = {
204 .owner = THIS_MODULE,
206 .get_sb = nfs_get_sb,
207 .kill_sb = nfs_kill_super,
208 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
211 struct file_system_type nfs_xdev_fs_type = {
212 .owner = THIS_MODULE,
214 .get_sb = nfs_xdev_get_sb,
215 .kill_sb = nfs_kill_super,
216 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
219 static const struct super_operations nfs_sops = {
220 .alloc_inode = nfs_alloc_inode,
221 .destroy_inode = nfs_destroy_inode,
222 .write_inode = nfs_write_inode,
223 .statfs = nfs_statfs,
224 .clear_inode = nfs_clear_inode,
225 .umount_begin = nfs_umount_begin,
226 .show_options = nfs_show_options,
227 .show_stats = nfs_show_stats,
231 static int nfs4_get_sb(struct file_system_type *fs_type,
232 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
233 static int nfs4_xdev_get_sb(struct file_system_type *fs_type,
234 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
235 static int nfs4_referral_get_sb(struct file_system_type *fs_type,
236 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt);
237 static void nfs4_kill_super(struct super_block *sb);
239 static struct file_system_type nfs4_fs_type = {
240 .owner = THIS_MODULE,
242 .get_sb = nfs4_get_sb,
243 .kill_sb = nfs4_kill_super,
244 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
247 struct file_system_type nfs4_xdev_fs_type = {
248 .owner = THIS_MODULE,
250 .get_sb = nfs4_xdev_get_sb,
251 .kill_sb = nfs4_kill_super,
252 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
255 struct file_system_type nfs4_referral_fs_type = {
256 .owner = THIS_MODULE,
258 .get_sb = nfs4_referral_get_sb,
259 .kill_sb = nfs4_kill_super,
260 .fs_flags = FS_RENAME_DOES_D_MOVE|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
263 static const struct super_operations nfs4_sops = {
264 .alloc_inode = nfs_alloc_inode,
265 .destroy_inode = nfs_destroy_inode,
266 .write_inode = nfs_write_inode,
267 .statfs = nfs_statfs,
268 .clear_inode = nfs4_clear_inode,
269 .umount_begin = nfs_umount_begin,
270 .show_options = nfs_show_options,
271 .show_stats = nfs_show_stats,
275 static struct shrinker acl_shrinker = {
276 .shrink = nfs_access_cache_shrinker,
277 .seeks = DEFAULT_SEEKS,
281 * Register the NFS filesystems
283 int __init register_nfs_fs(void)
287 ret = register_filesystem(&nfs_fs_type);
291 ret = nfs_register_sysctl();
295 ret = register_filesystem(&nfs4_fs_type);
299 register_shrinker(&acl_shrinker);
304 nfs_unregister_sysctl();
307 unregister_filesystem(&nfs_fs_type);
313 * Unregister the NFS filesystems
315 void __exit unregister_nfs_fs(void)
317 unregister_shrinker(&acl_shrinker);
319 unregister_filesystem(&nfs4_fs_type);
321 nfs_unregister_sysctl();
322 unregister_filesystem(&nfs_fs_type);
326 * Deliver file system statistics to userspace
328 static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
330 struct nfs_server *server = NFS_SB(dentry->d_sb);
331 unsigned char blockbits;
332 unsigned long blockres;
333 struct nfs_fh *fh = NFS_FH(dentry->d_inode);
334 struct nfs_fattr fattr;
335 struct nfs_fsstat res = {
342 error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
345 buf->f_type = NFS_SUPER_MAGIC;
348 * Current versions of glibc do not correctly handle the
349 * case where f_frsize != f_bsize. Eventually we want to
350 * report the value of wtmult in this field.
352 buf->f_frsize = dentry->d_sb->s_blocksize;
355 * On most *nix systems, f_blocks, f_bfree, and f_bavail
356 * are reported in units of f_frsize. Linux hasn't had
357 * an f_frsize field in its statfs struct until recently,
358 * thus historically Linux's sys_statfs reports these
359 * fields in units of f_bsize.
361 buf->f_bsize = dentry->d_sb->s_blocksize;
362 blockbits = dentry->d_sb->s_blocksize_bits;
363 blockres = (1 << blockbits) - 1;
364 buf->f_blocks = (res.tbytes + blockres) >> blockbits;
365 buf->f_bfree = (res.fbytes + blockres) >> blockbits;
366 buf->f_bavail = (res.abytes + blockres) >> blockbits;
368 buf->f_files = res.tfiles;
369 buf->f_ffree = res.afiles;
371 buf->f_namelen = server->namelen;
377 dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
383 * Map the security flavour number to a name
385 static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
387 static const struct {
388 rpc_authflavor_t flavour;
391 { RPC_AUTH_NULL, "null" },
392 { RPC_AUTH_UNIX, "sys" },
393 { RPC_AUTH_GSS_KRB5, "krb5" },
394 { RPC_AUTH_GSS_KRB5I, "krb5i" },
395 { RPC_AUTH_GSS_KRB5P, "krb5p" },
396 { RPC_AUTH_GSS_LKEY, "lkey" },
397 { RPC_AUTH_GSS_LKEYI, "lkeyi" },
398 { RPC_AUTH_GSS_LKEYP, "lkeyp" },
399 { RPC_AUTH_GSS_SPKM, "spkm" },
400 { RPC_AUTH_GSS_SPKMI, "spkmi" },
401 { RPC_AUTH_GSS_SPKMP, "spkmp" },
402 { UINT_MAX, "unknown" }
406 for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
407 if (sec_flavours[i].flavour == flavour)
410 return sec_flavours[i].str;
414 * Describe the mount options in force on this server representation
416 static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
418 static const struct proc_nfs_info {
423 { NFS_MOUNT_SOFT, ",soft", ",hard" },
424 { NFS_MOUNT_INTR, ",intr", "" },
425 { NFS_MOUNT_NOCTO, ",nocto", "" },
426 { NFS_MOUNT_NOAC, ",noac", "" },
427 { NFS_MOUNT_NONLM, ",nolock", "" },
428 { NFS_MOUNT_NOACL, ",noacl", "" },
429 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
430 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
433 const struct proc_nfs_info *nfs_infop;
434 struct nfs_client *clp = nfss->nfs_client;
436 seq_printf(m, ",vers=%d", clp->rpc_ops->version);
437 seq_printf(m, ",rsize=%d", nfss->rsize);
438 seq_printf(m, ",wsize=%d", nfss->wsize);
439 if (nfss->acregmin != 3*HZ || showdefaults)
440 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
441 if (nfss->acregmax != 60*HZ || showdefaults)
442 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
443 if (nfss->acdirmin != 30*HZ || showdefaults)
444 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
445 if (nfss->acdirmax != 60*HZ || showdefaults)
446 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
447 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
448 if (nfss->flags & nfs_infop->flag)
449 seq_puts(m, nfs_infop->str);
451 seq_puts(m, nfs_infop->nostr);
453 seq_printf(m, ",proto=%s",
454 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
455 seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ);
456 seq_printf(m, ",retrans=%u", clp->retrans_count);
457 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
461 * Describe the mount options on this VFS mountpoint
463 static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
465 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
467 nfs_show_mount_options(m, nfss, 0);
469 seq_printf(m, ",addr="NIPQUAD_FMT,
470 NIPQUAD(nfss->nfs_client->cl_addr.sin_addr));
476 * Present statistical information for this VFS mountpoint
478 static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
481 struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
482 struct rpc_auth *auth = nfss->client->cl_auth;
483 struct nfs_iostats totals = { };
485 seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
488 * Display all mount option settings
490 seq_printf(m, "\n\topts:\t");
491 seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
492 seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
493 seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
494 seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
495 nfs_show_mount_options(m, nfss, 1);
497 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
499 seq_printf(m, "\n\tcaps:\t");
500 seq_printf(m, "caps=0x%x", nfss->caps);
501 seq_printf(m, ",wtmult=%d", nfss->wtmult);
502 seq_printf(m, ",dtsize=%d", nfss->dtsize);
503 seq_printf(m, ",bsize=%d", nfss->bsize);
504 seq_printf(m, ",namelen=%d", nfss->namelen);
507 if (nfss->nfs_client->cl_nfsversion == 4) {
508 seq_printf(m, "\n\tnfsv4:\t");
509 seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
510 seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
511 seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
516 * Display security flavor in effect for this mount
518 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
520 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
523 * Display superblock I/O counters
525 for_each_possible_cpu(cpu) {
526 struct nfs_iostats *stats;
529 stats = per_cpu_ptr(nfss->io_stats, cpu);
531 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
532 totals.events[i] += stats->events[i];
533 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
534 totals.bytes[i] += stats->bytes[i];
539 seq_printf(m, "\n\tevents:\t");
540 for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
541 seq_printf(m, "%lu ", totals.events[i]);
542 seq_printf(m, "\n\tbytes:\t");
543 for (i = 0; i < __NFSIOS_BYTESMAX; i++)
544 seq_printf(m, "%Lu ", totals.bytes[i]);
547 rpc_print_iostats(m, nfss->client);
553 * Begin unmount by attempting to remove all automounted mountpoints we added
554 * in response to xdev traversals and referrals
556 static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
558 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
559 struct rpc_clnt *rpc;
561 shrink_submounts(vfsmnt, &nfs_automount_list);
563 if (!(flags & MNT_FORCE))
565 /* -EIO all pending I/O */
566 rpc = server->client_acl;
568 rpc_killall_tasks(rpc);
569 rpc = server->client;
571 rpc_killall_tasks(rpc);
575 * Sanity-check a server address provided by the mount command
577 static int nfs_verify_server_address(struct sockaddr *addr)
579 switch (addr->sa_family) {
581 struct sockaddr_in *sa = (struct sockaddr_in *) addr;
582 if (sa->sin_addr.s_addr != INADDR_ANY)
592 * Error-check and convert a string of mount options from user space into
595 static int nfs_parse_mount_options(char *raw,
596 struct nfs_parsed_mount_data *mnt)
601 dfprintk(MOUNT, "NFS: mount options string was NULL.\n");
604 dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw);
606 while ((p = strsep(&raw, ",")) != NULL) {
607 substring_t args[MAX_OPT_ARGS];
613 dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p);
615 token = match_token(p, nfs_mount_option_tokens, args);
618 mnt->flags |= NFS_MOUNT_SOFT;
621 mnt->flags &= ~NFS_MOUNT_SOFT;
624 mnt->flags |= NFS_MOUNT_INTR;
627 mnt->flags &= ~NFS_MOUNT_INTR;
630 mnt->flags |= NFS_MOUNT_POSIX;
633 mnt->flags &= ~NFS_MOUNT_POSIX;
636 mnt->flags &= ~NFS_MOUNT_NOCTO;
639 mnt->flags |= NFS_MOUNT_NOCTO;
642 mnt->flags &= ~NFS_MOUNT_NOAC;
645 mnt->flags |= NFS_MOUNT_NOAC;
648 mnt->flags &= ~NFS_MOUNT_NONLM;
651 mnt->flags |= NFS_MOUNT_NONLM;
654 mnt->flags &= ~NFS_MOUNT_VER3;
657 mnt->flags |= NFS_MOUNT_VER3;
660 mnt->flags &= ~NFS_MOUNT_TCP;
661 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
666 mnt->flags |= NFS_MOUNT_TCP;
667 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
672 mnt->flags &= ~NFS_MOUNT_NOACL;
675 mnt->flags |= NFS_MOUNT_NOACL;
678 mnt->flags &= ~NFS_MOUNT_NORDIRPLUS;
681 mnt->flags |= NFS_MOUNT_NORDIRPLUS;
684 mnt->flags &= ~NFS_MOUNT_UNSHARED;
686 case Opt_nosharecache:
687 mnt->flags |= NFS_MOUNT_UNSHARED;
691 if (match_int(args, &option))
693 if (option < 0 || option > 65535)
695 mnt->nfs_server.address.sin_port = htons(option);
698 if (match_int(args, &mnt->rsize))
702 if (match_int(args, &mnt->wsize))
706 if (match_int(args, &option))
713 if (match_int(args, &mnt->timeo))
717 if (match_int(args, &mnt->retrans))
721 if (match_int(args, &mnt->acregmin))
725 if (match_int(args, &mnt->acregmax))
729 if (match_int(args, &mnt->acdirmin))
733 if (match_int(args, &mnt->acdirmax))
737 if (match_int(args, &option))
744 mnt->acdirmax = option;
747 if (match_int(args, &mnt->namlen))
751 if (match_int(args, &option))
753 if (option < 0 || option > 65535)
755 mnt->mount_server.port = option;
758 if (match_int(args, &option))
762 mnt->mount_server.program = option;
765 if (match_int(args, &option))
769 mnt->mount_server.version = option;
772 if (match_int(args, &option))
776 mnt->nfs_server.program = option;
779 if (match_int(args, &option))
783 mnt->flags &= ~NFS_MOUNT_VER3;
786 mnt->flags |= NFS_MOUNT_VER3;
794 string = match_strdup(args);
797 token = match_token(string, nfs_secflavor_tokens, args);
801 * The flags setting is for v2/v3. The flavor_len
802 * setting is for v4. v2/v3 also need to know the
803 * difference between NULL and UNIX.
807 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
808 mnt->auth_flavor_len = 0;
809 mnt->auth_flavors[0] = RPC_AUTH_NULL;
812 mnt->flags &= ~NFS_MOUNT_SECFLAVOUR;
813 mnt->auth_flavor_len = 0;
814 mnt->auth_flavors[0] = RPC_AUTH_UNIX;
817 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
818 mnt->auth_flavor_len = 1;
819 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5;
822 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
823 mnt->auth_flavor_len = 1;
824 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I;
827 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
828 mnt->auth_flavor_len = 1;
829 mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P;
832 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
833 mnt->auth_flavor_len = 1;
834 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY;
837 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
838 mnt->auth_flavor_len = 1;
839 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI;
842 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
843 mnt->auth_flavor_len = 1;
844 mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP;
847 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
848 mnt->auth_flavor_len = 1;
849 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM;
852 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
853 mnt->auth_flavor_len = 1;
854 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI;
857 mnt->flags |= NFS_MOUNT_SECFLAVOUR;
858 mnt->auth_flavor_len = 1;
859 mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP;
866 string = match_strdup(args);
869 token = match_token(string,
870 nfs_xprt_protocol_tokens, args);
875 mnt->flags &= ~NFS_MOUNT_TCP;
876 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
881 mnt->flags |= NFS_MOUNT_TCP;
882 mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
891 string = match_strdup(args);
894 token = match_token(string,
895 nfs_xprt_protocol_tokens, args);
900 mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
903 mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
910 string = match_strdup(args);
913 mnt->nfs_server.address.sin_family = AF_INET;
914 mnt->nfs_server.address.sin_addr.s_addr =
919 string = match_strdup(args);
922 mnt->client_address = string;
925 string = match_strdup(args);
928 mnt->mount_server.address.sin_family = AF_INET;
929 mnt->mount_server.address.sin_addr.s_addr =
946 printk(KERN_INFO "NFS: not enough memory to parse option\n");
950 printk(KERN_INFO "NFS: unrecognized NFS version number\n");
954 printk(KERN_INFO "NFS: unrecognized transport protocol\n");
958 printk(KERN_INFO "NFS: unrecognized security flavor\n");
962 printk(KERN_INFO "NFS: unknown mount option: %s\n", p);
967 * Use the remote server's MOUNT service to request the NFS file handle
968 * corresponding to the provided path.
970 static int nfs_try_mount(struct nfs_parsed_mount_data *args,
971 struct nfs_fh *root_fh)
973 struct sockaddr_in sin;
976 if (args->mount_server.version == 0) {
977 if (args->flags & NFS_MOUNT_VER3)
978 args->mount_server.version = NFS_MNT3_VERSION;
980 args->mount_server.version = NFS_MNT_VERSION;
984 * Construct the mount server's address.
986 if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY)
987 sin = args->mount_server.address;
989 sin = args->nfs_server.address;
991 * autobind will be used if mount_server.port == 0
993 sin.sin_port = htons(args->mount_server.port);
996 * Now ask the mount server to map our export path
999 status = nfs_mount((struct sockaddr *) &sin,
1001 args->nfs_server.hostname,
1002 args->nfs_server.export_path,
1003 args->mount_server.version,
1004 args->mount_server.protocol,
1009 dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT
1010 ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status);
1015 * Validate the NFS2/NFS3 mount data
1016 * - fills in the mount root filehandle
1018 * For option strings, user space handles the following behaviors:
1020 * + DNS: mapping server host name to IP address ("addr=" option)
1022 * + failure mode: how to behave if a mount request can't be handled
1023 * immediately ("fg/bg" option)
1025 * + retry: how often to retry a mount request ("retry=" option)
1027 * + breaking back: trying proto=udp after proto=tcp, v2 after v3,
1028 * mountproto=tcp after mountproto=udp, and so on
1030 * XXX: as far as I can tell, changing the NFS program number is not
1031 * supported in the NFS client.
1033 static int nfs_validate_mount_data(void *options,
1034 struct nfs_parsed_mount_data *args,
1035 struct nfs_fh *mntfh,
1036 const char *dev_name)
1038 struct nfs_mount_data *data = (struct nfs_mount_data *)options;
1043 memset(args, 0, sizeof(*args));
1044 args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP);
1045 args->rsize = NFS_MAX_FILE_IO_SIZE;
1046 args->wsize = NFS_MAX_FILE_IO_SIZE;
1050 args->acregmax = 60;
1051 args->acdirmin = 30;
1052 args->acdirmax = 60;
1053 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1054 args->mount_server.program = NFS_MNT_PROGRAM;
1055 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1056 args->nfs_server.program = NFS_PROGRAM;
1058 switch (data->version) {
1064 if (data->flags & NFS_MOUNT_VER3)
1066 data->root.size = NFS2_FHSIZE;
1067 memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
1069 if (data->flags & NFS_MOUNT_SECFLAVOUR)
1072 memset(data->context, 0, sizeof(data->context));
1074 if (data->flags & NFS_MOUNT_VER3)
1075 mntfh->size = data->root.size;
1077 mntfh->size = NFS2_FHSIZE;
1079 if (mntfh->size > sizeof(mntfh->data))
1080 goto out_invalid_fh;
1082 memcpy(mntfh->data, data->root.data, mntfh->size);
1083 if (mntfh->size < sizeof(mntfh->data))
1084 memset(mntfh->data + mntfh->size, 0,
1085 sizeof(mntfh->data) - mntfh->size);
1087 * Translate to nfs_parsed_mount_data, which nfs_fill_super
1090 args->flags = data->flags;
1091 args->rsize = data->rsize;
1092 args->wsize = data->wsize;
1093 args->flags = data->flags;
1094 args->timeo = data->timeo;
1095 args->retrans = data->retrans;
1096 args->acregmin = data->acregmin;
1097 args->acregmax = data->acregmax;
1098 args->acdirmin = data->acdirmin;
1099 args->acdirmax = data->acdirmax;
1100 args->nfs_server.address = data->addr;
1101 if (!(data->flags & NFS_MOUNT_TCP))
1102 args->nfs_server.protocol = XPRT_TRANSPORT_UDP;
1103 /* N.B. caller will free nfs_server.hostname in all cases */
1104 args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL);
1105 args->namlen = data->namlen;
1106 args->bsize = data->bsize;
1107 args->auth_flavors[0] = data->pseudoflavor;
1114 if (nfs_parse_mount_options((char *)options, args) == 0)
1117 c = strchr(dev_name, ':');
1121 /* N.B. caller will free nfs_server.hostname in all cases */
1122 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1125 if (strlen(c) > NFS_MAXPATHLEN)
1126 return -ENAMETOOLONG;
1127 args->nfs_server.export_path = c;
1129 status = nfs_try_mount(args, mntfh);
1137 if (!(args->flags & NFS_MOUNT_SECFLAVOUR))
1138 args->auth_flavors[0] = RPC_AUTH_UNIX;
1140 #ifndef CONFIG_NFS_V3
1141 if (args->flags & NFS_MOUNT_VER3)
1142 goto out_v3_not_compiled;
1143 #endif /* !CONFIG_NFS_V3 */
1145 if (!nfs_verify_server_address((struct sockaddr *)
1146 &args->nfs_server.address))
1147 goto out_no_address;
1152 dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n");
1156 dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n",
1161 dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n");
1164 #ifndef CONFIG_NFS_V3
1165 out_v3_not_compiled:
1166 dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n");
1167 return -EPROTONOSUPPORT;
1168 #endif /* !CONFIG_NFS_V3 */
1171 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1175 dfprintk(MOUNT, "NFS: invalid root filehandle\n");
1180 * Initialise the common bits of the superblock
1182 static inline void nfs_initialise_sb(struct super_block *sb)
1184 struct nfs_server *server = NFS_SB(sb);
1186 sb->s_magic = NFS_SUPER_MAGIC;
1188 /* We probably want something more informative here */
1189 snprintf(sb->s_id, sizeof(sb->s_id),
1190 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
1192 if (sb->s_blocksize == 0)
1193 sb->s_blocksize = nfs_block_bits(server->wsize,
1194 &sb->s_blocksize_bits);
1196 if (server->flags & NFS_MOUNT_NOAC)
1197 sb->s_flags |= MS_SYNCHRONOUS;
1199 nfs_super_set_maxbytes(sb, server->maxfilesize);
1203 * Finish setting up an NFS2/3 superblock
1205 static void nfs_fill_super(struct super_block *sb,
1206 struct nfs_parsed_mount_data *data)
1208 struct nfs_server *server = NFS_SB(sb);
1210 sb->s_blocksize_bits = 0;
1211 sb->s_blocksize = 0;
1213 sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1215 if (server->flags & NFS_MOUNT_VER3) {
1216 /* The VFS shouldn't apply the umask to mode bits. We will do
1217 * so ourselves when necessary.
1219 sb->s_flags |= MS_POSIXACL;
1220 sb->s_time_gran = 1;
1223 sb->s_op = &nfs_sops;
1224 nfs_initialise_sb(sb);
1228 * Finish setting up a cloned NFS2/3 superblock
1230 static void nfs_clone_super(struct super_block *sb,
1231 const struct super_block *old_sb)
1233 struct nfs_server *server = NFS_SB(sb);
1235 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1236 sb->s_blocksize = old_sb->s_blocksize;
1237 sb->s_maxbytes = old_sb->s_maxbytes;
1239 if (server->flags & NFS_MOUNT_VER3) {
1240 /* The VFS shouldn't apply the umask to mode bits. We will do
1241 * so ourselves when necessary.
1243 sb->s_flags |= MS_POSIXACL;
1244 sb->s_time_gran = 1;
1247 sb->s_op = old_sb->s_op;
1248 nfs_initialise_sb(sb);
1251 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1253 static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags)
1255 const struct nfs_server *a = s->s_fs_info;
1256 const struct rpc_clnt *clnt_a = a->client;
1257 const struct rpc_clnt *clnt_b = b->client;
1259 if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK))
1261 if (a->nfs_client != b->nfs_client)
1263 if (a->flags != b->flags)
1265 if (a->wsize != b->wsize)
1267 if (a->rsize != b->rsize)
1269 if (a->acregmin != b->acregmin)
1271 if (a->acregmax != b->acregmax)
1273 if (a->acdirmin != b->acdirmin)
1275 if (a->acdirmax != b->acdirmax)
1277 if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
1284 struct nfs_sb_mountdata {
1285 struct nfs_server *server;
1289 static int nfs_set_super(struct super_block *s, void *data)
1291 struct nfs_sb_mountdata *sb_mntdata = data;
1292 struct nfs_server *server = sb_mntdata->server;
1295 s->s_flags = sb_mntdata->mntflags;
1296 s->s_fs_info = server;
1297 ret = set_anon_super(s, server);
1299 server->s_dev = s->s_dev;
1303 static int nfs_compare_super(struct super_block *sb, void *data)
1305 struct nfs_sb_mountdata *sb_mntdata = data;
1306 struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb);
1307 int mntflags = sb_mntdata->mntflags;
1309 if (memcmp(&old->nfs_client->cl_addr,
1310 &server->nfs_client->cl_addr,
1311 sizeof(old->nfs_client->cl_addr)) != 0)
1313 /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
1314 if (old->flags & NFS_MOUNT_UNSHARED)
1316 if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
1318 return nfs_compare_mount_options(sb, server, mntflags);
1321 static int nfs_get_sb(struct file_system_type *fs_type,
1322 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1324 struct nfs_server *server = NULL;
1325 struct super_block *s;
1326 struct nfs_fh mntfh;
1327 struct nfs_parsed_mount_data data;
1328 struct dentry *mntroot;
1329 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1330 struct nfs_sb_mountdata sb_mntdata = {
1335 /* Validate the mount data */
1336 error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name);
1340 /* Get a volume representation */
1341 server = nfs_create_server(&data, &mntfh);
1342 if (IS_ERR(server)) {
1343 error = PTR_ERR(server);
1346 sb_mntdata.server = server;
1348 if (server->flags & NFS_MOUNT_UNSHARED)
1349 compare_super = NULL;
1351 /* Get a superblock - note that we may end up sharing one that already exists */
1352 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1358 if (s->s_fs_info != server) {
1359 nfs_free_server(server);
1364 /* initial superblock/root creation */
1365 nfs_fill_super(s, &data);
1368 mntroot = nfs_get_root(s, &mntfh);
1369 if (IS_ERR(mntroot)) {
1370 error = PTR_ERR(mntroot);
1371 goto error_splat_super;
1374 s->s_flags |= MS_ACTIVE;
1376 mnt->mnt_root = mntroot;
1380 kfree(data.nfs_server.hostname);
1384 nfs_free_server(server);
1388 up_write(&s->s_umount);
1389 deactivate_super(s);
1394 * Destroy an NFS2/3 superblock
1396 static void nfs_kill_super(struct super_block *s)
1398 struct nfs_server *server = NFS_SB(s);
1401 nfs_free_server(server);
1405 * Clone an NFS2/3 server record on xdev traversal (FSID-change)
1407 static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1408 const char *dev_name, void *raw_data,
1409 struct vfsmount *mnt)
1411 struct nfs_clone_mount *data = raw_data;
1412 struct super_block *s;
1413 struct nfs_server *server;
1414 struct dentry *mntroot;
1415 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1416 struct nfs_sb_mountdata sb_mntdata = {
1421 dprintk("--> nfs_xdev_get_sb()\n");
1423 /* create a new volume representation */
1424 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1425 if (IS_ERR(server)) {
1426 error = PTR_ERR(server);
1427 goto out_err_noserver;
1429 sb_mntdata.server = server;
1431 if (server->flags & NFS_MOUNT_UNSHARED)
1432 compare_super = NULL;
1434 /* Get a superblock - note that we may end up sharing one that already exists */
1435 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1441 if (s->s_fs_info != server) {
1442 nfs_free_server(server);
1447 /* initial superblock/root creation */
1448 nfs_clone_super(s, data->sb);
1451 mntroot = nfs_get_root(s, data->fh);
1452 if (IS_ERR(mntroot)) {
1453 error = PTR_ERR(mntroot);
1454 goto error_splat_super;
1457 s->s_flags |= MS_ACTIVE;
1459 mnt->mnt_root = mntroot;
1461 dprintk("<-- nfs_xdev_get_sb() = 0\n");
1465 nfs_free_server(server);
1467 dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error);
1471 up_write(&s->s_umount);
1472 deactivate_super(s);
1473 dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error);
1477 #ifdef CONFIG_NFS_V4
1480 * Finish setting up a cloned NFS4 superblock
1482 static void nfs4_clone_super(struct super_block *sb,
1483 const struct super_block *old_sb)
1485 sb->s_blocksize_bits = old_sb->s_blocksize_bits;
1486 sb->s_blocksize = old_sb->s_blocksize;
1487 sb->s_maxbytes = old_sb->s_maxbytes;
1488 sb->s_time_gran = 1;
1489 sb->s_op = old_sb->s_op;
1490 nfs_initialise_sb(sb);
1494 * Set up an NFS4 superblock
1496 static void nfs4_fill_super(struct super_block *sb)
1498 sb->s_time_gran = 1;
1499 sb->s_op = &nfs4_sops;
1500 nfs_initialise_sb(sb);
1504 * Validate NFSv4 mount options
1506 static int nfs4_validate_mount_data(void *options,
1507 struct nfs_parsed_mount_data *args,
1508 const char *dev_name)
1510 struct nfs4_mount_data *data = (struct nfs4_mount_data *)options;
1516 memset(args, 0, sizeof(*args));
1517 args->rsize = NFS_MAX_FILE_IO_SIZE;
1518 args->wsize = NFS_MAX_FILE_IO_SIZE;
1522 args->acregmax = 60;
1523 args->acdirmin = 30;
1524 args->acdirmax = 60;
1525 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1527 switch (data->version) {
1529 if (data->host_addrlen != sizeof(args->nfs_server.address))
1530 goto out_no_address;
1531 if (copy_from_user(&args->nfs_server.address,
1533 sizeof(args->nfs_server.address)))
1535 if (args->nfs_server.address.sin_port == 0)
1536 args->nfs_server.address.sin_port = htons(NFS_PORT);
1537 if (!nfs_verify_server_address((struct sockaddr *)
1538 &args->nfs_server.address))
1539 goto out_no_address;
1541 switch (data->auth_flavourlen) {
1543 args->auth_flavors[0] = RPC_AUTH_UNIX;
1546 if (copy_from_user(&args->auth_flavors[0],
1547 data->auth_flavours,
1548 sizeof(args->auth_flavors[0])))
1552 goto out_inval_auth;
1555 c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN);
1558 args->nfs_server.hostname = c;
1560 c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN);
1563 args->nfs_server.export_path = c;
1564 dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c);
1566 c = strndup_user(data->client_addr.data, 16);
1569 args->client_address = c;
1572 * Translate to nfs_parsed_mount_data, which nfs4_fill_super
1576 args->flags = data->flags & NFS4_MOUNT_FLAGMASK;
1577 args->rsize = data->rsize;
1578 args->wsize = data->wsize;
1579 args->timeo = data->timeo;
1580 args->retrans = data->retrans;
1581 args->acregmin = data->acregmin;
1582 args->acregmax = data->acregmax;
1583 args->acdirmin = data->acdirmin;
1584 args->acdirmax = data->acdirmax;
1585 args->nfs_server.protocol = data->proto;
1591 if (nfs_parse_mount_options((char *)options, args) == 0)
1594 if (!nfs_verify_server_address((struct sockaddr *)
1595 &args->nfs_server.address))
1598 switch (args->auth_flavor_len) {
1600 args->auth_flavors[0] = RPC_AUTH_UNIX;
1605 goto out_inval_auth;
1609 * Split "dev_name" into "hostname:mntpath".
1611 c = strchr(dev_name, ':');
1614 /* while calculating len, pretend ':' is '\0' */
1616 if (len > NFS4_MAXNAMLEN)
1617 return -ENAMETOOLONG;
1618 args->nfs_server.hostname = kzalloc(len, GFP_KERNEL);
1619 if (args->nfs_server.hostname == NULL)
1621 strncpy(args->nfs_server.hostname, dev_name, len - 1);
1623 c++; /* step over the ':' */
1625 if (len > NFS4_MAXPATHLEN)
1626 return -ENAMETOOLONG;
1627 args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL);
1628 if (args->nfs_server.export_path == NULL)
1630 strncpy(args->nfs_server.export_path, c, len);
1632 dprintk("MNTPATH: %s\n", args->nfs_server.export_path);
1634 if (args->client_address == NULL)
1635 goto out_no_client_address;
1644 dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n");
1648 dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n",
1649 data->auth_flavourlen);
1653 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1656 out_no_client_address:
1657 dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n");
1662 * Get the superblock for an NFS4 mountpoint
1664 static int nfs4_get_sb(struct file_system_type *fs_type,
1665 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1667 struct nfs_parsed_mount_data data;
1668 struct super_block *s;
1669 struct nfs_server *server;
1670 struct nfs_fh mntfh;
1671 struct dentry *mntroot;
1672 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1673 struct nfs_sb_mountdata sb_mntdata = {
1678 /* Validate the mount data */
1679 error = nfs4_validate_mount_data(raw_data, &data, dev_name);
1683 /* Get a volume representation */
1684 server = nfs4_create_server(&data, &mntfh);
1685 if (IS_ERR(server)) {
1686 error = PTR_ERR(server);
1689 sb_mntdata.server = server;
1691 if (server->flags & NFS4_MOUNT_UNSHARED)
1692 compare_super = NULL;
1694 /* Get a superblock - note that we may end up sharing one that already exists */
1695 s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata);
1701 if (s->s_fs_info != server) {
1702 nfs_free_server(server);
1707 /* initial superblock/root creation */
1711 mntroot = nfs4_get_root(s, &mntfh);
1712 if (IS_ERR(mntroot)) {
1713 error = PTR_ERR(mntroot);
1714 goto error_splat_super;
1717 s->s_flags |= MS_ACTIVE;
1719 mnt->mnt_root = mntroot;
1723 kfree(data.client_address);
1724 kfree(data.nfs_server.export_path);
1725 kfree(data.nfs_server.hostname);
1729 nfs_free_server(server);
1733 up_write(&s->s_umount);
1734 deactivate_super(s);
1738 static void nfs4_kill_super(struct super_block *sb)
1740 struct nfs_server *server = NFS_SB(sb);
1742 nfs_return_all_delegations(sb);
1743 kill_anon_super(sb);
1745 nfs4_renewd_prepare_shutdown(server);
1746 nfs_free_server(server);
1750 * Clone an NFS4 server record on xdev traversal (FSID-change)
1752 static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1753 const char *dev_name, void *raw_data,
1754 struct vfsmount *mnt)
1756 struct nfs_clone_mount *data = raw_data;
1757 struct super_block *s;
1758 struct nfs_server *server;
1759 struct dentry *mntroot;
1760 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1761 struct nfs_sb_mountdata sb_mntdata = {
1766 dprintk("--> nfs4_xdev_get_sb()\n");
1768 /* create a new volume representation */
1769 server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr);
1770 if (IS_ERR(server)) {
1771 error = PTR_ERR(server);
1772 goto out_err_noserver;
1774 sb_mntdata.server = server;
1776 if (server->flags & NFS4_MOUNT_UNSHARED)
1777 compare_super = NULL;
1779 /* Get a superblock - note that we may end up sharing one that already exists */
1780 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1786 if (s->s_fs_info != server) {
1787 nfs_free_server(server);
1792 /* initial superblock/root creation */
1793 nfs4_clone_super(s, data->sb);
1796 mntroot = nfs4_get_root(s, data->fh);
1797 if (IS_ERR(mntroot)) {
1798 error = PTR_ERR(mntroot);
1799 goto error_splat_super;
1802 s->s_flags |= MS_ACTIVE;
1804 mnt->mnt_root = mntroot;
1806 dprintk("<-- nfs4_xdev_get_sb() = 0\n");
1810 nfs_free_server(server);
1812 dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error);
1816 up_write(&s->s_umount);
1817 deactivate_super(s);
1818 dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error);
1823 * Create an NFS4 server record on referral traversal
1825 static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1826 const char *dev_name, void *raw_data,
1827 struct vfsmount *mnt)
1829 struct nfs_clone_mount *data = raw_data;
1830 struct super_block *s;
1831 struct nfs_server *server;
1832 struct dentry *mntroot;
1833 struct nfs_fh mntfh;
1834 int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
1835 struct nfs_sb_mountdata sb_mntdata = {
1840 dprintk("--> nfs4_referral_get_sb()\n");
1842 /* create a new volume representation */
1843 server = nfs4_create_referral_server(data, &mntfh);
1844 if (IS_ERR(server)) {
1845 error = PTR_ERR(server);
1846 goto out_err_noserver;
1848 sb_mntdata.server = server;
1850 if (server->flags & NFS4_MOUNT_UNSHARED)
1851 compare_super = NULL;
1853 /* Get a superblock - note that we may end up sharing one that already exists */
1854 s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata);
1860 if (s->s_fs_info != server) {
1861 nfs_free_server(server);
1866 /* initial superblock/root creation */
1870 mntroot = nfs4_get_root(s, &mntfh);
1871 if (IS_ERR(mntroot)) {
1872 error = PTR_ERR(mntroot);
1873 goto error_splat_super;
1876 s->s_flags |= MS_ACTIVE;
1878 mnt->mnt_root = mntroot;
1880 dprintk("<-- nfs4_referral_get_sb() = 0\n");
1884 nfs_free_server(server);
1886 dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
1890 up_write(&s->s_umount);
1891 deactivate_super(s);
1892 dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
1896 #endif /* CONFIG_NFS_V4 */