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