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