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