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