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