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