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