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