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