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