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