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