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