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