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/mnt_namespace.h> |
| 45 | #include <linux/namei.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 46 | #include <linux/nfs_idmap.h> |
| 47 | #include <linux/vfs.h> |
| 48 | #include <linux/inet.h> |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 49 | #include <linux/in6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 51 | #include <net/ipv6.h> |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 52 | #include <linux/netdevice.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 53 | #include <linux/nfs_xdr.h> |
Adrian Bunk | b5d5dfb | 2007-02-12 00:53:40 -0800 | [diff] [blame] | 54 | #include <linux/magic.h> |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 55 | #include <linux/parser.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 56 | |
| 57 | #include <asm/system.h> |
| 58 | #include <asm/uaccess.h> |
| 59 | |
| 60 | #include "nfs4_fs.h" |
| 61 | #include "callback.h" |
| 62 | #include "delegation.h" |
| 63 | #include "iostat.h" |
| 64 | #include "internal.h" |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 65 | #include "fscache.h" |
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 *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 265 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
Al Viro | c7f404b | 2011-03-16 06:59:40 -0400 | [diff] [blame] | 266 | static int nfs_show_devname(struct seq_file *, struct vfsmount *); |
| 267 | static int nfs_show_path(struct seq_file *, struct vfsmount *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 268 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
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 | */ |
| 723 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 724 | { |
| 725 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 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 | } |
| 735 | |
Al Viro | c7f404b | 2011-03-16 06:59:40 -0400 | [diff] [blame] | 736 | static int nfs_show_devname(struct seq_file *m, struct vfsmount *mnt) |
| 737 | { |
| 738 | char *page = (char *) __get_free_page(GFP_KERNEL); |
| 739 | char *devname, *dummy; |
| 740 | int err = 0; |
| 741 | if (!page) |
| 742 | return -ENOMEM; |
| 743 | devname = nfs_path(&dummy, mnt->mnt_root, page, PAGE_SIZE); |
| 744 | if (IS_ERR(devname)) |
| 745 | err = PTR_ERR(devname); |
| 746 | else |
| 747 | seq_escape(m, devname, " \t\n\\"); |
| 748 | free_page((unsigned long)page); |
| 749 | return err; |
| 750 | } |
| 751 | |
| 752 | static int nfs_show_path(struct seq_file *m, struct vfsmount *mnt) |
| 753 | { |
| 754 | seq_puts(m, "/"); |
| 755 | return 0; |
| 756 | } |
| 757 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 758 | /* |
| 759 | * Present statistical information for this VFS mountpoint |
| 760 | */ |
| 761 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 762 | { |
| 763 | int i, cpu; |
| 764 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 765 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 766 | struct nfs_iostats totals = { }; |
| 767 | |
| 768 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 769 | |
| 770 | /* |
| 771 | * Display all mount option settings |
| 772 | */ |
| 773 | seq_printf(m, "\n\topts:\t"); |
| 774 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 775 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 776 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 777 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 778 | nfs_show_mount_options(m, nfss, 1); |
| 779 | |
| 780 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 781 | |
| 782 | seq_printf(m, "\n\tcaps:\t"); |
| 783 | seq_printf(m, "caps=0x%x", nfss->caps); |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 784 | seq_printf(m, ",wtmult=%u", nfss->wtmult); |
| 785 | seq_printf(m, ",dtsize=%u", nfss->dtsize); |
| 786 | seq_printf(m, ",bsize=%u", nfss->bsize); |
| 787 | seq_printf(m, ",namlen=%u", nfss->namelen); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 788 | |
| 789 | #ifdef CONFIG_NFS_V4 |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 790 | if (nfss->nfs_client->rpc_ops->version == 4) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 791 | seq_printf(m, "\n\tnfsv4:\t"); |
| 792 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 793 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 794 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 795 | } |
| 796 | #endif |
| 797 | |
| 798 | /* |
| 799 | * Display security flavor in effect for this mount |
| 800 | */ |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 801 | seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 802 | if (auth->au_flavor) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 803 | seq_printf(m, ",pseudoflavor=%u", auth->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 804 | |
| 805 | /* |
| 806 | * Display superblock I/O counters |
| 807 | */ |
| 808 | for_each_possible_cpu(cpu) { |
| 809 | struct nfs_iostats *stats; |
| 810 | |
| 811 | preempt_disable(); |
| 812 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 813 | |
| 814 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 815 | totals.events[i] += stats->events[i]; |
| 816 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 817 | totals.bytes[i] += stats->bytes[i]; |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 818 | #ifdef CONFIG_NFS_FSCACHE |
| 819 | for (i = 0; i < __NFSIOS_FSCACHEMAX; i++) |
| 820 | totals.fscache[i] += stats->fscache[i]; |
| 821 | #endif |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 822 | |
| 823 | preempt_enable(); |
| 824 | } |
| 825 | |
| 826 | seq_printf(m, "\n\tevents:\t"); |
| 827 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 828 | seq_printf(m, "%lu ", totals.events[i]); |
| 829 | seq_printf(m, "\n\tbytes:\t"); |
| 830 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 831 | seq_printf(m, "%Lu ", totals.bytes[i]); |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 832 | #ifdef CONFIG_NFS_FSCACHE |
| 833 | if (nfss->options & NFS_OPTION_FSCACHE) { |
| 834 | seq_printf(m, "\n\tfsc:\t"); |
| 835 | for (i = 0; i < __NFSIOS_FSCACHEMAX; i++) |
| 836 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 837 | } |
| 838 | #endif |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 839 | seq_printf(m, "\n"); |
| 840 | |
| 841 | rpc_print_iostats(m, nfss->client); |
| 842 | |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | /* |
| 847 | * Begin unmount by attempting to remove all automounted mountpoints we added |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 848 | * in response to xdev traversals and referrals |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 849 | */ |
Al Viro | 42faad9 | 2008-04-24 07:21:56 -0400 | [diff] [blame] | 850 | static void nfs_umount_begin(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 851 | { |
Alessio Igor Bogani | 67e5520 | 2009-04-24 09:06:53 +0200 | [diff] [blame] | 852 | struct nfs_server *server; |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 853 | struct rpc_clnt *rpc; |
| 854 | |
Alessio Igor Bogani | 67e5520 | 2009-04-24 09:06:53 +0200 | [diff] [blame] | 855 | server = NFS_SB(sb); |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 856 | /* -EIO all pending I/O */ |
| 857 | rpc = server->client_acl; |
| 858 | if (!IS_ERR(rpc)) |
| 859 | rpc_killall_tasks(rpc); |
| 860 | rpc = server->client; |
| 861 | if (!IS_ERR(rpc)) |
| 862 | rpc_killall_tasks(rpc); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Trond Myklebust | c5811db | 2009-10-06 15:40:15 -0400 | [diff] [blame] | 865 | 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] | 866 | { |
| 867 | struct nfs_parsed_mount_data *data; |
| 868 | |
| 869 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 870 | if (data) { |
Chuck Lever | 9423a08 | 2009-09-23 14:36:38 -0400 | [diff] [blame] | 871 | data->acregmin = NFS_DEF_ACREGMIN; |
| 872 | data->acregmax = NFS_DEF_ACREGMAX; |
| 873 | data->acdirmin = NFS_DEF_ACDIRMIN; |
| 874 | data->acdirmax = NFS_DEF_ACDIRMAX; |
Trond Myklebust | c5811db | 2009-10-06 15:40:15 -0400 | [diff] [blame] | 875 | data->mount_server.port = NFS_UNSPEC_PORT; |
Chuck Lever | 9423a08 | 2009-09-23 14:36:38 -0400 | [diff] [blame] | 876 | data->nfs_server.port = NFS_UNSPEC_PORT; |
Trond Myklebust | c5811db | 2009-10-06 15:40:15 -0400 | [diff] [blame] | 877 | data->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | 9423a08 | 2009-09-23 14:36:38 -0400 | [diff] [blame] | 878 | data->auth_flavors[0] = RPC_AUTH_UNIX; |
| 879 | data->auth_flavor_len = 1; |
Trond Myklebust | c5811db | 2009-10-06 15:40:15 -0400 | [diff] [blame] | 880 | data->version = version; |
Chuck Lever | 9423a08 | 2009-09-23 14:36:38 -0400 | [diff] [blame] | 881 | data->minorversion = 0; |
| 882 | } |
| 883 | return data; |
| 884 | } |
| 885 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 886 | /* |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 887 | * Sanity-check a server address provided by the mount command. |
| 888 | * |
| 889 | * Address family must be initialized, and address must not be |
| 890 | * the ANY address for that family. |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 891 | */ |
| 892 | static int nfs_verify_server_address(struct sockaddr *addr) |
| 893 | { |
| 894 | switch (addr->sa_family) { |
| 895 | case AF_INET: { |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 896 | struct sockaddr_in *sa = (struct sockaddr_in *)addr; |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 897 | return sa->sin_addr.s_addr != htonl(INADDR_ANY); |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 898 | } |
| 899 | case AF_INET6: { |
| 900 | struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; |
| 901 | return !ipv6_addr_any(sa); |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 905 | dfprintk(MOUNT, "NFS: Invalid IP address specified\n"); |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 906 | return 0; |
| 907 | } |
| 908 | |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 909 | /* |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 910 | * Select between a default port value and a user-specified port value. |
| 911 | * If a zero value is set, then autobind will be used. |
| 912 | */ |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 913 | static void nfs_set_port(struct sockaddr *sap, int *port, |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 914 | const unsigned short default_port) |
| 915 | { |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 916 | if (*port == NFS_UNSPEC_PORT) |
| 917 | *port = default_port; |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 918 | |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 919 | rpc_set_port(sap, *port); |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 923 | * Sanity check the NFS transport protocol. |
| 924 | * |
| 925 | */ |
| 926 | static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt) |
| 927 | { |
| 928 | switch (mnt->nfs_server.protocol) { |
| 929 | case XPRT_TRANSPORT_UDP: |
| 930 | case XPRT_TRANSPORT_TCP: |
| 931 | case XPRT_TRANSPORT_RDMA: |
| 932 | break; |
| 933 | default: |
| 934 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * For text based NFSv2/v3 mounts, the mount protocol transport default |
| 940 | * settings should depend upon the specified NFS transport. |
| 941 | */ |
| 942 | static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt) |
| 943 | { |
| 944 | nfs_validate_transport_protocol(mnt); |
| 945 | |
| 946 | if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP || |
| 947 | mnt->mount_server.protocol == XPRT_TRANSPORT_TCP) |
| 948 | return; |
| 949 | switch (mnt->nfs_server.protocol) { |
| 950 | case XPRT_TRANSPORT_UDP: |
| 951 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
| 952 | break; |
| 953 | case XPRT_TRANSPORT_TCP: |
| 954 | case XPRT_TRANSPORT_RDMA: |
| 955 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /* |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 960 | * Parse the value of the 'sec=' option. |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 961 | */ |
| 962 | static int nfs_parse_security_flavors(char *value, |
| 963 | struct nfs_parsed_mount_data *mnt) |
| 964 | { |
| 965 | substring_t args[MAX_OPT_ARGS]; |
| 966 | |
| 967 | dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value); |
| 968 | |
| 969 | switch (match_token(value, nfs_secflavor_tokens, args)) { |
| 970 | case Opt_sec_none: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 971 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 972 | break; |
| 973 | case Opt_sec_sys: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 974 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 975 | break; |
| 976 | case Opt_sec_krb5: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 977 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 978 | break; |
| 979 | case Opt_sec_krb5i: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 980 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 981 | break; |
| 982 | case Opt_sec_krb5p: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 983 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 984 | break; |
| 985 | case Opt_sec_lkey: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 986 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 987 | break; |
| 988 | case Opt_sec_lkeyi: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 989 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 990 | break; |
| 991 | case Opt_sec_lkeyp: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 992 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 993 | break; |
| 994 | case Opt_sec_spkm: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 995 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 996 | break; |
| 997 | case Opt_sec_spkmi: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 998 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 999 | break; |
| 1000 | case Opt_sec_spkmp: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 1001 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 1002 | break; |
| 1003 | default: |
| 1004 | return 0; |
| 1005 | } |
| 1006 | |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 1007 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
Chuck Lever | 059f90b | 2009-08-09 15:09:31 -0400 | [diff] [blame] | 1008 | mnt->auth_flavor_len = 1; |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 1009 | return 1; |
| 1010 | } |
| 1011 | |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1012 | static int nfs_get_option_str(substring_t args[], char **option) |
| 1013 | { |
| 1014 | kfree(*option); |
| 1015 | *option = match_strdup(args); |
| 1016 | return !option; |
| 1017 | } |
| 1018 | |
| 1019 | static int nfs_get_option_ul(substring_t args[], unsigned long *option) |
| 1020 | { |
| 1021 | int rc; |
| 1022 | char *string; |
| 1023 | |
| 1024 | string = match_strdup(args); |
| 1025 | if (string == NULL) |
| 1026 | return -ENOMEM; |
| 1027 | rc = strict_strtoul(string, 10, option); |
| 1028 | kfree(string); |
| 1029 | |
| 1030 | return rc; |
| 1031 | } |
| 1032 | |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 1033 | /* |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1034 | * 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] | 1035 | * a data structure. The whole mount string is processed; bad options are |
| 1036 | * skipped as they are encountered. If there were no errors, return 1; |
| 1037 | * otherwise return 0 (zero). |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1038 | */ |
| 1039 | static int nfs_parse_mount_options(char *raw, |
| 1040 | struct nfs_parsed_mount_data *mnt) |
| 1041 | { |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1042 | char *p, *string, *secdata; |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1043 | int rc, sloppy = 0, invalid_option = 0; |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1044 | unsigned short protofamily = AF_UNSPEC; |
| 1045 | unsigned short mountfamily = AF_UNSPEC; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1046 | |
| 1047 | if (!raw) { |
| 1048 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 1049 | return 1; |
| 1050 | } |
| 1051 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 1052 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1053 | secdata = alloc_secdata(); |
| 1054 | if (!secdata) |
| 1055 | goto out_nomem; |
| 1056 | |
| 1057 | rc = security_sb_copy_data(raw, secdata); |
| 1058 | if (rc) |
| 1059 | goto out_security_failure; |
| 1060 | |
| 1061 | rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts); |
| 1062 | if (rc) |
| 1063 | goto out_security_failure; |
| 1064 | |
| 1065 | free_secdata(secdata); |
| 1066 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1067 | while ((p = strsep(&raw, ",")) != NULL) { |
| 1068 | substring_t args[MAX_OPT_ARGS]; |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1069 | unsigned long option; |
| 1070 | int token; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1071 | |
| 1072 | if (!*p) |
| 1073 | continue; |
| 1074 | |
| 1075 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 1076 | |
| 1077 | token = match_token(p, nfs_mount_option_tokens, args); |
| 1078 | switch (token) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1079 | |
| 1080 | /* |
| 1081 | * boolean options: foo/nofoo |
| 1082 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1083 | case Opt_soft: |
| 1084 | mnt->flags |= NFS_MOUNT_SOFT; |
| 1085 | break; |
| 1086 | case Opt_hard: |
| 1087 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 1088 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1089 | case Opt_posix: |
| 1090 | mnt->flags |= NFS_MOUNT_POSIX; |
| 1091 | break; |
| 1092 | case Opt_noposix: |
| 1093 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 1094 | break; |
| 1095 | case Opt_cto: |
| 1096 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 1097 | break; |
| 1098 | case Opt_nocto: |
| 1099 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 1100 | break; |
| 1101 | case Opt_ac: |
| 1102 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 1103 | break; |
| 1104 | case Opt_noac: |
| 1105 | mnt->flags |= NFS_MOUNT_NOAC; |
| 1106 | break; |
| 1107 | case Opt_lock: |
| 1108 | mnt->flags &= ~NFS_MOUNT_NONLM; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 1109 | mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | |
| 1110 | NFS_MOUNT_LOCAL_FCNTL); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1111 | break; |
| 1112 | case Opt_nolock: |
| 1113 | mnt->flags |= NFS_MOUNT_NONLM; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 1114 | mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | |
| 1115 | NFS_MOUNT_LOCAL_FCNTL); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1116 | break; |
| 1117 | case Opt_v2: |
| 1118 | mnt->flags &= ~NFS_MOUNT_VER3; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1119 | mnt->version = 2; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1120 | break; |
| 1121 | case Opt_v3: |
| 1122 | mnt->flags |= NFS_MOUNT_VER3; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1123 | mnt->version = 3; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1124 | break; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1125 | case Opt_v4: |
| 1126 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 1127 | mnt->version = 4; |
| 1128 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1129 | case Opt_udp: |
| 1130 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1131 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1132 | break; |
| 1133 | case Opt_tcp: |
| 1134 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1135 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1136 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1137 | case Opt_rdma: |
| 1138 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 1139 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Tom Talpey | a67d18f | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 1140 | xprt_load_transport(p); |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1141 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1142 | case Opt_acl: |
| 1143 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 1144 | break; |
| 1145 | case Opt_noacl: |
| 1146 | mnt->flags |= NFS_MOUNT_NOACL; |
| 1147 | break; |
| 1148 | case Opt_rdirplus: |
| 1149 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 1150 | break; |
| 1151 | case Opt_nordirplus: |
| 1152 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 1153 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1154 | case Opt_sharecache: |
| 1155 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 1156 | break; |
| 1157 | case Opt_nosharecache: |
| 1158 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 1159 | break; |
Chuck Lever | d740351 | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 1160 | case Opt_resvport: |
| 1161 | mnt->flags &= ~NFS_MOUNT_NORESVPORT; |
| 1162 | break; |
| 1163 | case Opt_noresvport: |
| 1164 | mnt->flags |= NFS_MOUNT_NORESVPORT; |
| 1165 | break; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 1166 | case Opt_fscache: |
| 1167 | mnt->options |= NFS_OPTION_FSCACHE; |
| 1168 | kfree(mnt->fscache_uniq); |
| 1169 | mnt->fscache_uniq = NULL; |
| 1170 | break; |
| 1171 | case Opt_nofscache: |
| 1172 | mnt->options &= ~NFS_OPTION_FSCACHE; |
| 1173 | kfree(mnt->fscache_uniq); |
| 1174 | mnt->fscache_uniq = NULL; |
| 1175 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1176 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1177 | /* |
| 1178 | * options that take numeric values |
| 1179 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1180 | case Opt_port: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1181 | if (nfs_get_option_ul(args, &option) || |
| 1182 | option > USHRT_MAX) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1183 | goto out_invalid_value; |
| 1184 | mnt->nfs_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1185 | break; |
| 1186 | case Opt_rsize: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1187 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1188 | goto out_invalid_value; |
| 1189 | mnt->rsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1190 | break; |
| 1191 | case Opt_wsize: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1192 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1193 | goto out_invalid_value; |
| 1194 | mnt->wsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1195 | break; |
| 1196 | case Opt_bsize: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1197 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1198 | goto out_invalid_value; |
| 1199 | mnt->bsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1200 | break; |
| 1201 | case Opt_timeo: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1202 | if (nfs_get_option_ul(args, &option) || option == 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1203 | goto out_invalid_value; |
| 1204 | mnt->timeo = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1205 | break; |
| 1206 | case Opt_retrans: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1207 | if (nfs_get_option_ul(args, &option) || option == 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1208 | goto out_invalid_value; |
| 1209 | mnt->retrans = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1210 | break; |
| 1211 | case Opt_acregmin: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1212 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1213 | goto out_invalid_value; |
| 1214 | mnt->acregmin = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1215 | break; |
| 1216 | case Opt_acregmax: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1217 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1218 | goto out_invalid_value; |
| 1219 | mnt->acregmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1220 | break; |
| 1221 | case Opt_acdirmin: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1222 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1223 | goto out_invalid_value; |
| 1224 | mnt->acdirmin = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1225 | break; |
| 1226 | case Opt_acdirmax: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1227 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1228 | goto out_invalid_value; |
| 1229 | mnt->acdirmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1230 | break; |
| 1231 | case Opt_actimeo: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1232 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1233 | goto out_invalid_value; |
| 1234 | mnt->acregmin = mnt->acregmax = |
| 1235 | mnt->acdirmin = mnt->acdirmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1236 | break; |
| 1237 | case Opt_namelen: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1238 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1239 | goto out_invalid_value; |
| 1240 | mnt->namlen = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1241 | break; |
| 1242 | case Opt_mountport: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1243 | if (nfs_get_option_ul(args, &option) || |
| 1244 | option > USHRT_MAX) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1245 | goto out_invalid_value; |
| 1246 | mnt->mount_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1247 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1248 | case Opt_mountvers: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1249 | if (nfs_get_option_ul(args, &option) || |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1250 | option < NFS_MNT_VERSION || |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1251 | option > NFS_MNT3_VERSION) |
| 1252 | goto out_invalid_value; |
| 1253 | mnt->mount_server.version = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1254 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1255 | case Opt_nfsvers: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1256 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1257 | goto out_invalid_value; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1258 | switch (option) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1259 | case NFS2_VERSION: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1260 | mnt->flags &= ~NFS_MOUNT_VER3; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1261 | mnt->version = 2; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1262 | break; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1263 | case NFS3_VERSION: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1264 | mnt->flags |= NFS_MOUNT_VER3; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1265 | mnt->version = 3; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1266 | break; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1267 | case NFS4_VERSION: |
| 1268 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 1269 | mnt->version = 4; |
| 1270 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1271 | default: |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1272 | goto out_invalid_value; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1273 | } |
| 1274 | break; |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1275 | case Opt_minorversion: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1276 | if (nfs_get_option_ul(args, &option)) |
Chuck Lever | f3f4f4e | 2009-08-09 15:09:29 -0400 | [diff] [blame] | 1277 | goto out_invalid_value; |
| 1278 | if (option > NFS4_MAX_MINOR_VERSION) |
| 1279 | goto out_invalid_value; |
| 1280 | mnt->minorversion = option; |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1281 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1282 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1283 | /* |
| 1284 | * options that take text values |
| 1285 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1286 | case Opt_sec: |
| 1287 | string = match_strdup(args); |
| 1288 | if (string == NULL) |
| 1289 | goto out_nomem; |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 1290 | rc = nfs_parse_security_flavors(string, mnt); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1291 | kfree(string); |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1292 | if (!rc) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1293 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1294 | "security flavor\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1295 | return 0; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1296 | } |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1297 | break; |
| 1298 | case Opt_proto: |
| 1299 | string = match_strdup(args); |
| 1300 | if (string == NULL) |
| 1301 | goto out_nomem; |
| 1302 | token = match_token(string, |
| 1303 | nfs_xprt_protocol_tokens, args); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1304 | |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1305 | protofamily = AF_INET; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1306 | switch (token) { |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1307 | case Opt_xprt_udp6: |
| 1308 | protofamily = AF_INET6; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1309 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1310 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1311 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1312 | break; |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1313 | case Opt_xprt_tcp6: |
| 1314 | protofamily = AF_INET6; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1315 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1316 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1317 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1318 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1319 | case Opt_xprt_rdma: |
| 1320 | /* vector side protocols to TCP */ |
| 1321 | mnt->flags |= NFS_MOUNT_TCP; |
| 1322 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Tom Talpey | a67d18f | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 1323 | xprt_load_transport(string); |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1324 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1325 | default: |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1326 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1327 | "transport protocol\n"); |
Yinghai Lu | 4223a4a | 2009-10-20 14:13:46 +0900 | [diff] [blame] | 1328 | kfree(string); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1329 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1330 | } |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1331 | kfree(string); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1332 | break; |
| 1333 | case Opt_mountproto: |
| 1334 | string = match_strdup(args); |
| 1335 | if (string == NULL) |
| 1336 | goto out_nomem; |
| 1337 | token = match_token(string, |
| 1338 | nfs_xprt_protocol_tokens, args); |
Trond Myklebust | d508afb | 2009-04-06 16:41:35 -0700 | [diff] [blame] | 1339 | kfree(string); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1340 | |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1341 | mountfamily = AF_INET; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1342 | switch (token) { |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1343 | case Opt_xprt_udp6: |
| 1344 | mountfamily = AF_INET6; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1345 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1346 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1347 | break; |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1348 | case Opt_xprt_tcp6: |
| 1349 | mountfamily = AF_INET6; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1350 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1351 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1352 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1353 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1354 | default: |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1355 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1356 | "transport protocol\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1357 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1358 | } |
| 1359 | break; |
| 1360 | case Opt_addr: |
| 1361 | string = match_strdup(args); |
| 1362 | if (string == NULL) |
| 1363 | goto out_nomem; |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1364 | mnt->nfs_server.addrlen = |
| 1365 | rpc_pton(string, strlen(string), |
| 1366 | (struct sockaddr *) |
| 1367 | &mnt->nfs_server.address, |
| 1368 | sizeof(mnt->nfs_server.address)); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1369 | kfree(string); |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1370 | if (mnt->nfs_server.addrlen == 0) |
| 1371 | goto out_invalid_address; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1372 | break; |
| 1373 | case Opt_clientaddr: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1374 | if (nfs_get_option_str(args, &mnt->client_address)) |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1375 | goto out_nomem; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1376 | break; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1377 | case Opt_mounthost: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1378 | if (nfs_get_option_str(args, |
| 1379 | &mnt->mount_server.hostname)) |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1380 | goto out_nomem; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1381 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 1382 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1383 | string = match_strdup(args); |
| 1384 | if (string == NULL) |
| 1385 | goto out_nomem; |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1386 | mnt->mount_server.addrlen = |
| 1387 | rpc_pton(string, strlen(string), |
| 1388 | (struct sockaddr *) |
| 1389 | &mnt->mount_server.address, |
| 1390 | sizeof(mnt->mount_server.address)); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1391 | kfree(string); |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1392 | if (mnt->mount_server.addrlen == 0) |
| 1393 | goto out_invalid_address; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1394 | break; |
Trond Myklebust | 7973c1f | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1395 | case Opt_lookupcache: |
| 1396 | string = match_strdup(args); |
| 1397 | if (string == NULL) |
| 1398 | goto out_nomem; |
| 1399 | token = match_token(string, |
| 1400 | nfs_lookupcache_tokens, args); |
| 1401 | kfree(string); |
| 1402 | switch (token) { |
| 1403 | case Opt_lookupcache_all: |
| 1404 | mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE); |
| 1405 | break; |
| 1406 | case Opt_lookupcache_positive: |
| 1407 | mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE; |
| 1408 | mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG; |
| 1409 | break; |
| 1410 | case Opt_lookupcache_none: |
| 1411 | mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE; |
| 1412 | break; |
| 1413 | default: |
Trond Myklebust | 7973c1f | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1414 | dfprintk(MOUNT, "NFS: invalid " |
| 1415 | "lookupcache argument\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1416 | return 0; |
Trond Myklebust | 7973c1f | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1417 | }; |
| 1418 | break; |
Chuck Lever | a6d5ff6 | 2010-05-07 13:33:58 -0400 | [diff] [blame] | 1419 | case Opt_fscache_uniq: |
Rob Landley | c5cb09b | 2011-03-09 16:02:37 -0600 | [diff] [blame] | 1420 | if (nfs_get_option_str(args, &mnt->fscache_uniq)) |
Chuck Lever | a6d5ff6 | 2010-05-07 13:33:58 -0400 | [diff] [blame] | 1421 | goto out_nomem; |
Chuck Lever | a6d5ff6 | 2010-05-07 13:33:58 -0400 | [diff] [blame] | 1422 | mnt->options |= NFS_OPTION_FSCACHE; |
| 1423 | break; |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 1424 | case Opt_local_lock: |
| 1425 | string = match_strdup(args); |
| 1426 | if (string == NULL) |
| 1427 | goto out_nomem; |
| 1428 | token = match_token(string, nfs_local_lock_tokens, |
| 1429 | args); |
| 1430 | kfree(string); |
| 1431 | switch (token) { |
| 1432 | case Opt_local_lock_all: |
| 1433 | mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | |
| 1434 | NFS_MOUNT_LOCAL_FCNTL); |
| 1435 | break; |
| 1436 | case Opt_local_lock_flock: |
| 1437 | mnt->flags |= NFS_MOUNT_LOCAL_FLOCK; |
| 1438 | break; |
| 1439 | case Opt_local_lock_posix: |
| 1440 | mnt->flags |= NFS_MOUNT_LOCAL_FCNTL; |
| 1441 | break; |
| 1442 | case Opt_local_lock_none: |
| 1443 | mnt->flags &= ~(NFS_MOUNT_LOCAL_FLOCK | |
| 1444 | NFS_MOUNT_LOCAL_FCNTL); |
| 1445 | break; |
| 1446 | default: |
| 1447 | dfprintk(MOUNT, "NFS: invalid " |
| 1448 | "local_lock argument\n"); |
| 1449 | return 0; |
| 1450 | }; |
| 1451 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1452 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1453 | /* |
| 1454 | * Special options |
| 1455 | */ |
| 1456 | case Opt_sloppy: |
| 1457 | sloppy = 1; |
| 1458 | dfprintk(MOUNT, "NFS: relaxing parsing rules\n"); |
| 1459 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1460 | case Opt_userspace: |
| 1461 | case Opt_deprecated: |
Chuck Lever | d33e4df | 2008-06-12 12:37:41 -0400 | [diff] [blame] | 1462 | dfprintk(MOUNT, "NFS: ignoring mount option " |
| 1463 | "'%s'\n", p); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1464 | break; |
| 1465 | |
| 1466 | default: |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1467 | invalid_option = 1; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1468 | dfprintk(MOUNT, "NFS: unrecognized mount option " |
| 1469 | "'%s'\n", p); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1473 | if (!sloppy && invalid_option) |
| 1474 | return 0; |
| 1475 | |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1476 | /* |
| 1477 | * verify that any proto=/mountproto= options match the address |
| 1478 | * familiies in the addr=/mountaddr= options. |
| 1479 | */ |
| 1480 | if (protofamily != AF_UNSPEC && |
| 1481 | protofamily != mnt->nfs_server.address.ss_family) |
| 1482 | goto out_proto_mismatch; |
| 1483 | |
| 1484 | if (mountfamily != AF_UNSPEC) { |
| 1485 | if (mnt->mount_server.addrlen) { |
| 1486 | if (mountfamily != mnt->mount_server.address.ss_family) |
| 1487 | goto out_mountproto_mismatch; |
| 1488 | } else { |
| 1489 | if (mountfamily != mnt->nfs_server.address.ss_family) |
| 1490 | goto out_mountproto_mismatch; |
| 1491 | } |
| 1492 | } |
| 1493 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1494 | return 1; |
| 1495 | |
Jeff Layton | ee671b0 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1496 | out_mountproto_mismatch: |
| 1497 | printk(KERN_INFO "NFS: mount server address does not match mountproto= " |
| 1498 | "option\n"); |
| 1499 | return 0; |
| 1500 | out_proto_mismatch: |
| 1501 | printk(KERN_INFO "NFS: server address does not match proto= option\n"); |
| 1502 | return 0; |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1503 | out_invalid_address: |
| 1504 | printk(KERN_INFO "NFS: bad IP address specified: %s\n", p); |
| 1505 | return 0; |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1506 | out_invalid_value: |
Chuck Lever | 53a0b9c | 2009-08-09 15:09:36 -0400 | [diff] [blame] | 1507 | printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1508 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1509 | out_nomem: |
| 1510 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| 1511 | return 0; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1512 | out_security_failure: |
| 1513 | free_secdata(secdata); |
| 1514 | printk(KERN_INFO "NFS: security options invalid: %d\n", rc); |
| 1515 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | /* |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1519 | * Match the requested auth flavors with the list returned by |
| 1520 | * the server. Returns zero and sets the mount's authentication |
| 1521 | * flavor on success; returns -EACCES if server does not support |
| 1522 | * the requested flavor. |
| 1523 | */ |
| 1524 | static int nfs_walk_authlist(struct nfs_parsed_mount_data *args, |
| 1525 | struct nfs_mount_request *request) |
| 1526 | { |
| 1527 | unsigned int i, j, server_authlist_len = *(request->auth_flav_len); |
| 1528 | |
| 1529 | /* |
Chuck Lever | 5eecfde | 2009-08-21 17:50:30 -0400 | [diff] [blame] | 1530 | * Certain releases of Linux's mountd return an empty |
| 1531 | * flavor list. To prevent behavioral regression with |
| 1532 | * these servers (ie. rejecting mounts that used to |
| 1533 | * succeed), revert to pre-2.6.32 behavior (no checking) |
| 1534 | * if the returned flavor list is empty. |
| 1535 | */ |
| 1536 | if (server_authlist_len == 0) |
| 1537 | return 0; |
| 1538 | |
| 1539 | /* |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1540 | * We avoid sophisticated negotiating here, as there are |
| 1541 | * plenty of cases where we can get it wrong, providing |
| 1542 | * either too little or too much security. |
| 1543 | * |
| 1544 | * RFC 2623, section 2.7 suggests we SHOULD prefer the |
| 1545 | * flavor listed first. However, some servers list |
| 1546 | * AUTH_NULL first. Our caller plants AUTH_SYS, the |
| 1547 | * preferred default, in args->auth_flavors[0] if user |
| 1548 | * didn't specify sec= mount option. |
| 1549 | */ |
| 1550 | for (i = 0; i < args->auth_flavor_len; i++) |
| 1551 | for (j = 0; j < server_authlist_len; j++) |
| 1552 | if (args->auth_flavors[i] == request->auth_flavs[j]) { |
| 1553 | dfprintk(MOUNT, "NFS: using auth flavor %d\n", |
| 1554 | request->auth_flavs[j]); |
| 1555 | args->auth_flavors[0] = request->auth_flavs[j]; |
| 1556 | return 0; |
| 1557 | } |
| 1558 | |
| 1559 | dfprintk(MOUNT, "NFS: server does not support requested auth flavor\n"); |
| 1560 | nfs_umount(request); |
| 1561 | return -EACCES; |
| 1562 | } |
| 1563 | |
| 1564 | /* |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1565 | * Use the remote server's MOUNT service to request the NFS file handle |
| 1566 | * corresponding to the provided path. |
| 1567 | */ |
| 1568 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 1569 | struct nfs_fh *root_fh) |
| 1570 | { |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1571 | rpc_authflavor_t server_authlist[NFS_MAX_SECFLAVORS]; |
| 1572 | unsigned int server_authlist_len = ARRAY_SIZE(server_authlist); |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1573 | struct nfs_mount_request request = { |
| 1574 | .sap = (struct sockaddr *) |
| 1575 | &args->mount_server.address, |
| 1576 | .dirpath = args->nfs_server.export_path, |
| 1577 | .protocol = args->mount_server.protocol, |
| 1578 | .fh = root_fh, |
Chuck Lever | 50a737f | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 1579 | .noresvport = args->flags & NFS_MOUNT_NORESVPORT, |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1580 | .auth_flav_len = &server_authlist_len, |
| 1581 | .auth_flavs = server_authlist, |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1582 | }; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1583 | int status; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1584 | |
| 1585 | if (args->mount_server.version == 0) { |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 1586 | switch (args->version) { |
| 1587 | default: |
| 1588 | args->mount_server.version = NFS_MNT3_VERSION; |
| 1589 | break; |
| 1590 | case 2: |
| 1591 | args->mount_server.version = NFS_MNT_VERSION; |
| 1592 | } |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1593 | } |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1594 | request.version = args->mount_server.version; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1595 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1596 | if (args->mount_server.hostname) |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1597 | request.hostname = args->mount_server.hostname; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1598 | else |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1599 | request.hostname = args->nfs_server.hostname; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1600 | |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1601 | /* |
| 1602 | * Construct the mount server's address. |
| 1603 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1604 | if (args->mount_server.address.ss_family == AF_UNSPEC) { |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1605 | memcpy(request.sap, &args->nfs_server.address, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1606 | args->nfs_server.addrlen); |
| 1607 | args->mount_server.addrlen = args->nfs_server.addrlen; |
| 1608 | } |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1609 | request.salen = args->mount_server.addrlen; |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 1610 | nfs_set_port(request.sap, &args->mount_server.port, 0); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1611 | |
| 1612 | /* |
| 1613 | * Now ask the mount server to map our export path |
| 1614 | * to a file handle. |
| 1615 | */ |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1616 | status = nfs_mount(&request); |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1617 | if (status != 0) { |
| 1618 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", |
| 1619 | request.hostname, status); |
| 1620 | return status; |
| 1621 | } |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1622 | |
Chuck Lever | ec88f28 | 2009-08-09 15:09:32 -0400 | [diff] [blame] | 1623 | /* |
| 1624 | * MNTv1 (NFSv2) does not support auth flavor negotiation. |
| 1625 | */ |
| 1626 | if (args->mount_server.version != NFS_MNT3_VERSION) |
| 1627 | return 0; |
| 1628 | return nfs_walk_authlist(args, &request); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1629 | } |
| 1630 | |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1631 | /* |
| 1632 | * Split "dev_name" into "hostname:export_path". |
| 1633 | * |
| 1634 | * The leftmost colon demarks the split between the server's hostname |
| 1635 | * and the export path. If the hostname starts with a left square |
| 1636 | * bracket, then it may contain colons. |
| 1637 | * |
| 1638 | * Note: caller frees hostname and export path, even on error. |
| 1639 | */ |
| 1640 | static int nfs_parse_devname(const char *dev_name, |
| 1641 | char **hostname, size_t maxnamlen, |
| 1642 | char **export_path, size_t maxpathlen) |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1643 | { |
| 1644 | size_t len; |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1645 | char *end; |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1646 | |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1647 | /* Is the host name protected with square brakcets? */ |
| 1648 | if (*dev_name == '[') { |
| 1649 | end = strchr(++dev_name, ']'); |
| 1650 | if (end == NULL || end[1] != ':') |
| 1651 | goto out_bad_devname; |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1652 | |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1653 | len = end - dev_name; |
| 1654 | end++; |
| 1655 | } else { |
| 1656 | char *comma; |
| 1657 | |
| 1658 | end = strchr(dev_name, ':'); |
| 1659 | if (end == NULL) |
| 1660 | goto out_bad_devname; |
| 1661 | len = end - dev_name; |
| 1662 | |
| 1663 | /* kill possible hostname list: not supported */ |
| 1664 | comma = strchr(dev_name, ','); |
| 1665 | if (comma != NULL && comma < end) |
| 1666 | *comma = 0; |
| 1667 | } |
| 1668 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1669 | if (len > maxnamlen) |
| 1670 | goto out_hostname; |
| 1671 | |
| 1672 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1673 | *hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1674 | if (*hostname == NULL) |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1675 | goto out_nomem; |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1676 | len = strlen(++end); |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1677 | if (len > maxpathlen) |
| 1678 | goto out_path; |
Rob Landley | c12bace | 2011-03-09 15:54:13 -0600 | [diff] [blame] | 1679 | *export_path = kstrndup(end, len, GFP_KERNEL); |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1680 | if (!*export_path) |
| 1681 | goto out_nomem; |
| 1682 | |
| 1683 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path); |
| 1684 | return 0; |
| 1685 | |
| 1686 | out_bad_devname: |
| 1687 | dfprintk(MOUNT, "NFS: device name not in host:path format\n"); |
| 1688 | return -EINVAL; |
| 1689 | |
| 1690 | out_nomem: |
| 1691 | dfprintk(MOUNT, "NFS: not enough memory to parse device name\n"); |
| 1692 | return -ENOMEM; |
| 1693 | |
| 1694 | out_hostname: |
| 1695 | dfprintk(MOUNT, "NFS: server hostname too long\n"); |
| 1696 | return -ENAMETOOLONG; |
| 1697 | |
| 1698 | out_path: |
| 1699 | dfprintk(MOUNT, "NFS: export pathname too long\n"); |
| 1700 | return -ENAMETOOLONG; |
| 1701 | } |
| 1702 | |
| 1703 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1704 | * Validate the NFS2/NFS3 mount data |
| 1705 | * - fills in the mount root filehandle |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1706 | * |
| 1707 | * For option strings, user space handles the following behaviors: |
| 1708 | * |
| 1709 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 1710 | * |
| 1711 | * + failure mode: how to behave if a mount request can't be handled |
| 1712 | * immediately ("fg/bg" option) |
| 1713 | * |
| 1714 | * + retry: how often to retry a mount request ("retry=" option) |
| 1715 | * |
| 1716 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 1717 | * mountproto=tcp after mountproto=udp, and so on |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1718 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1719 | static int nfs_validate_mount_data(void *options, |
| 1720 | struct nfs_parsed_mount_data *args, |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1721 | struct nfs_fh *mntfh, |
| 1722 | const char *dev_name) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1723 | { |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1724 | struct nfs_mount_data *data = (struct nfs_mount_data *)options; |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 1725 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1726 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1727 | if (data == NULL) |
| 1728 | goto out_no_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1729 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1730 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1731 | case 1: |
| 1732 | data->namlen = 0; |
| 1733 | case 2: |
| 1734 | data->bsize = 0; |
| 1735 | case 3: |
| 1736 | if (data->flags & NFS_MOUNT_VER3) |
| 1737 | goto out_no_v3; |
| 1738 | data->root.size = NFS2_FHSIZE; |
| 1739 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1740 | case 4: |
| 1741 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1742 | goto out_no_sec; |
| 1743 | case 5: |
| 1744 | memset(data->context, 0, sizeof(data->context)); |
| 1745 | case 6: |
Trond Myklebust | b7e2445 | 2008-06-19 15:21:11 -0400 | [diff] [blame] | 1746 | if (data->flags & NFS_MOUNT_VER3) { |
| 1747 | if (data->root.size > NFS3_FHSIZE || data->root.size == 0) |
| 1748 | goto out_invalid_fh; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1749 | mntfh->size = data->root.size; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1750 | args->version = 3; |
| 1751 | } else { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1752 | mntfh->size = NFS2_FHSIZE; |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1753 | args->version = 2; |
| 1754 | } |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1755 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1756 | |
| 1757 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1758 | if (mntfh->size < sizeof(mntfh->data)) |
| 1759 | memset(mntfh->data + mntfh->size, 0, |
| 1760 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1761 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1762 | /* |
| 1763 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1764 | * can deal with. |
| 1765 | */ |
Trond Myklebust | ff3525a | 2008-08-15 16:59:14 -0400 | [diff] [blame] | 1766 | args->flags = data->flags & NFS_MOUNT_FLAGMASK; |
Bryan Schumaker | d5eff1a | 2010-08-03 13:04:00 -0400 | [diff] [blame] | 1767 | args->flags |= NFS_MOUNT_LEGACY_INTERFACE; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1768 | args->rsize = data->rsize; |
| 1769 | args->wsize = data->wsize; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1770 | args->timeo = data->timeo; |
| 1771 | args->retrans = data->retrans; |
| 1772 | args->acregmin = data->acregmin; |
| 1773 | args->acregmax = data->acregmax; |
| 1774 | args->acdirmin = data->acdirmin; |
| 1775 | args->acdirmax = data->acdirmax; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1776 | |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 1777 | memcpy(sap, &data->addr, sizeof(data->addr)); |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1778 | args->nfs_server.addrlen = sizeof(data->addr); |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 1779 | if (!nfs_verify_server_address(sap)) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1780 | goto out_no_address; |
| 1781 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1782 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1783 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1784 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1785 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1786 | args->namlen = data->namlen; |
| 1787 | args->bsize = data->bsize; |
Chuck Lever | dd07c94 | 2008-06-24 16:33:46 -0400 | [diff] [blame] | 1788 | |
| 1789 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1790 | args->auth_flavors[0] = data->pseudoflavor; |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1791 | if (!args->nfs_server.hostname) |
| 1792 | goto out_nomem; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1793 | |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 1794 | if (!(data->flags & NFS_MOUNT_NONLM)) |
| 1795 | args->flags &= ~(NFS_MOUNT_LOCAL_FLOCK| |
| 1796 | NFS_MOUNT_LOCAL_FCNTL); |
| 1797 | else |
| 1798 | args->flags |= (NFS_MOUNT_LOCAL_FLOCK| |
| 1799 | NFS_MOUNT_LOCAL_FCNTL); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1800 | /* |
| 1801 | * The legacy version 6 binary mount data from userspace has a |
| 1802 | * field used only to transport selinux information into the |
| 1803 | * the kernel. To continue to support that functionality we |
| 1804 | * have a touch of selinux knowledge here in the NFS code. The |
| 1805 | * userspace code converted context=blah to just blah so we are |
| 1806 | * converting back to the full string selinux understands. |
| 1807 | */ |
| 1808 | if (data->context[0]){ |
| 1809 | #ifdef CONFIG_SECURITY_SELINUX |
| 1810 | int rc; |
| 1811 | char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL); |
| 1812 | if (!opts_str) |
| 1813 | return -ENOMEM; |
| 1814 | strcpy(opts_str, "context="); |
| 1815 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
| 1816 | strcat(opts_str, &data->context[0]); |
| 1817 | rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts); |
| 1818 | kfree(opts_str); |
| 1819 | if (rc) |
| 1820 | return rc; |
| 1821 | #else |
| 1822 | return -EINVAL; |
| 1823 | #endif |
| 1824 | } |
| 1825 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1826 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1827 | default: { |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1828 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1829 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1830 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1831 | return -EINVAL; |
| 1832 | |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 1833 | if (!nfs_verify_server_address(sap)) |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1834 | goto out_no_address; |
| 1835 | |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1836 | if (args->version == 4) |
| 1837 | #ifdef CONFIG_NFS_V4 |
| 1838 | return nfs4_validate_text_mount_data(options, |
| 1839 | args, dev_name); |
| 1840 | #else |
| 1841 | goto out_v4_not_compiled; |
| 1842 | #endif |
| 1843 | |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 1844 | nfs_set_port(sap, &args->nfs_server.port, 0); |
Chuck Lever | ed596a8 | 2008-06-26 17:47:05 -0400 | [diff] [blame] | 1845 | |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 1846 | nfs_set_mount_transport_protocol(args); |
| 1847 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1848 | status = nfs_parse_devname(dev_name, |
| 1849 | &args->nfs_server.hostname, |
| 1850 | PAGE_SIZE, |
| 1851 | &args->nfs_server.export_path, |
| 1852 | NFS_MAXPATHLEN); |
| 1853 | if (!status) |
| 1854 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1855 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1856 | kfree(args->nfs_server.export_path); |
| 1857 | args->nfs_server.export_path = NULL; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1858 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1859 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1860 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1861 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1862 | break; |
| 1863 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1864 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1865 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1866 | #ifndef CONFIG_NFS_V3 |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 1867 | if (args->version == 3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1868 | goto out_v3_not_compiled; |
| 1869 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1870 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1871 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1872 | |
| 1873 | out_no_data: |
| 1874 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1875 | return -EINVAL; |
| 1876 | |
| 1877 | out_no_v3: |
| 1878 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1879 | data->version); |
| 1880 | return -EINVAL; |
| 1881 | |
| 1882 | out_no_sec: |
| 1883 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1884 | return -EINVAL; |
| 1885 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1886 | #ifndef CONFIG_NFS_V3 |
| 1887 | out_v3_not_compiled: |
| 1888 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1889 | return -EPROTONOSUPPORT; |
| 1890 | #endif /* !CONFIG_NFS_V3 */ |
| 1891 | |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 1892 | #ifndef CONFIG_NFS_V4 |
| 1893 | out_v4_not_compiled: |
| 1894 | dfprintk(MOUNT, "NFS: NFSv4 is not compiled into kernel\n"); |
| 1895 | return -EPROTONOSUPPORT; |
| 1896 | #endif /* !CONFIG_NFS_V4 */ |
| 1897 | |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1898 | out_nomem: |
| 1899 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); |
| 1900 | return -ENOMEM; |
| 1901 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1902 | out_no_address: |
| 1903 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1904 | return -EINVAL; |
| 1905 | |
| 1906 | out_invalid_fh: |
| 1907 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1908 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1909 | } |
| 1910 | |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1911 | static int |
| 1912 | nfs_compare_remount_data(struct nfs_server *nfss, |
| 1913 | struct nfs_parsed_mount_data *data) |
| 1914 | { |
| 1915 | if (data->flags != nfss->flags || |
| 1916 | data->rsize != nfss->rsize || |
| 1917 | data->wsize != nfss->wsize || |
| 1918 | data->retrans != nfss->client->cl_timeout->to_retries || |
| 1919 | data->auth_flavors[0] != nfss->client->cl_auth->au_flavor || |
| 1920 | data->acregmin != nfss->acregmin / HZ || |
| 1921 | data->acregmax != nfss->acregmax / HZ || |
| 1922 | data->acdirmin != nfss->acdirmin / HZ || |
| 1923 | data->acdirmax != nfss->acdirmax / HZ || |
| 1924 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || |
Trond Myklebust | bcd2ea1 | 2009-10-06 15:41:22 -0400 | [diff] [blame] | 1925 | data->nfs_server.port != nfss->port || |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1926 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || |
Stefan Richter | a1be9ee | 2009-10-12 11:26:12 -0400 | [diff] [blame] | 1927 | !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address, |
| 1928 | (struct sockaddr *)&nfss->nfs_client->cl_addr)) |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1929 | return -EINVAL; |
| 1930 | |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | static int |
| 1935 | nfs_remount(struct super_block *sb, int *flags, char *raw_data) |
| 1936 | { |
| 1937 | int error; |
| 1938 | struct nfs_server *nfss = sb->s_fs_info; |
| 1939 | struct nfs_parsed_mount_data *data; |
| 1940 | struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data; |
| 1941 | struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data; |
Trond Myklebust | cd10072 | 2008-06-17 16:12:00 -0400 | [diff] [blame] | 1942 | u32 nfsvers = nfss->nfs_client->rpc_ops->version; |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1943 | |
| 1944 | /* |
| 1945 | * Userspace mount programs that send binary options generally send |
| 1946 | * them populated with default values. We have no way to know which |
| 1947 | * ones were explicitly specified. Fall back to legacy behavior and |
| 1948 | * just return success. |
| 1949 | */ |
Marc Zyngier | 31c9446 | 2008-07-17 13:21:55 +0200 | [diff] [blame] | 1950 | if ((nfsvers == 4 && (!options4 || options4->version == 1)) || |
| 1951 | (nfsvers <= 3 && (!options || (options->version >= 1 && |
| 1952 | options->version <= 6)))) |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1953 | return 0; |
| 1954 | |
| 1955 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 1956 | if (data == NULL) |
| 1957 | return -ENOMEM; |
| 1958 | |
| 1959 | /* fill out struct with values from existing mount */ |
| 1960 | data->flags = nfss->flags; |
| 1961 | data->rsize = nfss->rsize; |
| 1962 | data->wsize = nfss->wsize; |
| 1963 | data->retrans = nfss->client->cl_timeout->to_retries; |
| 1964 | data->auth_flavors[0] = nfss->client->cl_auth->au_flavor; |
| 1965 | data->acregmin = nfss->acregmin / HZ; |
| 1966 | data->acregmax = nfss->acregmax / HZ; |
| 1967 | data->acdirmin = nfss->acdirmin / HZ; |
| 1968 | data->acdirmax = nfss->acdirmax / HZ; |
| 1969 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; |
Trond Myklebust | bcd2ea1 | 2009-10-06 15:41:22 -0400 | [diff] [blame] | 1970 | data->nfs_server.port = nfss->port; |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1971 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; |
| 1972 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, |
| 1973 | data->nfs_server.addrlen); |
| 1974 | |
| 1975 | /* overwrite those values with any that were specified */ |
| 1976 | error = nfs_parse_mount_options((char *)options, data); |
| 1977 | if (error < 0) |
| 1978 | goto out; |
| 1979 | |
Jeff Layton | 26c4c17 | 2011-04-27 11:49:09 -0400 | [diff] [blame] | 1980 | /* |
| 1981 | * noac is a special case. It implies -o sync, but that's not |
| 1982 | * necessarily reflected in the mtab options. do_remount_sb |
| 1983 | * will clear MS_SYNCHRONOUS if -o sync wasn't specified in the |
| 1984 | * remount options, so we have to explicitly reset it. |
| 1985 | */ |
| 1986 | if (data->flags & NFS_MOUNT_NOAC) |
| 1987 | *flags |= MS_SYNCHRONOUS; |
| 1988 | |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1989 | /* compare new mount options with old ones */ |
| 1990 | error = nfs_compare_remount_data(nfss, data); |
| 1991 | out: |
| 1992 | kfree(data); |
| 1993 | return error; |
| 1994 | } |
| 1995 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1996 | /* |
| 1997 | * Initialise the common bits of the superblock |
| 1998 | */ |
| 1999 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 2000 | { |
| 2001 | struct nfs_server *server = NFS_SB(sb); |
| 2002 | |
| 2003 | sb->s_magic = NFS_SUPER_MAGIC; |
| 2004 | |
| 2005 | /* We probably want something more informative here */ |
| 2006 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 2007 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 2008 | |
| 2009 | if (sb->s_blocksize == 0) |
| 2010 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 2011 | &sb->s_blocksize_bits); |
| 2012 | |
| 2013 | if (server->flags & NFS_MOUNT_NOAC) |
| 2014 | sb->s_flags |= MS_SYNCHRONOUS; |
| 2015 | |
Jens Axboe | 32a88aa | 2009-09-16 15:02:33 +0200 | [diff] [blame] | 2016 | sb->s_bdi = &server->backing_dev_info; |
| 2017 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2018 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 2019 | } |
| 2020 | |
| 2021 | /* |
| 2022 | * Finish setting up an NFS2/3 superblock |
| 2023 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 2024 | static void nfs_fill_super(struct super_block *sb, |
| 2025 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2026 | { |
| 2027 | struct nfs_server *server = NFS_SB(sb); |
| 2028 | |
| 2029 | sb->s_blocksize_bits = 0; |
| 2030 | sb->s_blocksize = 0; |
| 2031 | if (data->bsize) |
| 2032 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 2033 | |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 2034 | if (server->nfs_client->rpc_ops->version == 3) { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2035 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 2036 | * so ourselves when necessary. |
| 2037 | */ |
| 2038 | sb->s_flags |= MS_POSIXACL; |
| 2039 | sb->s_time_gran = 1; |
| 2040 | } |
| 2041 | |
| 2042 | sb->s_op = &nfs_sops; |
| 2043 | nfs_initialise_sb(sb); |
| 2044 | } |
| 2045 | |
| 2046 | /* |
| 2047 | * Finish setting up a cloned NFS2/3 superblock |
| 2048 | */ |
| 2049 | static void nfs_clone_super(struct super_block *sb, |
| 2050 | const struct super_block *old_sb) |
| 2051 | { |
| 2052 | struct nfs_server *server = NFS_SB(sb); |
| 2053 | |
| 2054 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 2055 | sb->s_blocksize = old_sb->s_blocksize; |
| 2056 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 2057 | |
Trond Myklebust | 8a6e5de | 2009-09-23 14:36:37 -0400 | [diff] [blame] | 2058 | if (server->nfs_client->rpc_ops->version == 3) { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2059 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 2060 | * so ourselves when necessary. |
| 2061 | */ |
| 2062 | sb->s_flags |= MS_POSIXACL; |
| 2063 | sb->s_time_gran = 1; |
| 2064 | } |
| 2065 | |
| 2066 | sb->s_op = old_sb->s_op; |
| 2067 | nfs_initialise_sb(sb); |
| 2068 | } |
| 2069 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2070 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 2071 | { |
| 2072 | const struct nfs_server *a = s->s_fs_info; |
| 2073 | const struct rpc_clnt *clnt_a = a->client; |
| 2074 | const struct rpc_clnt *clnt_b = b->client; |
| 2075 | |
| 2076 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 2077 | goto Ebusy; |
| 2078 | if (a->nfs_client != b->nfs_client) |
| 2079 | goto Ebusy; |
| 2080 | if (a->flags != b->flags) |
| 2081 | goto Ebusy; |
| 2082 | if (a->wsize != b->wsize) |
| 2083 | goto Ebusy; |
| 2084 | if (a->rsize != b->rsize) |
| 2085 | goto Ebusy; |
| 2086 | if (a->acregmin != b->acregmin) |
| 2087 | goto Ebusy; |
| 2088 | if (a->acregmax != b->acregmax) |
| 2089 | goto Ebusy; |
| 2090 | if (a->acdirmin != b->acdirmin) |
| 2091 | goto Ebusy; |
| 2092 | if (a->acdirmax != b->acdirmax) |
| 2093 | goto Ebusy; |
| 2094 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 2095 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2096 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2097 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2098 | return 0; |
| 2099 | } |
| 2100 | |
| 2101 | struct nfs_sb_mountdata { |
| 2102 | struct nfs_server *server; |
| 2103 | int mntflags; |
| 2104 | }; |
| 2105 | |
| 2106 | static int nfs_set_super(struct super_block *s, void *data) |
| 2107 | { |
| 2108 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 2109 | struct nfs_server *server = sb_mntdata->server; |
| 2110 | int ret; |
| 2111 | |
| 2112 | s->s_flags = sb_mntdata->mntflags; |
| 2113 | s->s_fs_info = server; |
Al Viro | 8b244ff | 2010-12-18 11:29:39 -0500 | [diff] [blame] | 2114 | s->s_d_op = server->nfs_client->rpc_ops->dentry_ops; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2115 | ret = set_anon_super(s, server); |
| 2116 | if (ret == 0) |
| 2117 | server->s_dev = s->s_dev; |
| 2118 | return ret; |
| 2119 | } |
| 2120 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 2121 | static int nfs_compare_super_address(struct nfs_server *server1, |
| 2122 | struct nfs_server *server2) |
| 2123 | { |
| 2124 | struct sockaddr *sap1, *sap2; |
| 2125 | |
| 2126 | sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr; |
| 2127 | sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr; |
| 2128 | |
| 2129 | if (sap1->sa_family != sap2->sa_family) |
| 2130 | return 0; |
| 2131 | |
| 2132 | switch (sap1->sa_family) { |
| 2133 | case AF_INET: { |
| 2134 | struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1; |
| 2135 | struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2; |
| 2136 | if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) |
| 2137 | return 0; |
| 2138 | if (sin1->sin_port != sin2->sin_port) |
| 2139 | return 0; |
| 2140 | break; |
| 2141 | } |
| 2142 | case AF_INET6: { |
| 2143 | struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1; |
| 2144 | struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2; |
| 2145 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
| 2146 | return 0; |
| 2147 | if (sin1->sin6_port != sin2->sin6_port) |
| 2148 | return 0; |
| 2149 | break; |
| 2150 | } |
| 2151 | default: |
| 2152 | return 0; |
| 2153 | } |
| 2154 | |
| 2155 | return 1; |
| 2156 | } |
| 2157 | |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2158 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 2159 | { |
| 2160 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 2161 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 2162 | int mntflags = sb_mntdata->mntflags; |
| 2163 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 2164 | if (!nfs_compare_super_address(old, server)) |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2165 | return 0; |
| 2166 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 2167 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 2168 | return 0; |
| 2169 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 2170 | return 0; |
| 2171 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2172 | } |
| 2173 | |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2174 | static int nfs_bdi_register(struct nfs_server *server) |
| 2175 | { |
| 2176 | return bdi_register_dev(&server->backing_dev_info, server->s_dev); |
| 2177 | } |
| 2178 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2179 | static struct dentry *nfs_fs_mount(struct file_system_type *fs_type, |
| 2180 | int flags, const char *dev_name, void *raw_data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2181 | { |
| 2182 | struct nfs_server *server = NULL; |
| 2183 | struct super_block *s; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2184 | struct nfs_parsed_mount_data *data; |
| 2185 | struct nfs_fh *mntfh; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2186 | struct dentry *mntroot = ERR_PTR(-ENOMEM); |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2187 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2188 | struct nfs_sb_mountdata sb_mntdata = { |
| 2189 | .mntflags = flags, |
| 2190 | }; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2191 | int error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2192 | |
Paulius Zaleckas | 1e657bd | 2010-10-31 18:21:05 +0200 | [diff] [blame] | 2193 | data = nfs_alloc_parsed_mount_data(NFS_DEFAULT_VERSION); |
Trond Myklebust | b157b06 | 2010-04-19 19:05:48 -0400 | [diff] [blame] | 2194 | mntfh = nfs_alloc_fhandle(); |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2195 | if (data == NULL || mntfh == NULL) |
| 2196 | goto out_free_fh; |
| 2197 | |
| 2198 | security_init_mnt_opts(&data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2199 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2200 | /* Validate the mount data */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2201 | error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2202 | if (error < 0) { |
| 2203 | mntroot = ERR_PTR(error); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2204 | goto out; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2205 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2206 | |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 2207 | #ifdef CONFIG_NFS_V4 |
| 2208 | if (data->version == 4) { |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2209 | mntroot = nfs4_try_mount(flags, dev_name, data); |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 2210 | kfree(data->client_address); |
Xiaotian Feng | 9699eda | 2010-04-22 18:56:17 +0800 | [diff] [blame] | 2211 | kfree(data->nfs_server.export_path); |
Chuck Lever | 764302c | 2009-09-08 19:50:03 -0400 | [diff] [blame] | 2212 | goto out; |
| 2213 | } |
| 2214 | #endif /* CONFIG_NFS_V4 */ |
| 2215 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2216 | /* Get a volume representation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2217 | server = nfs_create_server(data, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2218 | if (IS_ERR(server)) { |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2219 | mntroot = ERR_CAST(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2220 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2221 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2222 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2223 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2224 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 2225 | compare_super = NULL; |
| 2226 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2227 | /* 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] | 2228 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2229 | if (IS_ERR(s)) { |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2230 | mntroot = ERR_CAST(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2231 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2232 | } |
| 2233 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2234 | if (s->s_fs_info != server) { |
| 2235 | nfs_free_server(server); |
| 2236 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2237 | } else { |
| 2238 | error = nfs_bdi_register(server); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2239 | if (error) { |
| 2240 | mntroot = ERR_PTR(error); |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2241 | goto error_splat_bdi; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2242 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2243 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2244 | |
| 2245 | if (!s->s_root) { |
| 2246 | /* initial superblock/root creation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2247 | nfs_fill_super(s, data); |
Jesper Juhl | 160bc16 | 2011-04-10 17:57:07 +0200 | [diff] [blame] | 2248 | nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2249 | } |
| 2250 | |
Al Viro | 0d5839a | 2011-03-16 05:27:27 -0400 | [diff] [blame] | 2251 | mntroot = nfs_get_root(s, mntfh, dev_name); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2252 | if (IS_ERR(mntroot)) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2253 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2254 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2255 | error = security_sb_set_mnt_opts(s, &data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2256 | if (error) |
| 2257 | goto error_splat_root; |
| 2258 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2259 | s->s_flags |= MS_ACTIVE; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2260 | |
| 2261 | out: |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2262 | kfree(data->nfs_server.hostname); |
| 2263 | kfree(data->mount_server.hostname); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2264 | kfree(data->fscache_uniq); |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2265 | security_free_mnt_opts(&data->lsm_opts); |
| 2266 | out_free_fh: |
Trond Myklebust | b157b06 | 2010-04-19 19:05:48 -0400 | [diff] [blame] | 2267 | nfs_free_fhandle(mntfh); |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2268 | kfree(data); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2269 | return mntroot; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2270 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2271 | out_err_nosb: |
| 2272 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2273 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2274 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2275 | error_splat_root: |
| 2276 | dput(mntroot); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2277 | mntroot = ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2278 | error_splat_super: |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2279 | if (server && !s->s_root) |
| 2280 | bdi_unregister(&server->backing_dev_info); |
| 2281 | error_splat_bdi: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2282 | deactivate_locked_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2283 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2284 | } |
| 2285 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2286 | /* |
Trond Myklebust | 387c149 | 2010-02-03 08:27:35 -0500 | [diff] [blame] | 2287 | * Ensure that we unregister the bdi before kill_anon_super |
| 2288 | * releases the device name |
| 2289 | */ |
| 2290 | static void nfs_put_super(struct super_block *s) |
| 2291 | { |
| 2292 | struct nfs_server *server = NFS_SB(s); |
| 2293 | |
| 2294 | bdi_unregister(&server->backing_dev_info); |
| 2295 | } |
| 2296 | |
| 2297 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2298 | * Destroy an NFS2/3 superblock |
| 2299 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2300 | static void nfs_kill_super(struct super_block *s) |
| 2301 | { |
| 2302 | struct nfs_server *server = NFS_SB(s); |
| 2303 | |
| 2304 | kill_anon_super(s); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2305 | nfs_fscache_release_super_cookie(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2306 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2307 | } |
| 2308 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2309 | /* |
| 2310 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 2311 | */ |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2312 | static struct dentry * |
| 2313 | nfs_xdev_mount(struct file_system_type *fs_type, int flags, |
| 2314 | const char *dev_name, void *raw_data) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2315 | { |
| 2316 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2317 | struct super_block *s; |
| 2318 | struct nfs_server *server; |
| 2319 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2320 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2321 | struct nfs_sb_mountdata sb_mntdata = { |
| 2322 | .mntflags = flags, |
| 2323 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2324 | int error; |
| 2325 | |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2326 | dprintk("--> nfs_xdev_mount()\n"); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2327 | |
| 2328 | /* create a new volume representation */ |
| 2329 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2330 | if (IS_ERR(server)) { |
| 2331 | error = PTR_ERR(server); |
| 2332 | goto out_err_noserver; |
| 2333 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2334 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2335 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2336 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 2337 | compare_super = NULL; |
| 2338 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2339 | /* 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] | 2340 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2341 | if (IS_ERR(s)) { |
| 2342 | error = PTR_ERR(s); |
| 2343 | goto out_err_nosb; |
| 2344 | } |
| 2345 | |
| 2346 | if (s->s_fs_info != server) { |
| 2347 | nfs_free_server(server); |
| 2348 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2349 | } else { |
| 2350 | error = nfs_bdi_register(server); |
| 2351 | if (error) |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2352 | goto error_splat_bdi; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | if (!s->s_root) { |
| 2356 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2357 | nfs_clone_super(s, data->sb); |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 2358 | nfs_fscache_get_super_cookie(s, NULL, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2359 | } |
| 2360 | |
Al Viro | 0d5839a | 2011-03-16 05:27:27 -0400 | [diff] [blame] | 2361 | mntroot = nfs_get_root(s, data->fh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2362 | if (IS_ERR(mntroot)) { |
| 2363 | error = PTR_ERR(mntroot); |
| 2364 | goto error_splat_super; |
| 2365 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2366 | 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] | 2367 | dput(mntroot); |
| 2368 | error = -ESTALE; |
| 2369 | goto error_splat_super; |
| 2370 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2371 | |
| 2372 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2373 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2374 | /* clone any lsm security options from the parent to the new sb */ |
| 2375 | security_sb_clone_mnt_opts(data->sb, s); |
| 2376 | |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2377 | dprintk("<-- nfs_xdev_mount() = 0\n"); |
| 2378 | return mntroot; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2379 | |
| 2380 | out_err_nosb: |
| 2381 | nfs_free_server(server); |
| 2382 | out_err_noserver: |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2383 | dprintk("<-- nfs_xdev_mount() = %d [error]\n", error); |
| 2384 | return ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2385 | |
| 2386 | error_splat_super: |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2387 | if (server && !s->s_root) |
| 2388 | bdi_unregister(&server->backing_dev_info); |
| 2389 | error_splat_bdi: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2390 | deactivate_locked_super(s); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2391 | dprintk("<-- nfs_xdev_mount() = %d [splat]\n", error); |
| 2392 | return ERR_PTR(error); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2396 | |
| 2397 | /* |
| 2398 | * Finish setting up a cloned NFS4 superblock |
| 2399 | */ |
| 2400 | static void nfs4_clone_super(struct super_block *sb, |
| 2401 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2402 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2403 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 2404 | sb->s_blocksize = old_sb->s_blocksize; |
| 2405 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 2406 | sb->s_time_gran = 1; |
| 2407 | sb->s_op = old_sb->s_op; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2408 | /* |
| 2409 | * The VFS shouldn't apply the umask to mode bits. We will do |
| 2410 | * so ourselves when necessary. |
| 2411 | */ |
| 2412 | sb->s_flags |= MS_POSIXACL; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 2413 | sb->s_xattr = old_sb->s_xattr; |
| 2414 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | /* |
| 2418 | * Set up an NFS4 superblock |
| 2419 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2420 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2421 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2422 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2423 | sb->s_op = &nfs4_sops; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2424 | /* |
| 2425 | * The VFS shouldn't apply the umask to mode bits. We will do |
| 2426 | * so ourselves when necessary. |
| 2427 | */ |
| 2428 | sb->s_flags |= MS_POSIXACL; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 2429 | sb->s_xattr = nfs4_xattr_handlers; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2430 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2431 | } |
| 2432 | |
Trond Myklebust | 01c3f05 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 2433 | static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args) |
| 2434 | { |
Suresh Jayaraman | 5eebde2 | 2010-09-23 08:55:58 -0400 | [diff] [blame] | 2435 | args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3| |
| 2436 | NFS_MOUNT_LOCAL_FLOCK|NFS_MOUNT_LOCAL_FCNTL); |
Trond Myklebust | 01c3f05 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Chuck Lever | 7630c85 | 2009-09-08 19:49:57 -0400 | [diff] [blame] | 2439 | static int nfs4_validate_text_mount_data(void *options, |
| 2440 | struct nfs_parsed_mount_data *args, |
| 2441 | const char *dev_name) |
| 2442 | { |
| 2443 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; |
| 2444 | |
Trond Myklebust | f5855fe | 2009-10-06 15:40:37 -0400 | [diff] [blame] | 2445 | nfs_set_port(sap, &args->nfs_server.port, NFS_PORT); |
Chuck Lever | 7630c85 | 2009-09-08 19:49:57 -0400 | [diff] [blame] | 2446 | |
| 2447 | nfs_validate_transport_protocol(args); |
| 2448 | |
| 2449 | nfs4_validate_mount_flags(args); |
| 2450 | |
Trond Myklebust | 2ecda72 | 2009-09-08 19:50:07 -0400 | [diff] [blame] | 2451 | if (args->version != 4) { |
| 2452 | dfprintk(MOUNT, |
| 2453 | "NFS4: Illegal mount version\n"); |
| 2454 | return -EINVAL; |
| 2455 | } |
| 2456 | |
Chuck Lever | 7630c85 | 2009-09-08 19:49:57 -0400 | [diff] [blame] | 2457 | if (args->auth_flavor_len > 1) { |
| 2458 | dfprintk(MOUNT, |
| 2459 | "NFS4: Too many RPC auth flavours specified\n"); |
| 2460 | return -EINVAL; |
| 2461 | } |
| 2462 | |
| 2463 | if (args->client_address == NULL) { |
| 2464 | dfprintk(MOUNT, |
| 2465 | "NFS4: mount program didn't pass callback address\n"); |
| 2466 | return -EINVAL; |
| 2467 | } |
| 2468 | |
| 2469 | return nfs_parse_devname(dev_name, |
| 2470 | &args->nfs_server.hostname, |
| 2471 | NFS4_MAXNAMLEN, |
| 2472 | &args->nfs_server.export_path, |
| 2473 | NFS4_MAXPATHLEN); |
| 2474 | } |
| 2475 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2476 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2477 | * Validate NFSv4 mount options |
| 2478 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2479 | static int nfs4_validate_mount_data(void *options, |
| 2480 | struct nfs_parsed_mount_data *args, |
| 2481 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2482 | { |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 2483 | struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2484 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2485 | char *c; |
| 2486 | |
| 2487 | if (data == NULL) |
| 2488 | goto out_no_data; |
| 2489 | |
| 2490 | switch (data->version) { |
| 2491 | case 1: |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 2492 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2493 | goto out_no_address; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 2494 | if (data->host_addrlen == 0) |
| 2495 | goto out_no_address; |
| 2496 | args->nfs_server.addrlen = data->host_addrlen; |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 2497 | if (copy_from_user(sap, data->host_addr, data->host_addrlen)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2498 | return -EFAULT; |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 2499 | if (!nfs_verify_server_address(sap)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2500 | goto out_no_address; |
| 2501 | |
Chuck Lever | 6738b25 | 2008-06-24 16:33:54 -0400 | [diff] [blame] | 2502 | if (data->auth_flavourlen) { |
| 2503 | if (data->auth_flavourlen > 1) |
| 2504 | goto out_inval_auth; |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 2505 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2506 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 2507 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2508 | return -EFAULT; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 2512 | if (IS_ERR(c)) |
| 2513 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2514 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2515 | |
| 2516 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 2517 | if (IS_ERR(c)) |
| 2518 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2519 | args->nfs_server.export_path = c; |
| 2520 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2521 | |
| 2522 | c = strndup_user(data->client_addr.data, 16); |
| 2523 | if (IS_ERR(c)) |
| 2524 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2525 | args->client_address = c; |
| 2526 | |
| 2527 | /* |
| 2528 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 2529 | * can deal with. |
| 2530 | */ |
| 2531 | |
| 2532 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 2533 | args->rsize = data->rsize; |
| 2534 | args->wsize = data->wsize; |
| 2535 | args->timeo = data->timeo; |
| 2536 | args->retrans = data->retrans; |
| 2537 | args->acregmin = data->acregmin; |
| 2538 | args->acregmax = data->acregmax; |
| 2539 | args->acdirmin = data->acdirmin; |
| 2540 | args->acdirmax = data->acdirmax; |
| 2541 | args->nfs_server.protocol = data->proto; |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 2542 | nfs_validate_transport_protocol(args); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2543 | |
| 2544 | break; |
Chuck Lever | 7630c85 | 2009-09-08 19:49:57 -0400 | [diff] [blame] | 2545 | default: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2546 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2547 | return -EINVAL; |
| 2548 | |
Chuck Lever | 4cfd74f | 2009-09-08 19:49:47 -0400 | [diff] [blame] | 2549 | if (!nfs_verify_server_address(sap)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2550 | return -EINVAL; |
Chuck Lever | ed596a8 | 2008-06-26 17:47:05 -0400 | [diff] [blame] | 2551 | |
Chuck Lever | 7630c85 | 2009-09-08 19:49:57 -0400 | [diff] [blame] | 2552 | return nfs4_validate_text_mount_data(options, args, dev_name); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | return 0; |
| 2556 | |
| 2557 | out_no_data: |
| 2558 | dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n"); |
| 2559 | return -EINVAL; |
| 2560 | |
| 2561 | out_inval_auth: |
| 2562 | dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n", |
| 2563 | data->auth_flavourlen); |
| 2564 | return -EINVAL; |
| 2565 | |
| 2566 | out_no_address: |
| 2567 | dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); |
| 2568 | return -EINVAL; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | /* |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2572 | * Get the superblock for the NFS4 root partition |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2573 | */ |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2574 | static struct dentry * |
| 2575 | nfs4_remote_mount(struct file_system_type *fs_type, int flags, |
| 2576 | const char *dev_name, void *raw_data) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2577 | { |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2578 | struct nfs_parsed_mount_data *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2579 | struct super_block *s; |
| 2580 | struct nfs_server *server; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2581 | struct nfs_fh *mntfh; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2582 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2583 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2584 | struct nfs_sb_mountdata sb_mntdata = { |
| 2585 | .mntflags = flags, |
| 2586 | }; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2587 | int error = -ENOMEM; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2588 | |
Trond Myklebust | b157b06 | 2010-04-19 19:05:48 -0400 | [diff] [blame] | 2589 | mntfh = nfs_alloc_fhandle(); |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2590 | if (data == NULL || mntfh == NULL) |
| 2591 | goto out_free_fh; |
| 2592 | |
| 2593 | security_init_mnt_opts(&data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2594 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2595 | /* Get a volume representation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2596 | server = nfs4_create_server(data, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2597 | if (IS_ERR(server)) { |
| 2598 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2599 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2600 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2601 | sb_mntdata.server = server; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2602 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2603 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2604 | compare_super = NULL; |
| 2605 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2606 | /* 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] | 2607 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2608 | if (IS_ERR(s)) { |
| 2609 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2610 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2611 | } |
| 2612 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 2613 | if (s->s_fs_info != server) { |
| 2614 | nfs_free_server(server); |
| 2615 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2616 | } else { |
| 2617 | error = nfs_bdi_register(server); |
| 2618 | if (error) |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2619 | goto error_splat_bdi; |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 2620 | } |
| 2621 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2622 | if (!s->s_root) { |
| 2623 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2624 | nfs4_fill_super(s); |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 2625 | nfs_fscache_get_super_cookie( |
| 2626 | s, data ? data->fscache_uniq : NULL, NULL); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2627 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2628 | |
Al Viro | 0d5839a | 2011-03-16 05:27:27 -0400 | [diff] [blame] | 2629 | mntroot = nfs4_get_root(s, mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2630 | if (IS_ERR(mntroot)) { |
| 2631 | error = PTR_ERR(mntroot); |
| 2632 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2633 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2634 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2635 | error = security_sb_set_mnt_opts(s, &data->lsm_opts); |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2636 | if (error) |
| 2637 | goto error_splat_root; |
| 2638 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2639 | s->s_flags |= MS_ACTIVE; |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2640 | |
| 2641 | security_free_mnt_opts(&data->lsm_opts); |
| 2642 | nfs_free_fhandle(mntfh); |
| 2643 | return mntroot; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2644 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2645 | out: |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2646 | security_free_mnt_opts(&data->lsm_opts); |
| 2647 | out_free_fh: |
Trond Myklebust | b157b06 | 2010-04-19 19:05:48 -0400 | [diff] [blame] | 2648 | nfs_free_fhandle(mntfh); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2649 | return ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2650 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2651 | out_free: |
| 2652 | nfs_free_server(server); |
| 2653 | goto out; |
| 2654 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2655 | error_splat_root: |
| 2656 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2657 | error_splat_super: |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2658 | if (server && !s->s_root) |
| 2659 | bdi_unregister(&server->backing_dev_info); |
| 2660 | error_splat_bdi: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2661 | deactivate_locked_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2662 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2663 | } |
| 2664 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2665 | static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type, |
| 2666 | int flags, void *data, const char *hostname) |
| 2667 | { |
| 2668 | struct vfsmount *root_mnt; |
| 2669 | char *root_devname; |
| 2670 | size_t len; |
| 2671 | |
| 2672 | len = strlen(hostname) + 3; |
| 2673 | root_devname = kmalloc(len, GFP_KERNEL); |
| 2674 | if (root_devname == NULL) |
| 2675 | return ERR_PTR(-ENOMEM); |
| 2676 | snprintf(root_devname, len, "%s:/", hostname); |
| 2677 | root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data); |
| 2678 | kfree(root_devname); |
| 2679 | return root_mnt; |
| 2680 | } |
| 2681 | |
Trond Myklebust | ce587e0 | 2010-04-16 16:22:52 -0400 | [diff] [blame] | 2682 | struct nfs_referral_count { |
| 2683 | struct list_head list; |
| 2684 | const struct task_struct *task; |
| 2685 | unsigned int referral_count; |
| 2686 | }; |
| 2687 | |
| 2688 | static LIST_HEAD(nfs_referral_count_list); |
| 2689 | static DEFINE_SPINLOCK(nfs_referral_count_list_lock); |
| 2690 | |
| 2691 | static struct nfs_referral_count *nfs_find_referral_count(void) |
| 2692 | { |
| 2693 | struct nfs_referral_count *p; |
| 2694 | |
| 2695 | list_for_each_entry(p, &nfs_referral_count_list, list) { |
| 2696 | if (p->task == current) |
| 2697 | return p; |
| 2698 | } |
| 2699 | return NULL; |
| 2700 | } |
| 2701 | |
| 2702 | #define NFS_MAX_NESTED_REFERRALS 2 |
| 2703 | |
| 2704 | static int nfs_referral_loop_protect(void) |
| 2705 | { |
| 2706 | struct nfs_referral_count *p, *new; |
| 2707 | int ret = -ENOMEM; |
| 2708 | |
| 2709 | new = kmalloc(sizeof(*new), GFP_KERNEL); |
| 2710 | if (!new) |
| 2711 | goto out; |
| 2712 | new->task = current; |
| 2713 | new->referral_count = 1; |
| 2714 | |
| 2715 | ret = 0; |
| 2716 | spin_lock(&nfs_referral_count_list_lock); |
| 2717 | p = nfs_find_referral_count(); |
| 2718 | if (p != NULL) { |
| 2719 | if (p->referral_count >= NFS_MAX_NESTED_REFERRALS) |
| 2720 | ret = -ELOOP; |
| 2721 | else |
| 2722 | p->referral_count++; |
| 2723 | } else { |
| 2724 | list_add(&new->list, &nfs_referral_count_list); |
| 2725 | new = NULL; |
| 2726 | } |
| 2727 | spin_unlock(&nfs_referral_count_list_lock); |
| 2728 | kfree(new); |
| 2729 | out: |
| 2730 | return ret; |
| 2731 | } |
| 2732 | |
| 2733 | static void nfs_referral_loop_unprotect(void) |
| 2734 | { |
| 2735 | struct nfs_referral_count *p; |
| 2736 | |
| 2737 | spin_lock(&nfs_referral_count_list_lock); |
| 2738 | p = nfs_find_referral_count(); |
| 2739 | p->referral_count--; |
| 2740 | if (p->referral_count == 0) |
| 2741 | list_del(&p->list); |
| 2742 | else |
| 2743 | p = NULL; |
| 2744 | spin_unlock(&nfs_referral_count_list_lock); |
| 2745 | kfree(p); |
| 2746 | } |
| 2747 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2748 | static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt, |
| 2749 | const char *export_path) |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2750 | { |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2751 | struct nameidata *nd = NULL; |
Linus Torvalds | a2770d8 | 2009-12-17 12:51:05 -0800 | [diff] [blame] | 2752 | struct mnt_namespace *ns_private; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2753 | struct super_block *s; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2754 | struct dentry *dentry; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2755 | int ret; |
| 2756 | |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2757 | nd = kmalloc(sizeof(*nd), GFP_KERNEL); |
| 2758 | if (nd == NULL) |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2759 | return ERR_PTR(-ENOMEM); |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2760 | |
Linus Torvalds | a2770d8 | 2009-12-17 12:51:05 -0800 | [diff] [blame] | 2761 | ns_private = create_mnt_ns(root_mnt); |
| 2762 | ret = PTR_ERR(ns_private); |
| 2763 | if (IS_ERR(ns_private)) |
| 2764 | goto out_mntput; |
| 2765 | |
Trond Myklebust | ce587e0 | 2010-04-16 16:22:52 -0400 | [diff] [blame] | 2766 | ret = nfs_referral_loop_protect(); |
| 2767 | if (ret != 0) |
| 2768 | goto out_put_mnt_ns; |
| 2769 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2770 | ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2771 | export_path, LOOKUP_FOLLOW, nd); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2772 | |
Trond Myklebust | ce587e0 | 2010-04-16 16:22:52 -0400 | [diff] [blame] | 2773 | nfs_referral_loop_unprotect(); |
Linus Torvalds | a2770d8 | 2009-12-17 12:51:05 -0800 | [diff] [blame] | 2774 | put_mnt_ns(ns_private); |
| 2775 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2776 | if (ret != 0) |
| 2777 | goto out_err; |
| 2778 | |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2779 | s = nd->path.mnt->mnt_sb; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2780 | atomic_inc(&s->s_active); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2781 | dentry = dget(nd->path.dentry); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2782 | |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2783 | path_put(&nd->path); |
| 2784 | kfree(nd); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2785 | down_write(&s->s_umount); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2786 | return dentry; |
Trond Myklebust | ce587e0 | 2010-04-16 16:22:52 -0400 | [diff] [blame] | 2787 | out_put_mnt_ns: |
| 2788 | put_mnt_ns(ns_private); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2789 | out_mntput: |
| 2790 | mntput(root_mnt); |
| 2791 | out_err: |
Trond Myklebust | 04ffdbe | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2792 | kfree(nd); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2793 | return ERR_PTR(ret); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2796 | static struct dentry *nfs4_try_mount(int flags, const char *dev_name, |
| 2797 | struct nfs_parsed_mount_data *data) |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2798 | { |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2799 | char *export_path; |
| 2800 | struct vfsmount *root_mnt; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2801 | struct dentry *res; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2802 | |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2803 | dfprintk(MOUNT, "--> nfs4_try_mount()\n"); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2804 | |
| 2805 | export_path = data->nfs_server.export_path; |
| 2806 | data->nfs_server.export_path = "/"; |
| 2807 | root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data, |
| 2808 | data->nfs_server.hostname); |
| 2809 | data->nfs_server.export_path = export_path; |
| 2810 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2811 | res = ERR_CAST(root_mnt); |
| 2812 | if (!IS_ERR(root_mnt)) |
| 2813 | res = nfs_follow_remote_path(root_mnt, export_path); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2814 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2815 | dfprintk(MOUNT, "<-- nfs4_try_mount() = %ld%s\n", |
| 2816 | IS_ERR(res) ? PTR_ERR(res) : 0, |
| 2817 | IS_ERR(res) ? " [error]" : ""); |
| 2818 | return res; |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | /* |
| 2822 | * Get the superblock for an NFS4 mountpoint |
| 2823 | */ |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2824 | static struct dentry *nfs4_mount(struct file_system_type *fs_type, |
| 2825 | int flags, const char *dev_name, void *raw_data) |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2826 | { |
| 2827 | struct nfs_parsed_mount_data *data; |
| 2828 | int error = -ENOMEM; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2829 | struct dentry *res = ERR_PTR(-ENOMEM); |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2830 | |
Trond Myklebust | c5811db | 2009-10-06 15:40:15 -0400 | [diff] [blame] | 2831 | data = nfs_alloc_parsed_mount_data(4); |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2832 | if (data == NULL) |
| 2833 | goto out_free_data; |
| 2834 | |
| 2835 | /* Validate the mount data */ |
| 2836 | error = nfs4_validate_mount_data(raw_data, data, dev_name); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2837 | if (error < 0) { |
| 2838 | res = ERR_PTR(error); |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2839 | goto out; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2840 | } |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2841 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2842 | res = nfs4_try_mount(flags, dev_name, data); |
| 2843 | if (IS_ERR(res)) |
| 2844 | error = PTR_ERR(res); |
Chuck Lever | a6fe23b | 2009-09-08 19:50:00 -0400 | [diff] [blame] | 2845 | |
| 2846 | out: |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2847 | kfree(data->client_address); |
| 2848 | kfree(data->nfs_server.export_path); |
| 2849 | kfree(data->nfs_server.hostname); |
| 2850 | kfree(data->fscache_uniq); |
| 2851 | out_free_data: |
| 2852 | kfree(data); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2853 | dprintk("<-- nfs4_mount() = %d%s\n", error, |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2854 | error != 0 ? " [error]" : ""); |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 2855 | return res; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2856 | } |
| 2857 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2858 | static void nfs4_kill_super(struct super_block *sb) |
| 2859 | { |
| 2860 | struct nfs_server *server = NFS_SB(sb); |
| 2861 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 2862 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2863 | nfs_super_return_all_delegations(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2864 | kill_anon_super(sb); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2865 | nfs_fscache_release_super_cookie(sb); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2866 | nfs_free_server(server); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 2867 | dprintk("<-- %s\n", __func__); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2871 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2872 | */ |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2873 | static struct dentry * |
| 2874 | nfs4_xdev_mount(struct file_system_type *fs_type, int flags, |
| 2875 | const char *dev_name, void *raw_data) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2876 | { |
| 2877 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2878 | struct super_block *s; |
| 2879 | struct nfs_server *server; |
| 2880 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2881 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2882 | struct nfs_sb_mountdata sb_mntdata = { |
| 2883 | .mntflags = flags, |
| 2884 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2885 | int error; |
| 2886 | |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2887 | dprintk("--> nfs4_xdev_mount()\n"); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2888 | |
| 2889 | /* create a new volume representation */ |
| 2890 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2891 | if (IS_ERR(server)) { |
| 2892 | error = PTR_ERR(server); |
| 2893 | goto out_err_noserver; |
| 2894 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2895 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2896 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2897 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2898 | compare_super = NULL; |
| 2899 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2900 | /* 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] | 2901 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2902 | if (IS_ERR(s)) { |
| 2903 | error = PTR_ERR(s); |
| 2904 | goto out_err_nosb; |
| 2905 | } |
| 2906 | |
| 2907 | if (s->s_fs_info != server) { |
| 2908 | nfs_free_server(server); |
| 2909 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2910 | } else { |
| 2911 | error = nfs_bdi_register(server); |
| 2912 | if (error) |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2913 | goto error_splat_bdi; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | if (!s->s_root) { |
| 2917 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2918 | nfs4_clone_super(s, data->sb); |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 2919 | nfs_fscache_get_super_cookie(s, NULL, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2920 | } |
| 2921 | |
Al Viro | 0d5839a | 2011-03-16 05:27:27 -0400 | [diff] [blame] | 2922 | mntroot = nfs4_get_root(s, data->fh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2923 | if (IS_ERR(mntroot)) { |
| 2924 | error = PTR_ERR(mntroot); |
| 2925 | goto error_splat_super; |
| 2926 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2927 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2928 | dput(mntroot); |
| 2929 | error = -ESTALE; |
| 2930 | goto error_splat_super; |
| 2931 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2932 | |
| 2933 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2934 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2935 | security_sb_clone_mnt_opts(data->sb, s); |
| 2936 | |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2937 | dprintk("<-- nfs4_xdev_mount() = 0\n"); |
| 2938 | return mntroot; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2939 | |
| 2940 | out_err_nosb: |
| 2941 | nfs_free_server(server); |
| 2942 | out_err_noserver: |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2943 | dprintk("<-- nfs4_xdev_mount() = %d [error]\n", error); |
| 2944 | return ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2945 | |
| 2946 | error_splat_super: |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 2947 | if (server && !s->s_root) |
| 2948 | bdi_unregister(&server->backing_dev_info); |
| 2949 | error_splat_bdi: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2950 | deactivate_locked_super(s); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2951 | dprintk("<-- nfs4_xdev_mount() = %d [splat]\n", error); |
| 2952 | return ERR_PTR(error); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2953 | } |
| 2954 | |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 2955 | static struct dentry * |
| 2956 | nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags, |
| 2957 | const char *dev_name, void *raw_data) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2958 | { |
| 2959 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2960 | struct super_block *s; |
| 2961 | struct nfs_server *server; |
| 2962 | struct dentry *mntroot; |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2963 | struct nfs_fh *mntfh; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2964 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2965 | struct nfs_sb_mountdata sb_mntdata = { |
| 2966 | .mntflags = flags, |
| 2967 | }; |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2968 | int error = -ENOMEM; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2969 | |
| 2970 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2971 | |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2972 | mntfh = nfs_alloc_fhandle(); |
| 2973 | if (mntfh == NULL) |
| 2974 | goto out_err_nofh; |
| 2975 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2976 | /* create a new volume representation */ |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2977 | server = nfs4_create_referral_server(data, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2978 | if (IS_ERR(server)) { |
| 2979 | error = PTR_ERR(server); |
| 2980 | goto out_err_noserver; |
| 2981 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2982 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2983 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2984 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2985 | compare_super = NULL; |
| 2986 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2987 | /* 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] | 2988 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2989 | if (IS_ERR(s)) { |
| 2990 | error = PTR_ERR(s); |
| 2991 | goto out_err_nosb; |
| 2992 | } |
| 2993 | |
| 2994 | if (s->s_fs_info != server) { |
| 2995 | nfs_free_server(server); |
| 2996 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2997 | } else { |
| 2998 | error = nfs_bdi_register(server); |
| 2999 | if (error) |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 3000 | goto error_splat_bdi; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | if (!s->s_root) { |
| 3004 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3005 | nfs4_fill_super(s); |
David Howells | 2df5480 | 2009-09-23 14:36:39 -0400 | [diff] [blame] | 3006 | nfs_fscache_get_super_cookie(s, NULL, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Al Viro | 0d5839a | 2011-03-16 05:27:27 -0400 | [diff] [blame] | 3009 | mntroot = nfs4_get_root(s, mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3010 | if (IS_ERR(mntroot)) { |
| 3011 | error = PTR_ERR(mntroot); |
| 3012 | goto error_splat_super; |
| 3013 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 3014 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 3015 | dput(mntroot); |
| 3016 | error = -ESTALE; |
| 3017 | goto error_splat_super; |
| 3018 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3019 | |
| 3020 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3021 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 3022 | security_sb_clone_mnt_opts(data->sb, s); |
| 3023 | |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3024 | nfs_free_fhandle(mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3025 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 3026 | return mntroot; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3027 | |
| 3028 | out_err_nosb: |
| 3029 | nfs_free_server(server); |
| 3030 | out_err_noserver: |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3031 | nfs_free_fhandle(mntfh); |
| 3032 | out_err_nofh: |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3033 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 3034 | return ERR_PTR(error); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3035 | |
| 3036 | error_splat_super: |
NeilBrown | cfbc068 | 2010-03-11 11:20:17 +1100 | [diff] [blame] | 3037 | if (server && !s->s_root) |
| 3038 | bdi_unregister(&server->backing_dev_info); |
| 3039 | error_splat_bdi: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 3040 | deactivate_locked_super(s); |
Trond Myklebust | 4f72729 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 3041 | nfs_free_fhandle(mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3042 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
Al Viro | 31f4347 | 2010-10-29 03:38:12 -0400 | [diff] [blame] | 3043 | return ERR_PTR(error); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 3044 | } |
| 3045 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 3046 | /* |
| 3047 | * Create an NFS4 server record on referral traversal |
| 3048 | */ |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 3049 | static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, |
| 3050 | int flags, const char *dev_name, void *raw_data) |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 3051 | { |
| 3052 | struct nfs_clone_mount *data = raw_data; |
| 3053 | char *export_path; |
| 3054 | struct vfsmount *root_mnt; |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 3055 | struct dentry *res; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 3056 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 3057 | dprintk("--> nfs4_referral_mount()\n"); |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 3058 | |
| 3059 | export_path = data->mnt_path; |
| 3060 | data->mnt_path = "/"; |
| 3061 | |
| 3062 | root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type, |
| 3063 | flags, data, data->hostname); |
| 3064 | data->mnt_path = export_path; |
| 3065 | |
Al Viro | 0119498 | 2011-03-16 07:25:36 -0400 | [diff] [blame] | 3066 | res = ERR_CAST(root_mnt); |
| 3067 | if (!IS_ERR(root_mnt)) |
| 3068 | res = nfs_follow_remote_path(root_mnt, export_path); |
| 3069 | dprintk("<-- nfs4_referral_mount() = %ld%s\n", |
| 3070 | IS_ERR(res) ? PTR_ERR(res) : 0, |
| 3071 | IS_ERR(res) ? " [error]" : ""); |
| 3072 | return res; |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 3073 | } |
| 3074 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 3075 | #endif /* CONFIG_NFS_V4 */ |