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