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