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