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