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