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