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