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