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 | * |
| 8 | * Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some |
| 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> |
| 45 | #include <linux/nfs_idmap.h> |
| 46 | #include <linux/vfs.h> |
| 47 | #include <linux/inet.h> |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 48 | #include <linux/in6.h> |
| 49 | #include <net/ipv6.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 50 | #include <linux/nfs_xdr.h> |
Adrian Bunk | b5d5dfb | 2007-02-12 00:53:40 -0800 | [diff] [blame] | 51 | #include <linux/magic.h> |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 52 | #include <linux/parser.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 53 | |
| 54 | #include <asm/system.h> |
| 55 | #include <asm/uaccess.h> |
| 56 | |
| 57 | #include "nfs4_fs.h" |
| 58 | #include "callback.h" |
| 59 | #include "delegation.h" |
| 60 | #include "iostat.h" |
| 61 | #include "internal.h" |
| 62 | |
| 63 | #define NFSDBG_FACILITY NFSDBG_VFS |
| 64 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 65 | enum { |
| 66 | /* Mount options that take no arguments */ |
| 67 | Opt_soft, Opt_hard, |
| 68 | Opt_intr, Opt_nointr, |
| 69 | Opt_posix, Opt_noposix, |
| 70 | Opt_cto, Opt_nocto, |
| 71 | Opt_ac, Opt_noac, |
| 72 | Opt_lock, Opt_nolock, |
| 73 | Opt_v2, Opt_v3, |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 74 | Opt_udp, Opt_tcp, Opt_rdma, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 75 | Opt_acl, Opt_noacl, |
| 76 | Opt_rdirplus, Opt_nordirplus, |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 77 | Opt_sharecache, Opt_nosharecache, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 78 | |
| 79 | /* Mount options that take integer arguments */ |
| 80 | Opt_port, |
| 81 | Opt_rsize, Opt_wsize, Opt_bsize, |
| 82 | Opt_timeo, Opt_retrans, |
| 83 | Opt_acregmin, Opt_acregmax, |
| 84 | Opt_acdirmin, Opt_acdirmax, |
| 85 | Opt_actimeo, |
| 86 | Opt_namelen, |
| 87 | Opt_mountport, |
Chuck Lever | e887cbc | 2007-10-26 13:32:29 -0400 | [diff] [blame] | 88 | Opt_mountvers, |
Chuck Lever | ad879ce | 2007-10-26 13:32:24 -0400 | [diff] [blame] | 89 | Opt_nfsvers, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 90 | |
| 91 | /* Mount options that take string arguments */ |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 92 | Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 93 | Opt_addr, Opt_mountaddr, Opt_clientaddr, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 94 | |
| 95 | /* Mount options that are ignored */ |
| 96 | Opt_userspace, Opt_deprecated, |
| 97 | |
| 98 | Opt_err |
| 99 | }; |
| 100 | |
| 101 | static match_table_t nfs_mount_option_tokens = { |
| 102 | { Opt_userspace, "bg" }, |
| 103 | { Opt_userspace, "fg" }, |
| 104 | { Opt_soft, "soft" }, |
| 105 | { Opt_hard, "hard" }, |
| 106 | { Opt_intr, "intr" }, |
| 107 | { Opt_nointr, "nointr" }, |
| 108 | { Opt_posix, "posix" }, |
| 109 | { Opt_noposix, "noposix" }, |
| 110 | { Opt_cto, "cto" }, |
| 111 | { Opt_nocto, "nocto" }, |
| 112 | { Opt_ac, "ac" }, |
| 113 | { Opt_noac, "noac" }, |
| 114 | { Opt_lock, "lock" }, |
| 115 | { Opt_nolock, "nolock" }, |
| 116 | { Opt_v2, "v2" }, |
| 117 | { Opt_v3, "v3" }, |
| 118 | { Opt_udp, "udp" }, |
| 119 | { Opt_tcp, "tcp" }, |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 120 | { Opt_rdma, "rdma" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 121 | { Opt_acl, "acl" }, |
| 122 | { Opt_noacl, "noacl" }, |
| 123 | { Opt_rdirplus, "rdirplus" }, |
| 124 | { Opt_nordirplus, "nordirplus" }, |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 125 | { Opt_sharecache, "sharecache" }, |
| 126 | { Opt_nosharecache, "nosharecache" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 127 | |
| 128 | { Opt_port, "port=%u" }, |
| 129 | { Opt_rsize, "rsize=%u" }, |
| 130 | { Opt_wsize, "wsize=%u" }, |
| 131 | { Opt_bsize, "bsize=%u" }, |
| 132 | { Opt_timeo, "timeo=%u" }, |
| 133 | { Opt_retrans, "retrans=%u" }, |
| 134 | { Opt_acregmin, "acregmin=%u" }, |
| 135 | { Opt_acregmax, "acregmax=%u" }, |
| 136 | { Opt_acdirmin, "acdirmin=%u" }, |
| 137 | { Opt_acdirmax, "acdirmax=%u" }, |
| 138 | { Opt_actimeo, "actimeo=%u" }, |
| 139 | { Opt_userspace, "retry=%u" }, |
| 140 | { Opt_namelen, "namlen=%u" }, |
| 141 | { Opt_mountport, "mountport=%u" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 142 | { Opt_mountvers, "mountvers=%u" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 143 | { Opt_nfsvers, "nfsvers=%u" }, |
| 144 | { Opt_nfsvers, "vers=%u" }, |
| 145 | |
| 146 | { Opt_sec, "sec=%s" }, |
| 147 | { Opt_proto, "proto=%s" }, |
| 148 | { Opt_mountproto, "mountproto=%s" }, |
| 149 | { Opt_addr, "addr=%s" }, |
| 150 | { Opt_clientaddr, "clientaddr=%s" }, |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 151 | { Opt_mounthost, "mounthost=%s" }, |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 152 | { Opt_mountaddr, "mountaddr=%s" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 153 | |
| 154 | { Opt_err, NULL } |
| 155 | }; |
| 156 | |
| 157 | enum { |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 158 | Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 159 | |
| 160 | Opt_xprt_err |
| 161 | }; |
| 162 | |
| 163 | static match_table_t nfs_xprt_protocol_tokens = { |
| 164 | { Opt_xprt_udp, "udp" }, |
| 165 | { Opt_xprt_tcp, "tcp" }, |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 166 | { Opt_xprt_rdma, "rdma" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 167 | |
| 168 | { Opt_xprt_err, NULL } |
| 169 | }; |
| 170 | |
| 171 | enum { |
| 172 | Opt_sec_none, Opt_sec_sys, |
| 173 | Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, |
| 174 | Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, |
| 175 | Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, |
| 176 | |
| 177 | Opt_sec_err |
| 178 | }; |
| 179 | |
| 180 | static match_table_t nfs_secflavor_tokens = { |
| 181 | { Opt_sec_none, "none" }, |
| 182 | { Opt_sec_none, "null" }, |
| 183 | { Opt_sec_sys, "sys" }, |
| 184 | |
| 185 | { Opt_sec_krb5, "krb5" }, |
| 186 | { Opt_sec_krb5i, "krb5i" }, |
| 187 | { Opt_sec_krb5p, "krb5p" }, |
| 188 | |
| 189 | { Opt_sec_lkey, "lkey" }, |
| 190 | { Opt_sec_lkeyi, "lkeyi" }, |
| 191 | { Opt_sec_lkeyp, "lkeyp" }, |
| 192 | |
Olga Kornievskaia | 8d04221 | 2008-02-13 16:47:06 -0500 | [diff] [blame] | 193 | { Opt_sec_spkm, "spkm3" }, |
| 194 | { Opt_sec_spkmi, "spkm3i" }, |
| 195 | { Opt_sec_spkmp, "spkm3p" }, |
| 196 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 197 | { Opt_sec_err, NULL } |
| 198 | }; |
| 199 | |
| 200 | |
Al Viro | 42faad9 | 2008-04-24 07:21:56 -0400 | [diff] [blame] | 201 | static void nfs_umount_begin(struct super_block *); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 202 | static int nfs_statfs(struct dentry *, struct kstatfs *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 203 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
| 204 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 205 | 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] | 206 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 207 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 208 | static void nfs_kill_super(struct super_block *); |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 209 | static void nfs_put_super(struct super_block *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 210 | |
| 211 | static struct file_system_type nfs_fs_type = { |
| 212 | .owner = THIS_MODULE, |
| 213 | .name = "nfs", |
| 214 | .get_sb = nfs_get_sb, |
| 215 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 216 | .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] | 217 | }; |
| 218 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 219 | struct file_system_type nfs_xdev_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 220 | .owner = THIS_MODULE, |
| 221 | .name = "nfs", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 222 | .get_sb = nfs_xdev_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 223 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 224 | .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] | 225 | }; |
| 226 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 227 | static const struct super_operations nfs_sops = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 228 | .alloc_inode = nfs_alloc_inode, |
| 229 | .destroy_inode = nfs_destroy_inode, |
| 230 | .write_inode = nfs_write_inode, |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 231 | .put_super = nfs_put_super, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 232 | .statfs = nfs_statfs, |
| 233 | .clear_inode = nfs_clear_inode, |
| 234 | .umount_begin = nfs_umount_begin, |
| 235 | .show_options = nfs_show_options, |
| 236 | .show_stats = nfs_show_stats, |
| 237 | }; |
| 238 | |
| 239 | #ifdef CONFIG_NFS_V4 |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 240 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 241 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 242 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, |
| 243 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
| 244 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, |
| 245 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 246 | static void nfs4_kill_super(struct super_block *sb); |
| 247 | |
| 248 | static struct file_system_type nfs4_fs_type = { |
| 249 | .owner = THIS_MODULE, |
| 250 | .name = "nfs4", |
| 251 | .get_sb = nfs4_get_sb, |
| 252 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 253 | .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] | 254 | }; |
| 255 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 256 | struct file_system_type nfs4_xdev_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 257 | .owner = THIS_MODULE, |
| 258 | .name = "nfs4", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 259 | .get_sb = nfs4_xdev_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 260 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 261 | .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] | 262 | }; |
| 263 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 264 | struct file_system_type nfs4_referral_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 265 | .owner = THIS_MODULE, |
| 266 | .name = "nfs4", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 267 | .get_sb = nfs4_referral_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 268 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 269 | .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] | 270 | }; |
| 271 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 272 | static const struct super_operations nfs4_sops = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 273 | .alloc_inode = nfs_alloc_inode, |
| 274 | .destroy_inode = nfs_destroy_inode, |
| 275 | .write_inode = nfs_write_inode, |
| 276 | .statfs = nfs_statfs, |
| 277 | .clear_inode = nfs4_clear_inode, |
| 278 | .umount_begin = nfs_umount_begin, |
| 279 | .show_options = nfs_show_options, |
| 280 | .show_stats = nfs_show_stats, |
| 281 | }; |
| 282 | #endif |
| 283 | |
Rusty Russell | 8e1f936 | 2007-07-17 04:03:17 -0700 | [diff] [blame] | 284 | static struct shrinker acl_shrinker = { |
| 285 | .shrink = nfs_access_cache_shrinker, |
| 286 | .seeks = DEFAULT_SEEKS, |
| 287 | }; |
Trond Myklebust | 979df72 | 2006-07-25 11:28:19 -0400 | [diff] [blame] | 288 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 289 | /* |
| 290 | * Register the NFS filesystems |
| 291 | */ |
| 292 | int __init register_nfs_fs(void) |
| 293 | { |
| 294 | int ret; |
| 295 | |
| 296 | ret = register_filesystem(&nfs_fs_type); |
| 297 | if (ret < 0) |
| 298 | goto error_0; |
| 299 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 300 | ret = nfs_register_sysctl(); |
| 301 | if (ret < 0) |
| 302 | goto error_1; |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 303 | #ifdef CONFIG_NFS_V4 |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 304 | ret = register_filesystem(&nfs4_fs_type); |
| 305 | if (ret < 0) |
| 306 | goto error_2; |
| 307 | #endif |
Rusty Russell | 8e1f936 | 2007-07-17 04:03:17 -0700 | [diff] [blame] | 308 | register_shrinker(&acl_shrinker); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 309 | return 0; |
| 310 | |
| 311 | #ifdef CONFIG_NFS_V4 |
| 312 | error_2: |
| 313 | nfs_unregister_sysctl(); |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 314 | #endif |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 315 | error_1: |
| 316 | unregister_filesystem(&nfs_fs_type); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 317 | error_0: |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * Unregister the NFS filesystems |
| 323 | */ |
| 324 | void __exit unregister_nfs_fs(void) |
| 325 | { |
Rusty Russell | 8e1f936 | 2007-07-17 04:03:17 -0700 | [diff] [blame] | 326 | unregister_shrinker(&acl_shrinker); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 327 | #ifdef CONFIG_NFS_V4 |
| 328 | unregister_filesystem(&nfs4_fs_type); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 329 | #endif |
Alexey Dobriyan | 49af7ee | 2007-09-18 22:46:40 -0700 | [diff] [blame] | 330 | nfs_unregister_sysctl(); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 331 | unregister_filesystem(&nfs_fs_type); |
| 332 | } |
| 333 | |
Steve Dickson | ef818a2 | 2007-11-08 04:05:04 -0500 | [diff] [blame] | 334 | void nfs_sb_active(struct nfs_server *server) |
| 335 | { |
| 336 | atomic_inc(&server->active); |
| 337 | } |
| 338 | |
| 339 | void nfs_sb_deactive(struct nfs_server *server) |
| 340 | { |
| 341 | if (atomic_dec_and_test(&server->active)) |
| 342 | wake_up(&server->active_wq); |
| 343 | } |
| 344 | |
| 345 | static void nfs_put_super(struct super_block *sb) |
| 346 | { |
| 347 | struct nfs_server *server = NFS_SB(sb); |
| 348 | /* |
| 349 | * Make sure there are no outstanding ops to this server. |
| 350 | * If so, wait for them to finish before allowing the |
| 351 | * unmount to continue. |
| 352 | */ |
| 353 | wait_event(server->active_wq, atomic_read(&server->active) == 0); |
| 354 | } |
| 355 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 356 | /* |
| 357 | * Deliver file system statistics to userspace |
| 358 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 359 | static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 360 | { |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 361 | struct nfs_server *server = NFS_SB(dentry->d_sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 362 | unsigned char blockbits; |
| 363 | unsigned long blockres; |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 364 | struct nfs_fh *fh = NFS_FH(dentry->d_inode); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 365 | struct nfs_fattr fattr; |
| 366 | struct nfs_fsstat res = { |
| 367 | .fattr = &fattr, |
| 368 | }; |
| 369 | int error; |
| 370 | |
| 371 | lock_kernel(); |
| 372 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 373 | error = server->nfs_client->rpc_ops->statfs(server, fh, &res); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 374 | if (error < 0) |
| 375 | goto out_err; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 376 | buf->f_type = NFS_SUPER_MAGIC; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 377 | |
| 378 | /* |
| 379 | * Current versions of glibc do not correctly handle the |
| 380 | * case where f_frsize != f_bsize. Eventually we want to |
| 381 | * report the value of wtmult in this field. |
| 382 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 383 | buf->f_frsize = dentry->d_sb->s_blocksize; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 384 | |
| 385 | /* |
| 386 | * On most *nix systems, f_blocks, f_bfree, and f_bavail |
| 387 | * are reported in units of f_frsize. Linux hasn't had |
| 388 | * an f_frsize field in its statfs struct until recently, |
| 389 | * thus historically Linux's sys_statfs reports these |
| 390 | * fields in units of f_bsize. |
| 391 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 392 | buf->f_bsize = dentry->d_sb->s_blocksize; |
| 393 | blockbits = dentry->d_sb->s_blocksize_bits; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 394 | blockres = (1 << blockbits) - 1; |
| 395 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; |
| 396 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; |
| 397 | buf->f_bavail = (res.abytes + blockres) >> blockbits; |
| 398 | |
| 399 | buf->f_files = res.tfiles; |
| 400 | buf->f_ffree = res.afiles; |
| 401 | |
| 402 | buf->f_namelen = server->namelen; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 403 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 404 | unlock_kernel(); |
| 405 | return 0; |
| 406 | |
| 407 | out_err: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 408 | dprintk("%s: statfs error = %d\n", __func__, -error); |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 409 | unlock_kernel(); |
| 410 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 411 | } |
| 412 | |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 413 | /* |
| 414 | * Map the security flavour number to a name |
| 415 | */ |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 416 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) |
| 417 | { |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 418 | static const struct { |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 419 | rpc_authflavor_t flavour; |
| 420 | const char *str; |
| 421 | } sec_flavours[] = { |
| 422 | { RPC_AUTH_NULL, "null" }, |
| 423 | { RPC_AUTH_UNIX, "sys" }, |
| 424 | { RPC_AUTH_GSS_KRB5, "krb5" }, |
| 425 | { RPC_AUTH_GSS_KRB5I, "krb5i" }, |
| 426 | { RPC_AUTH_GSS_KRB5P, "krb5p" }, |
| 427 | { RPC_AUTH_GSS_LKEY, "lkey" }, |
| 428 | { RPC_AUTH_GSS_LKEYI, "lkeyi" }, |
| 429 | { RPC_AUTH_GSS_LKEYP, "lkeyp" }, |
| 430 | { RPC_AUTH_GSS_SPKM, "spkm" }, |
| 431 | { RPC_AUTH_GSS_SPKMI, "spkmi" }, |
| 432 | { RPC_AUTH_GSS_SPKMP, "spkmp" }, |
Chuck Lever | 4d81cd1 | 2007-07-01 12:12:40 -0400 | [diff] [blame] | 433 | { UINT_MAX, "unknown" } |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 434 | }; |
| 435 | int i; |
| 436 | |
Chuck Lever | 4d81cd1 | 2007-07-01 12:12:40 -0400 | [diff] [blame] | 437 | for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) { |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 438 | if (sec_flavours[i].flavour == flavour) |
| 439 | break; |
| 440 | } |
| 441 | return sec_flavours[i].str; |
| 442 | } |
| 443 | |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 444 | static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss, |
| 445 | int showdefaults) |
| 446 | { |
| 447 | struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address; |
| 448 | |
| 449 | switch (sap->sa_family) { |
| 450 | case AF_INET: { |
| 451 | struct sockaddr_in *sin = (struct sockaddr_in *)sap; |
| 452 | seq_printf(m, ",mountaddr=" NIPQUAD_FMT, |
| 453 | NIPQUAD(sin->sin_addr.s_addr)); |
| 454 | break; |
| 455 | } |
| 456 | case AF_INET6: { |
| 457 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; |
| 458 | seq_printf(m, ",mountaddr=" NIP6_FMT, |
| 459 | NIP6(sin6->sin6_addr)); |
| 460 | break; |
| 461 | } |
| 462 | default: |
| 463 | if (showdefaults) |
| 464 | seq_printf(m, ",mountaddr=unspecified"); |
| 465 | } |
| 466 | |
| 467 | if (nfss->mountd_version || showdefaults) |
| 468 | seq_printf(m, ",mountvers=%u", nfss->mountd_version); |
| 469 | if (nfss->mountd_port || showdefaults) |
| 470 | seq_printf(m, ",mountport=%u", nfss->mountd_port); |
| 471 | |
| 472 | switch (nfss->mountd_protocol) { |
| 473 | case IPPROTO_UDP: |
| 474 | seq_printf(m, ",mountproto=udp"); |
| 475 | break; |
| 476 | case IPPROTO_TCP: |
| 477 | seq_printf(m, ",mountproto=tcp"); |
| 478 | break; |
| 479 | default: |
| 480 | if (showdefaults) |
| 481 | seq_printf(m, ",mountproto=auto"); |
| 482 | } |
| 483 | } |
| 484 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 485 | /* |
| 486 | * Describe the mount options in force on this server representation |
| 487 | */ |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 488 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, |
| 489 | int showdefaults) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 490 | { |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 491 | static const struct proc_nfs_info { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 492 | int flag; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 493 | const char *str; |
| 494 | const char *nostr; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 495 | } nfs_info[] = { |
| 496 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 497 | { NFS_MOUNT_INTR, ",intr", ",nointr" }, |
| 498 | { NFS_MOUNT_POSIX, ",posix", "" }, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 499 | { NFS_MOUNT_NOCTO, ",nocto", "" }, |
| 500 | { NFS_MOUNT_NOAC, ",noac", "" }, |
| 501 | { NFS_MOUNT_NONLM, ",nolock", "" }, |
| 502 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
Steve Dickson | 74dd34e | 2007-04-14 17:01:15 -0400 | [diff] [blame] | 503 | { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 504 | { NFS_MOUNT_UNSHARED, ",nosharecache", ""}, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 505 | { 0, NULL, NULL } |
| 506 | }; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 507 | const struct proc_nfs_info *nfs_infop; |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 508 | struct nfs_client *clp = nfss->nfs_client; |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 509 | u32 version = clp->rpc_ops->version; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 510 | |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 511 | seq_printf(m, ",vers=%u", version); |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 512 | seq_printf(m, ",rsize=%u", nfss->rsize); |
| 513 | seq_printf(m, ",wsize=%u", nfss->wsize); |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 514 | if (nfss->bsize != 0) |
| 515 | seq_printf(m, ",bsize=%u", nfss->bsize); |
| 516 | seq_printf(m, ",namlen=%u", nfss->namelen); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 517 | if (nfss->acregmin != 3*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 518 | seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 519 | if (nfss->acregmax != 60*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 520 | seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 521 | if (nfss->acdirmin != 30*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 522 | seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 523 | if (nfss->acdirmax != 60*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 524 | seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 525 | for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { |
| 526 | if (nfss->flags & nfs_infop->flag) |
| 527 | seq_puts(m, nfs_infop->str); |
| 528 | else |
| 529 | seq_puts(m, nfs_infop->nostr); |
| 530 | } |
\"Talpey, Thomas\ | 56928ed | 2007-09-10 13:48:47 -0400 | [diff] [blame] | 531 | seq_printf(m, ",proto=%s", |
| 532 | rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO)); |
Chuck Lever | 82d101d | 2008-03-14 14:10:37 -0400 | [diff] [blame] | 533 | if (version == 4) { |
| 534 | if (nfss->port != NFS_PORT) |
| 535 | seq_printf(m, ",port=%u", nfss->port); |
| 536 | } else |
| 537 | if (nfss->port) |
| 538 | seq_printf(m, ",port=%u", nfss->port); |
| 539 | |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 540 | seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ); |
| 541 | seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries); |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 542 | 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] | 543 | |
| 544 | if (version != 4) |
| 545 | nfs_show_mountd_options(m, nfss, showdefaults); |
| 546 | |
| 547 | #ifdef CONFIG_NFS_V4 |
| 548 | if (clp->rpc_ops->version == 4) |
| 549 | seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr); |
| 550 | #endif |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /* |
| 554 | * Describe the mount options on this VFS mountpoint |
| 555 | */ |
| 556 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 557 | { |
| 558 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 559 | |
| 560 | nfs_show_mount_options(m, nfss, 0); |
| 561 | |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 562 | seq_printf(m, ",addr=%s", |
| 563 | rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient, |
| 564 | RPC_DISPLAY_ADDR)); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Present statistical information for this VFS mountpoint |
| 571 | */ |
| 572 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 573 | { |
| 574 | int i, cpu; |
| 575 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 576 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 577 | struct nfs_iostats totals = { }; |
| 578 | |
| 579 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 580 | |
| 581 | /* |
| 582 | * Display all mount option settings |
| 583 | */ |
| 584 | seq_printf(m, "\n\topts:\t"); |
| 585 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 586 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 587 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 588 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 589 | nfs_show_mount_options(m, nfss, 1); |
| 590 | |
| 591 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 592 | |
| 593 | seq_printf(m, "\n\tcaps:\t"); |
| 594 | seq_printf(m, "caps=0x%x", nfss->caps); |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 595 | seq_printf(m, ",wtmult=%u", nfss->wtmult); |
| 596 | seq_printf(m, ",dtsize=%u", nfss->dtsize); |
| 597 | seq_printf(m, ",bsize=%u", nfss->bsize); |
| 598 | seq_printf(m, ",namlen=%u", nfss->namelen); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 599 | |
| 600 | #ifdef CONFIG_NFS_V4 |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 601 | if (nfss->nfs_client->rpc_ops->version == 4) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 602 | seq_printf(m, "\n\tnfsv4:\t"); |
| 603 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 604 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 605 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 606 | } |
| 607 | #endif |
| 608 | |
| 609 | /* |
| 610 | * Display security flavor in effect for this mount |
| 611 | */ |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 612 | seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 613 | if (auth->au_flavor) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 614 | seq_printf(m, ",pseudoflavor=%u", auth->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 615 | |
| 616 | /* |
| 617 | * Display superblock I/O counters |
| 618 | */ |
| 619 | for_each_possible_cpu(cpu) { |
| 620 | struct nfs_iostats *stats; |
| 621 | |
| 622 | preempt_disable(); |
| 623 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 624 | |
| 625 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 626 | totals.events[i] += stats->events[i]; |
| 627 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 628 | totals.bytes[i] += stats->bytes[i]; |
| 629 | |
| 630 | preempt_enable(); |
| 631 | } |
| 632 | |
| 633 | seq_printf(m, "\n\tevents:\t"); |
| 634 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 635 | seq_printf(m, "%lu ", totals.events[i]); |
| 636 | seq_printf(m, "\n\tbytes:\t"); |
| 637 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 638 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 639 | seq_printf(m, "\n"); |
| 640 | |
| 641 | rpc_print_iostats(m, nfss->client); |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | /* |
| 647 | * Begin unmount by attempting to remove all automounted mountpoints we added |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 648 | * in response to xdev traversals and referrals |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 649 | */ |
Al Viro | 42faad9 | 2008-04-24 07:21:56 -0400 | [diff] [blame] | 650 | static void nfs_umount_begin(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 651 | { |
Al Viro | 42faad9 | 2008-04-24 07:21:56 -0400 | [diff] [blame] | 652 | struct nfs_server *server = NFS_SB(sb); |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 653 | struct rpc_clnt *rpc; |
| 654 | |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 655 | /* -EIO all pending I/O */ |
| 656 | rpc = server->client_acl; |
| 657 | if (!IS_ERR(rpc)) |
| 658 | rpc_killall_tasks(rpc); |
| 659 | rpc = server->client; |
| 660 | if (!IS_ERR(rpc)) |
| 661 | rpc_killall_tasks(rpc); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /* |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 665 | * Set the port number in an address. Be agnostic about the address family. |
| 666 | */ |
| 667 | static void nfs_set_port(struct sockaddr *sap, unsigned short port) |
| 668 | { |
| 669 | switch (sap->sa_family) { |
| 670 | case AF_INET: { |
| 671 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; |
| 672 | ap->sin_port = htons(port); |
| 673 | break; |
| 674 | } |
| 675 | case AF_INET6: { |
| 676 | struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; |
| 677 | ap->sin6_port = htons(port); |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /* |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 684 | * Sanity-check a server address provided by the mount command. |
| 685 | * |
| 686 | * Address family must be initialized, and address must not be |
| 687 | * the ANY address for that family. |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 688 | */ |
| 689 | static int nfs_verify_server_address(struct sockaddr *addr) |
| 690 | { |
| 691 | switch (addr->sa_family) { |
| 692 | case AF_INET: { |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 693 | struct sockaddr_in *sa = (struct sockaddr_in *)addr; |
Al Viro | e6f1ceb | 2008-03-17 22:44:53 -0700 | [diff] [blame] | 694 | return sa->sin_addr.s_addr != htonl(INADDR_ANY); |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 695 | } |
| 696 | case AF_INET6: { |
| 697 | struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; |
| 698 | return !ipv6_addr_any(sa); |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | /* |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 706 | * Parse string addresses passed in via a mount option, |
| 707 | * and construct a sockaddr based on the result. |
| 708 | * |
| 709 | * If address parsing fails, set the sockaddr's address |
| 710 | * family to AF_UNSPEC to force nfs_verify_server_address() |
| 711 | * to punt the mount. |
| 712 | */ |
| 713 | static void nfs_parse_server_address(char *value, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 714 | struct sockaddr *sap, |
| 715 | size_t *len) |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 716 | { |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 717 | if (strchr(value, ':')) { |
| 718 | struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; |
| 719 | u8 *addr = (u8 *)&ap->sin6_addr.in6_u; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 720 | |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 721 | ap->sin6_family = AF_INET6; |
| 722 | *len = sizeof(*ap); |
| 723 | if (in6_pton(value, -1, addr, '\0', NULL)) |
| 724 | return; |
| 725 | } else { |
| 726 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; |
| 727 | u8 *addr = (u8 *)&ap->sin_addr.s_addr; |
| 728 | |
| 729 | ap->sin_family = AF_INET; |
| 730 | *len = sizeof(*ap); |
| 731 | if (in4_pton(value, -1, addr, '\0', NULL)) |
| 732 | return; |
| 733 | } |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 734 | |
| 735 | sap->sa_family = AF_UNSPEC; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 736 | *len = 0; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | /* |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 740 | * Error-check and convert a string of mount options from user space into |
| 741 | * a data structure |
| 742 | */ |
| 743 | static int nfs_parse_mount_options(char *raw, |
| 744 | struct nfs_parsed_mount_data *mnt) |
| 745 | { |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 746 | char *p, *string, *secdata; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 747 | int rc; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 748 | |
| 749 | if (!raw) { |
| 750 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 751 | return 1; |
| 752 | } |
| 753 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 754 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 755 | secdata = alloc_secdata(); |
| 756 | if (!secdata) |
| 757 | goto out_nomem; |
| 758 | |
| 759 | rc = security_sb_copy_data(raw, secdata); |
| 760 | if (rc) |
| 761 | goto out_security_failure; |
| 762 | |
| 763 | rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts); |
| 764 | if (rc) |
| 765 | goto out_security_failure; |
| 766 | |
| 767 | free_secdata(secdata); |
| 768 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 769 | while ((p = strsep(&raw, ",")) != NULL) { |
| 770 | substring_t args[MAX_OPT_ARGS]; |
| 771 | int option, token; |
| 772 | |
| 773 | if (!*p) |
| 774 | continue; |
| 775 | |
| 776 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 777 | |
| 778 | token = match_token(p, nfs_mount_option_tokens, args); |
| 779 | switch (token) { |
| 780 | case Opt_soft: |
| 781 | mnt->flags |= NFS_MOUNT_SOFT; |
| 782 | break; |
| 783 | case Opt_hard: |
| 784 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 785 | break; |
| 786 | case Opt_intr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 787 | case Opt_nointr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 788 | break; |
| 789 | case Opt_posix: |
| 790 | mnt->flags |= NFS_MOUNT_POSIX; |
| 791 | break; |
| 792 | case Opt_noposix: |
| 793 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 794 | break; |
| 795 | case Opt_cto: |
| 796 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 797 | break; |
| 798 | case Opt_nocto: |
| 799 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 800 | break; |
| 801 | case Opt_ac: |
| 802 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 803 | break; |
| 804 | case Opt_noac: |
| 805 | mnt->flags |= NFS_MOUNT_NOAC; |
| 806 | break; |
| 807 | case Opt_lock: |
| 808 | mnt->flags &= ~NFS_MOUNT_NONLM; |
| 809 | break; |
| 810 | case Opt_nolock: |
| 811 | mnt->flags |= NFS_MOUNT_NONLM; |
| 812 | break; |
| 813 | case Opt_v2: |
| 814 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 815 | break; |
| 816 | case Opt_v3: |
| 817 | mnt->flags |= NFS_MOUNT_VER3; |
| 818 | break; |
| 819 | case Opt_udp: |
| 820 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 821 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 822 | mnt->timeo = 7; |
| 823 | mnt->retrans = 5; |
| 824 | break; |
| 825 | case Opt_tcp: |
| 826 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 827 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 828 | mnt->timeo = 600; |
| 829 | mnt->retrans = 2; |
| 830 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 831 | case Opt_rdma: |
| 832 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 833 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 834 | mnt->timeo = 600; |
| 835 | mnt->retrans = 2; |
| 836 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 837 | case Opt_acl: |
| 838 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 839 | break; |
| 840 | case Opt_noacl: |
| 841 | mnt->flags |= NFS_MOUNT_NOACL; |
| 842 | break; |
| 843 | case Opt_rdirplus: |
| 844 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 845 | break; |
| 846 | case Opt_nordirplus: |
| 847 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 848 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 849 | case Opt_sharecache: |
| 850 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 851 | break; |
| 852 | case Opt_nosharecache: |
| 853 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 854 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 855 | |
| 856 | case Opt_port: |
| 857 | if (match_int(args, &option)) |
| 858 | return 0; |
| 859 | if (option < 0 || option > 65535) |
| 860 | return 0; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 861 | mnt->nfs_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 862 | break; |
| 863 | case Opt_rsize: |
| 864 | if (match_int(args, &mnt->rsize)) |
| 865 | return 0; |
| 866 | break; |
| 867 | case Opt_wsize: |
| 868 | if (match_int(args, &mnt->wsize)) |
| 869 | return 0; |
| 870 | break; |
| 871 | case Opt_bsize: |
| 872 | if (match_int(args, &option)) |
| 873 | return 0; |
| 874 | if (option < 0) |
| 875 | return 0; |
| 876 | mnt->bsize = option; |
| 877 | break; |
| 878 | case Opt_timeo: |
| 879 | if (match_int(args, &mnt->timeo)) |
| 880 | return 0; |
| 881 | break; |
| 882 | case Opt_retrans: |
| 883 | if (match_int(args, &mnt->retrans)) |
| 884 | return 0; |
| 885 | break; |
| 886 | case Opt_acregmin: |
| 887 | if (match_int(args, &mnt->acregmin)) |
| 888 | return 0; |
| 889 | break; |
| 890 | case Opt_acregmax: |
| 891 | if (match_int(args, &mnt->acregmax)) |
| 892 | return 0; |
| 893 | break; |
| 894 | case Opt_acdirmin: |
| 895 | if (match_int(args, &mnt->acdirmin)) |
| 896 | return 0; |
| 897 | break; |
| 898 | case Opt_acdirmax: |
| 899 | if (match_int(args, &mnt->acdirmax)) |
| 900 | return 0; |
| 901 | break; |
| 902 | case Opt_actimeo: |
| 903 | if (match_int(args, &option)) |
| 904 | return 0; |
| 905 | if (option < 0) |
| 906 | return 0; |
| 907 | mnt->acregmin = |
| 908 | mnt->acregmax = |
| 909 | mnt->acdirmin = |
| 910 | mnt->acdirmax = option; |
| 911 | break; |
| 912 | case Opt_namelen: |
| 913 | if (match_int(args, &mnt->namlen)) |
| 914 | return 0; |
| 915 | break; |
| 916 | case Opt_mountport: |
| 917 | if (match_int(args, &option)) |
| 918 | return 0; |
| 919 | if (option < 0 || option > 65535) |
| 920 | return 0; |
| 921 | mnt->mount_server.port = option; |
| 922 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 923 | case Opt_mountvers: |
| 924 | if (match_int(args, &option)) |
| 925 | return 0; |
| 926 | if (option < 0) |
| 927 | return 0; |
| 928 | mnt->mount_server.version = option; |
| 929 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 930 | case Opt_nfsvers: |
| 931 | if (match_int(args, &option)) |
| 932 | return 0; |
| 933 | switch (option) { |
| 934 | case 2: |
| 935 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 936 | break; |
| 937 | case 3: |
| 938 | mnt->flags |= NFS_MOUNT_VER3; |
| 939 | break; |
| 940 | default: |
| 941 | goto out_unrec_vers; |
| 942 | } |
| 943 | break; |
| 944 | |
| 945 | case Opt_sec: |
| 946 | string = match_strdup(args); |
| 947 | if (string == NULL) |
| 948 | goto out_nomem; |
| 949 | token = match_token(string, nfs_secflavor_tokens, args); |
| 950 | kfree(string); |
| 951 | |
| 952 | /* |
| 953 | * The flags setting is for v2/v3. The flavor_len |
| 954 | * setting is for v4. v2/v3 also need to know the |
| 955 | * difference between NULL and UNIX. |
| 956 | */ |
| 957 | switch (token) { |
| 958 | case Opt_sec_none: |
| 959 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 960 | mnt->auth_flavor_len = 0; |
| 961 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 962 | break; |
| 963 | case Opt_sec_sys: |
| 964 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 965 | mnt->auth_flavor_len = 0; |
| 966 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 967 | break; |
| 968 | case Opt_sec_krb5: |
| 969 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 970 | mnt->auth_flavor_len = 1; |
| 971 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 972 | break; |
| 973 | case Opt_sec_krb5i: |
| 974 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 975 | mnt->auth_flavor_len = 1; |
| 976 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 977 | break; |
| 978 | case Opt_sec_krb5p: |
| 979 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 980 | mnt->auth_flavor_len = 1; |
| 981 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 982 | break; |
| 983 | case Opt_sec_lkey: |
| 984 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 985 | mnt->auth_flavor_len = 1; |
| 986 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 987 | break; |
| 988 | case Opt_sec_lkeyi: |
| 989 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 990 | mnt->auth_flavor_len = 1; |
| 991 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 992 | break; |
| 993 | case Opt_sec_lkeyp: |
| 994 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 995 | mnt->auth_flavor_len = 1; |
| 996 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 997 | break; |
| 998 | case Opt_sec_spkm: |
| 999 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 1000 | mnt->auth_flavor_len = 1; |
| 1001 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 1002 | break; |
| 1003 | case Opt_sec_spkmi: |
| 1004 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 1005 | mnt->auth_flavor_len = 1; |
| 1006 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 1007 | break; |
| 1008 | case Opt_sec_spkmp: |
| 1009 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 1010 | mnt->auth_flavor_len = 1; |
| 1011 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 1012 | break; |
| 1013 | default: |
| 1014 | goto out_unrec_sec; |
| 1015 | } |
| 1016 | break; |
| 1017 | case Opt_proto: |
| 1018 | string = match_strdup(args); |
| 1019 | if (string == NULL) |
| 1020 | goto out_nomem; |
| 1021 | token = match_token(string, |
| 1022 | nfs_xprt_protocol_tokens, args); |
| 1023 | kfree(string); |
| 1024 | |
| 1025 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1026 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1027 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1028 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1029 | mnt->timeo = 7; |
| 1030 | mnt->retrans = 5; |
| 1031 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1032 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1033 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1034 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1035 | mnt->timeo = 600; |
| 1036 | mnt->retrans = 2; |
| 1037 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1038 | case Opt_xprt_rdma: |
| 1039 | /* vector side protocols to TCP */ |
| 1040 | mnt->flags |= NFS_MOUNT_TCP; |
| 1041 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 1042 | mnt->timeo = 600; |
| 1043 | mnt->retrans = 2; |
| 1044 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1045 | default: |
| 1046 | goto out_unrec_xprt; |
| 1047 | } |
| 1048 | break; |
| 1049 | case Opt_mountproto: |
| 1050 | string = match_strdup(args); |
| 1051 | if (string == NULL) |
| 1052 | goto out_nomem; |
| 1053 | token = match_token(string, |
| 1054 | nfs_xprt_protocol_tokens, args); |
| 1055 | kfree(string); |
| 1056 | |
| 1057 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1058 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1059 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1060 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1061 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1062 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1063 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1064 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1065 | default: |
| 1066 | goto out_unrec_xprt; |
| 1067 | } |
| 1068 | break; |
| 1069 | case Opt_addr: |
| 1070 | string = match_strdup(args); |
| 1071 | if (string == NULL) |
| 1072 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1073 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1074 | &mnt->nfs_server.address, |
| 1075 | &mnt->nfs_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1076 | kfree(string); |
| 1077 | break; |
| 1078 | case Opt_clientaddr: |
| 1079 | string = match_strdup(args); |
| 1080 | if (string == NULL) |
| 1081 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1082 | kfree(mnt->client_address); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1083 | mnt->client_address = string; |
| 1084 | break; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1085 | case Opt_mounthost: |
| 1086 | string = match_strdup(args); |
| 1087 | if (string == NULL) |
| 1088 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1089 | kfree(mnt->mount_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1090 | mnt->mount_server.hostname = string; |
| 1091 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 1092 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1093 | string = match_strdup(args); |
| 1094 | if (string == NULL) |
| 1095 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1096 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1097 | &mnt->mount_server.address, |
| 1098 | &mnt->mount_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1099 | kfree(string); |
| 1100 | break; |
| 1101 | |
| 1102 | case Opt_userspace: |
| 1103 | case Opt_deprecated: |
| 1104 | break; |
| 1105 | |
| 1106 | default: |
| 1107 | goto out_unknown; |
| 1108 | } |
| 1109 | } |
| 1110 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1111 | nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, |
| 1112 | mnt->nfs_server.port); |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 1113 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1114 | return 1; |
| 1115 | |
| 1116 | out_nomem: |
| 1117 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| 1118 | return 0; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1119 | out_security_failure: |
| 1120 | free_secdata(secdata); |
| 1121 | printk(KERN_INFO "NFS: security options invalid: %d\n", rc); |
| 1122 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1123 | out_unrec_vers: |
| 1124 | printk(KERN_INFO "NFS: unrecognized NFS version number\n"); |
| 1125 | return 0; |
| 1126 | |
| 1127 | out_unrec_xprt: |
| 1128 | printk(KERN_INFO "NFS: unrecognized transport protocol\n"); |
| 1129 | return 0; |
| 1130 | |
| 1131 | out_unrec_sec: |
| 1132 | printk(KERN_INFO "NFS: unrecognized security flavor\n"); |
| 1133 | return 0; |
| 1134 | |
| 1135 | out_unknown: |
| 1136 | printk(KERN_INFO "NFS: unknown mount option: %s\n", p); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /* |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1141 | * Use the remote server's MOUNT service to request the NFS file handle |
| 1142 | * corresponding to the provided path. |
| 1143 | */ |
| 1144 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 1145 | struct nfs_fh *root_fh) |
| 1146 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1147 | struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1148 | char *hostname; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1149 | int status; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1150 | |
| 1151 | if (args->mount_server.version == 0) { |
| 1152 | if (args->flags & NFS_MOUNT_VER3) |
| 1153 | args->mount_server.version = NFS_MNT3_VERSION; |
| 1154 | else |
| 1155 | args->mount_server.version = NFS_MNT_VERSION; |
| 1156 | } |
| 1157 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1158 | if (args->mount_server.hostname) |
| 1159 | hostname = args->mount_server.hostname; |
| 1160 | else |
| 1161 | hostname = args->nfs_server.hostname; |
| 1162 | |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1163 | /* |
| 1164 | * Construct the mount server's address. |
| 1165 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1166 | if (args->mount_server.address.ss_family == AF_UNSPEC) { |
| 1167 | memcpy(sap, &args->nfs_server.address, |
| 1168 | args->nfs_server.addrlen); |
| 1169 | args->mount_server.addrlen = args->nfs_server.addrlen; |
| 1170 | } |
| 1171 | |
James Lentini | aad7000 | 2007-09-24 17:32:49 -0400 | [diff] [blame] | 1172 | /* |
| 1173 | * autobind will be used if mount_server.port == 0 |
| 1174 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1175 | nfs_set_port(sap, args->mount_server.port); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1176 | |
| 1177 | /* |
| 1178 | * Now ask the mount server to map our export path |
| 1179 | * to a file handle. |
| 1180 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1181 | status = nfs_mount(sap, |
| 1182 | args->mount_server.addrlen, |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1183 | hostname, |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1184 | args->nfs_server.export_path, |
| 1185 | args->mount_server.version, |
| 1186 | args->mount_server.protocol, |
| 1187 | root_fh); |
Chuck Lever | efd8340 | 2007-09-11 18:00:58 -0400 | [diff] [blame] | 1188 | if (status == 0) |
| 1189 | return 0; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1190 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1191 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d", |
| 1192 | hostname, status); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1193 | return status; |
| 1194 | } |
| 1195 | |
| 1196 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1197 | * Validate the NFS2/NFS3 mount data |
| 1198 | * - fills in the mount root filehandle |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1199 | * |
| 1200 | * For option strings, user space handles the following behaviors: |
| 1201 | * |
| 1202 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 1203 | * |
| 1204 | * + failure mode: how to behave if a mount request can't be handled |
| 1205 | * immediately ("fg/bg" option) |
| 1206 | * |
| 1207 | * + retry: how often to retry a mount request ("retry=" option) |
| 1208 | * |
| 1209 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 1210 | * mountproto=tcp after mountproto=udp, and so on |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1211 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1212 | static int nfs_validate_mount_data(void *options, |
| 1213 | struct nfs_parsed_mount_data *args, |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1214 | struct nfs_fh *mntfh, |
| 1215 | const char *dev_name) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1216 | { |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1217 | struct nfs_mount_data *data = (struct nfs_mount_data *)options; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1218 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1219 | memset(args, 0, sizeof(*args)); |
| 1220 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1221 | if (data == NULL) |
| 1222 | goto out_no_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1223 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1224 | args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP); |
| 1225 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1226 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1227 | args->timeo = 600; |
| 1228 | args->retrans = 2; |
| 1229 | args->acregmin = 3; |
| 1230 | args->acregmax = 60; |
| 1231 | args->acdirmin = 30; |
| 1232 | args->acdirmax = 60; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1233 | args->mount_server.port = 0; /* autobind unless user sets port */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1234 | args->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1235 | args->nfs_server.port = 0; /* autobind unless user sets port */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1236 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1237 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1238 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1239 | case 1: |
| 1240 | data->namlen = 0; |
| 1241 | case 2: |
| 1242 | data->bsize = 0; |
| 1243 | case 3: |
| 1244 | if (data->flags & NFS_MOUNT_VER3) |
| 1245 | goto out_no_v3; |
| 1246 | data->root.size = NFS2_FHSIZE; |
| 1247 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1248 | case 4: |
| 1249 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1250 | goto out_no_sec; |
| 1251 | case 5: |
| 1252 | memset(data->context, 0, sizeof(data->context)); |
| 1253 | case 6: |
| 1254 | if (data->flags & NFS_MOUNT_VER3) |
| 1255 | mntfh->size = data->root.size; |
| 1256 | else |
| 1257 | mntfh->size = NFS2_FHSIZE; |
| 1258 | |
| 1259 | if (mntfh->size > sizeof(mntfh->data)) |
| 1260 | goto out_invalid_fh; |
| 1261 | |
| 1262 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1263 | if (mntfh->size < sizeof(mntfh->data)) |
| 1264 | memset(mntfh->data + mntfh->size, 0, |
| 1265 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1266 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1267 | /* |
| 1268 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1269 | * can deal with. |
| 1270 | */ |
| 1271 | args->flags = data->flags; |
| 1272 | args->rsize = data->rsize; |
| 1273 | args->wsize = data->wsize; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1274 | args->timeo = data->timeo; |
| 1275 | args->retrans = data->retrans; |
| 1276 | args->acregmin = data->acregmin; |
| 1277 | args->acregmax = data->acregmax; |
| 1278 | args->acdirmin = data->acdirmin; |
| 1279 | args->acdirmax = data->acdirmax; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1280 | |
| 1281 | memcpy(&args->nfs_server.address, &data->addr, |
| 1282 | sizeof(data->addr)); |
| 1283 | args->nfs_server.addrlen = sizeof(data->addr); |
| 1284 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1285 | &args->nfs_server.address)) |
| 1286 | goto out_no_address; |
| 1287 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1288 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1289 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1290 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1291 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1292 | args->namlen = data->namlen; |
| 1293 | args->bsize = data->bsize; |
| 1294 | args->auth_flavors[0] = data->pseudoflavor; |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1295 | if (!args->nfs_server.hostname) |
| 1296 | goto out_nomem; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1297 | |
| 1298 | /* |
| 1299 | * The legacy version 6 binary mount data from userspace has a |
| 1300 | * field used only to transport selinux information into the |
| 1301 | * the kernel. To continue to support that functionality we |
| 1302 | * have a touch of selinux knowledge here in the NFS code. The |
| 1303 | * userspace code converted context=blah to just blah so we are |
| 1304 | * converting back to the full string selinux understands. |
| 1305 | */ |
| 1306 | if (data->context[0]){ |
| 1307 | #ifdef CONFIG_SECURITY_SELINUX |
| 1308 | int rc; |
| 1309 | char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL); |
| 1310 | if (!opts_str) |
| 1311 | return -ENOMEM; |
| 1312 | strcpy(opts_str, "context="); |
| 1313 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
| 1314 | strcat(opts_str, &data->context[0]); |
| 1315 | rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts); |
| 1316 | kfree(opts_str); |
| 1317 | if (rc) |
| 1318 | return rc; |
| 1319 | #else |
| 1320 | return -EINVAL; |
| 1321 | #endif |
| 1322 | } |
| 1323 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1324 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1325 | default: { |
| 1326 | unsigned int len; |
| 1327 | char *c; |
| 1328 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1329 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1330 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1331 | return -EINVAL; |
| 1332 | |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1333 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1334 | &args->nfs_server.address)) |
| 1335 | goto out_no_address; |
| 1336 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1337 | c = strchr(dev_name, ':'); |
| 1338 | if (c == NULL) |
| 1339 | return -EINVAL; |
Chuck Lever | 350c73a | 2007-08-29 17:59:01 -0400 | [diff] [blame] | 1340 | len = c - dev_name; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1341 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1342 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1343 | if (!args->nfs_server.hostname) |
| 1344 | goto out_nomem; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1345 | |
| 1346 | c++; |
| 1347 | if (strlen(c) > NFS_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1348 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1349 | args->nfs_server.export_path = c; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1350 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1351 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1352 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1353 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1354 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1355 | break; |
| 1356 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1357 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1358 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1359 | if (!(args->flags & NFS_MOUNT_SECFLAVOUR)) |
| 1360 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Trond Myklebust | 36b15c5 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1361 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1362 | #ifndef CONFIG_NFS_V3 |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1363 | if (args->flags & NFS_MOUNT_VER3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1364 | goto out_v3_not_compiled; |
| 1365 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1366 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1367 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1368 | |
| 1369 | out_no_data: |
| 1370 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1371 | return -EINVAL; |
| 1372 | |
| 1373 | out_no_v3: |
| 1374 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1375 | data->version); |
| 1376 | return -EINVAL; |
| 1377 | |
| 1378 | out_no_sec: |
| 1379 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1380 | return -EINVAL; |
| 1381 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1382 | #ifndef CONFIG_NFS_V3 |
| 1383 | out_v3_not_compiled: |
| 1384 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1385 | return -EPROTONOSUPPORT; |
| 1386 | #endif /* !CONFIG_NFS_V3 */ |
| 1387 | |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1388 | out_nomem: |
| 1389 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); |
| 1390 | return -ENOMEM; |
| 1391 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1392 | out_no_address: |
| 1393 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1394 | return -EINVAL; |
| 1395 | |
| 1396 | out_invalid_fh: |
| 1397 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1398 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /* |
| 1402 | * Initialise the common bits of the superblock |
| 1403 | */ |
| 1404 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 1405 | { |
| 1406 | struct nfs_server *server = NFS_SB(sb); |
| 1407 | |
| 1408 | sb->s_magic = NFS_SUPER_MAGIC; |
| 1409 | |
| 1410 | /* We probably want something more informative here */ |
| 1411 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 1412 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 1413 | |
| 1414 | if (sb->s_blocksize == 0) |
| 1415 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 1416 | &sb->s_blocksize_bits); |
| 1417 | |
| 1418 | if (server->flags & NFS_MOUNT_NOAC) |
| 1419 | sb->s_flags |= MS_SYNCHRONOUS; |
| 1420 | |
| 1421 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | * Finish setting up an NFS2/3 superblock |
| 1426 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1427 | static void nfs_fill_super(struct super_block *sb, |
| 1428 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1429 | { |
| 1430 | struct nfs_server *server = NFS_SB(sb); |
| 1431 | |
| 1432 | sb->s_blocksize_bits = 0; |
| 1433 | sb->s_blocksize = 0; |
| 1434 | if (data->bsize) |
| 1435 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 1436 | |
| 1437 | if (server->flags & NFS_MOUNT_VER3) { |
| 1438 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1439 | * so ourselves when necessary. |
| 1440 | */ |
| 1441 | sb->s_flags |= MS_POSIXACL; |
| 1442 | sb->s_time_gran = 1; |
| 1443 | } |
| 1444 | |
| 1445 | sb->s_op = &nfs_sops; |
| 1446 | nfs_initialise_sb(sb); |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | * Finish setting up a cloned NFS2/3 superblock |
| 1451 | */ |
| 1452 | static void nfs_clone_super(struct super_block *sb, |
| 1453 | const struct super_block *old_sb) |
| 1454 | { |
| 1455 | struct nfs_server *server = NFS_SB(sb); |
| 1456 | |
| 1457 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1458 | sb->s_blocksize = old_sb->s_blocksize; |
| 1459 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1460 | |
| 1461 | if (server->flags & NFS_MOUNT_VER3) { |
| 1462 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1463 | * so ourselves when necessary. |
| 1464 | */ |
| 1465 | sb->s_flags |= MS_POSIXACL; |
| 1466 | sb->s_time_gran = 1; |
| 1467 | } |
| 1468 | |
| 1469 | sb->s_op = old_sb->s_op; |
| 1470 | nfs_initialise_sb(sb); |
| 1471 | } |
| 1472 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1473 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) |
| 1474 | |
| 1475 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 1476 | { |
| 1477 | const struct nfs_server *a = s->s_fs_info; |
| 1478 | const struct rpc_clnt *clnt_a = a->client; |
| 1479 | const struct rpc_clnt *clnt_b = b->client; |
| 1480 | |
| 1481 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 1482 | goto Ebusy; |
| 1483 | if (a->nfs_client != b->nfs_client) |
| 1484 | goto Ebusy; |
| 1485 | if (a->flags != b->flags) |
| 1486 | goto Ebusy; |
| 1487 | if (a->wsize != b->wsize) |
| 1488 | goto Ebusy; |
| 1489 | if (a->rsize != b->rsize) |
| 1490 | goto Ebusy; |
| 1491 | if (a->acregmin != b->acregmin) |
| 1492 | goto Ebusy; |
| 1493 | if (a->acregmax != b->acregmax) |
| 1494 | goto Ebusy; |
| 1495 | if (a->acdirmin != b->acdirmin) |
| 1496 | goto Ebusy; |
| 1497 | if (a->acdirmax != b->acdirmax) |
| 1498 | goto Ebusy; |
| 1499 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 1500 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1501 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1502 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | struct nfs_sb_mountdata { |
| 1507 | struct nfs_server *server; |
| 1508 | int mntflags; |
| 1509 | }; |
| 1510 | |
| 1511 | static int nfs_set_super(struct super_block *s, void *data) |
| 1512 | { |
| 1513 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1514 | struct nfs_server *server = sb_mntdata->server; |
| 1515 | int ret; |
| 1516 | |
| 1517 | s->s_flags = sb_mntdata->mntflags; |
| 1518 | s->s_fs_info = server; |
| 1519 | ret = set_anon_super(s, server); |
| 1520 | if (ret == 0) |
| 1521 | server->s_dev = s->s_dev; |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1525 | static int nfs_compare_super_address(struct nfs_server *server1, |
| 1526 | struct nfs_server *server2) |
| 1527 | { |
| 1528 | struct sockaddr *sap1, *sap2; |
| 1529 | |
| 1530 | sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr; |
| 1531 | sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr; |
| 1532 | |
| 1533 | if (sap1->sa_family != sap2->sa_family) |
| 1534 | return 0; |
| 1535 | |
| 1536 | switch (sap1->sa_family) { |
| 1537 | case AF_INET: { |
| 1538 | struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1; |
| 1539 | struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2; |
| 1540 | if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) |
| 1541 | return 0; |
| 1542 | if (sin1->sin_port != sin2->sin_port) |
| 1543 | return 0; |
| 1544 | break; |
| 1545 | } |
| 1546 | case AF_INET6: { |
| 1547 | struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1; |
| 1548 | struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2; |
| 1549 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
| 1550 | return 0; |
| 1551 | if (sin1->sin6_port != sin2->sin6_port) |
| 1552 | return 0; |
| 1553 | break; |
| 1554 | } |
| 1555 | default: |
| 1556 | return 0; |
| 1557 | } |
| 1558 | |
| 1559 | return 1; |
| 1560 | } |
| 1561 | |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1562 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 1563 | { |
| 1564 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1565 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 1566 | int mntflags = sb_mntdata->mntflags; |
| 1567 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1568 | if (!nfs_compare_super_address(old, server)) |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1569 | return 0; |
| 1570 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 1571 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 1572 | return 0; |
| 1573 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 1574 | return 0; |
| 1575 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1576 | } |
| 1577 | |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 1578 | static int nfs_bdi_register(struct nfs_server *server) |
| 1579 | { |
| 1580 | return bdi_register_dev(&server->backing_dev_info, server->s_dev); |
| 1581 | } |
| 1582 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1583 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 1584 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 1585 | { |
| 1586 | struct nfs_server *server = NULL; |
| 1587 | struct super_block *s; |
| 1588 | struct nfs_fh mntfh; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1589 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1590 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1591 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1592 | struct nfs_sb_mountdata sb_mntdata = { |
| 1593 | .mntflags = flags, |
| 1594 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1595 | int error; |
| 1596 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1597 | security_init_mnt_opts(&data.lsm_opts); |
| 1598 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1599 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1600 | error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1601 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1602 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1603 | |
| 1604 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1605 | server = nfs_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1606 | if (IS_ERR(server)) { |
| 1607 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1608 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1609 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1610 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1611 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1612 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1613 | compare_super = NULL; |
| 1614 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1615 | /* 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] | 1616 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1617 | if (IS_ERR(s)) { |
| 1618 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1619 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1620 | } |
| 1621 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1622 | if (s->s_fs_info != server) { |
| 1623 | nfs_free_server(server); |
| 1624 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 1625 | } else { |
| 1626 | error = nfs_bdi_register(server); |
| 1627 | if (error) |
| 1628 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1629 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1630 | |
| 1631 | if (!s->s_root) { |
| 1632 | /* initial superblock/root creation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1633 | nfs_fill_super(s, &data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | mntroot = nfs_get_root(s, &mntfh); |
| 1637 | if (IS_ERR(mntroot)) { |
| 1638 | error = PTR_ERR(mntroot); |
| 1639 | goto error_splat_super; |
| 1640 | } |
| 1641 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1642 | error = security_sb_set_mnt_opts(s, &data.lsm_opts); |
| 1643 | if (error) |
| 1644 | goto error_splat_root; |
| 1645 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1646 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1647 | mnt->mnt_sb = s; |
| 1648 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1649 | error = 0; |
| 1650 | |
| 1651 | out: |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1652 | kfree(data.nfs_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1653 | kfree(data.mount_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1654 | security_free_mnt_opts(&data.lsm_opts); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1655 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1656 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1657 | out_err_nosb: |
| 1658 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1659 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1660 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1661 | error_splat_root: |
| 1662 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1663 | error_splat_super: |
| 1664 | up_write(&s->s_umount); |
| 1665 | deactivate_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1666 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1667 | } |
| 1668 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1669 | /* |
| 1670 | * Destroy an NFS2/3 superblock |
| 1671 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1672 | static void nfs_kill_super(struct super_block *s) |
| 1673 | { |
| 1674 | struct nfs_server *server = NFS_SB(s); |
| 1675 | |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 1676 | bdi_unregister(&server->backing_dev_info); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1677 | kill_anon_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1678 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1679 | } |
| 1680 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1681 | /* |
| 1682 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 1683 | */ |
| 1684 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1685 | const char *dev_name, void *raw_data, |
| 1686 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1687 | { |
| 1688 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1689 | struct super_block *s; |
| 1690 | struct nfs_server *server; |
| 1691 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1692 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1693 | struct nfs_sb_mountdata sb_mntdata = { |
| 1694 | .mntflags = flags, |
| 1695 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1696 | int error; |
| 1697 | |
| 1698 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 1699 | |
| 1700 | /* create a new volume representation */ |
| 1701 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 1702 | if (IS_ERR(server)) { |
| 1703 | error = PTR_ERR(server); |
| 1704 | goto out_err_noserver; |
| 1705 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1706 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1707 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1708 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1709 | compare_super = NULL; |
| 1710 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1711 | /* 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] | 1712 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1713 | if (IS_ERR(s)) { |
| 1714 | error = PTR_ERR(s); |
| 1715 | goto out_err_nosb; |
| 1716 | } |
| 1717 | |
| 1718 | if (s->s_fs_info != server) { |
| 1719 | nfs_free_server(server); |
| 1720 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 1721 | } else { |
| 1722 | error = nfs_bdi_register(server); |
| 1723 | if (error) |
| 1724 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | if (!s->s_root) { |
| 1728 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1729 | nfs_clone_super(s, data->sb); |
| 1730 | } |
| 1731 | |
| 1732 | mntroot = nfs_get_root(s, data->fh); |
| 1733 | if (IS_ERR(mntroot)) { |
| 1734 | error = PTR_ERR(mntroot); |
| 1735 | goto error_splat_super; |
| 1736 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 1737 | 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] | 1738 | dput(mntroot); |
| 1739 | error = -ESTALE; |
| 1740 | goto error_splat_super; |
| 1741 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1742 | |
| 1743 | s->s_flags |= MS_ACTIVE; |
| 1744 | mnt->mnt_sb = s; |
| 1745 | mnt->mnt_root = mntroot; |
| 1746 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1747 | /* clone any lsm security options from the parent to the new sb */ |
| 1748 | security_sb_clone_mnt_opts(data->sb, s); |
| 1749 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1750 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 1751 | return 0; |
| 1752 | |
| 1753 | out_err_nosb: |
| 1754 | nfs_free_server(server); |
| 1755 | out_err_noserver: |
| 1756 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 1757 | return error; |
| 1758 | |
| 1759 | error_splat_super: |
| 1760 | up_write(&s->s_umount); |
| 1761 | deactivate_super(s); |
| 1762 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 1763 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1764 | } |
| 1765 | |
| 1766 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1767 | |
| 1768 | /* |
| 1769 | * Finish setting up a cloned NFS4 superblock |
| 1770 | */ |
| 1771 | static void nfs4_clone_super(struct super_block *sb, |
| 1772 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1773 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1774 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1775 | sb->s_blocksize = old_sb->s_blocksize; |
| 1776 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1777 | sb->s_time_gran = 1; |
| 1778 | sb->s_op = old_sb->s_op; |
| 1779 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | /* |
| 1783 | * Set up an NFS4 superblock |
| 1784 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1785 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1786 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1787 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1788 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1789 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1792 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1793 | * Validate NFSv4 mount options |
| 1794 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1795 | static int nfs4_validate_mount_data(void *options, |
| 1796 | struct nfs_parsed_mount_data *args, |
| 1797 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1798 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1799 | struct sockaddr_in *ap; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1800 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1801 | char *c; |
| 1802 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1803 | memset(args, 0, sizeof(*args)); |
| 1804 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1805 | if (data == NULL) |
| 1806 | goto out_no_data; |
| 1807 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1808 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1809 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1810 | args->timeo = 600; |
| 1811 | args->retrans = 2; |
| 1812 | args->acregmin = 3; |
| 1813 | args->acregmax = 60; |
| 1814 | args->acdirmin = 30; |
| 1815 | args->acdirmax = 60; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1816 | args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1817 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1818 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1819 | switch (data->version) { |
| 1820 | case 1: |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1821 | ap = (struct sockaddr_in *)&args->nfs_server.address; |
| 1822 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1823 | goto out_no_address; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1824 | if (data->host_addrlen == 0) |
| 1825 | goto out_no_address; |
| 1826 | args->nfs_server.addrlen = data->host_addrlen; |
| 1827 | if (copy_from_user(ap, data->host_addr, data->host_addrlen)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1828 | return -EFAULT; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1829 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1830 | &args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1831 | goto out_no_address; |
| 1832 | |
| 1833 | switch (data->auth_flavourlen) { |
| 1834 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1835 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1836 | break; |
| 1837 | case 1: |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1838 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1839 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1840 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1841 | return -EFAULT; |
| 1842 | break; |
| 1843 | default: |
| 1844 | goto out_inval_auth; |
| 1845 | } |
| 1846 | |
| 1847 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 1848 | if (IS_ERR(c)) |
| 1849 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1850 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1851 | |
| 1852 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 1853 | if (IS_ERR(c)) |
| 1854 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1855 | args->nfs_server.export_path = c; |
| 1856 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1857 | |
| 1858 | c = strndup_user(data->client_addr.data, 16); |
| 1859 | if (IS_ERR(c)) |
| 1860 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1861 | args->client_address = c; |
| 1862 | |
| 1863 | /* |
| 1864 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 1865 | * can deal with. |
| 1866 | */ |
| 1867 | |
| 1868 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 1869 | args->rsize = data->rsize; |
| 1870 | args->wsize = data->wsize; |
| 1871 | args->timeo = data->timeo; |
| 1872 | args->retrans = data->retrans; |
| 1873 | args->acregmin = data->acregmin; |
| 1874 | args->acregmax = data->acregmax; |
| 1875 | args->acdirmin = data->acdirmin; |
| 1876 | args->acdirmax = data->acdirmax; |
| 1877 | args->nfs_server.protocol = data->proto; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1878 | |
| 1879 | break; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1880 | default: { |
| 1881 | unsigned int len; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1882 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1883 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1884 | return -EINVAL; |
| 1885 | |
| 1886 | if (!nfs_verify_server_address((struct sockaddr *) |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1887 | &args->nfs_server.address)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1888 | return -EINVAL; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1889 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1890 | switch (args->auth_flavor_len) { |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1891 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1892 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1893 | break; |
| 1894 | case 1: |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1895 | break; |
| 1896 | default: |
| 1897 | goto out_inval_auth; |
| 1898 | } |
| 1899 | |
| 1900 | /* |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1901 | * Split "dev_name" into "hostname:mntpath". |
| 1902 | */ |
| 1903 | c = strchr(dev_name, ':'); |
| 1904 | if (c == NULL) |
| 1905 | return -EINVAL; |
| 1906 | /* while calculating len, pretend ':' is '\0' */ |
| 1907 | len = c - dev_name; |
| 1908 | if (len > NFS4_MAXNAMLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1909 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1910 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1911 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1912 | if (!args->nfs_server.hostname) |
| 1913 | goto out_nomem; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1914 | |
| 1915 | c++; /* step over the ':' */ |
| 1916 | len = strlen(c); |
| 1917 | if (len > NFS4_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1918 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1919 | args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL); |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1920 | if (!args->nfs_server.export_path) |
| 1921 | goto out_nomem; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1922 | |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1923 | dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1924 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1925 | if (args->client_address == NULL) |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1926 | goto out_no_client_address; |
| 1927 | |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1928 | break; |
| 1929 | } |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | return 0; |
| 1933 | |
| 1934 | out_no_data: |
| 1935 | dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n"); |
| 1936 | return -EINVAL; |
| 1937 | |
| 1938 | out_inval_auth: |
| 1939 | dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n", |
| 1940 | data->auth_flavourlen); |
| 1941 | return -EINVAL; |
| 1942 | |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1943 | out_nomem: |
| 1944 | dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n"); |
| 1945 | return -ENOMEM; |
| 1946 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1947 | out_no_address: |
| 1948 | dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); |
| 1949 | return -EINVAL; |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1950 | |
| 1951 | out_no_client_address: |
| 1952 | dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n"); |
| 1953 | return -EINVAL; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1957 | * Get the superblock for an NFS4 mountpoint |
| 1958 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1959 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 1960 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1961 | { |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1962 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1963 | struct super_block *s; |
| 1964 | struct nfs_server *server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1965 | struct nfs_fh mntfh; |
| 1966 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1967 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1968 | struct nfs_sb_mountdata sb_mntdata = { |
| 1969 | .mntflags = flags, |
| 1970 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1971 | int error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1972 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1973 | security_init_mnt_opts(&data.lsm_opts); |
| 1974 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1975 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1976 | error = nfs4_validate_mount_data(raw_data, &data, dev_name); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1977 | if (error < 0) |
| 1978 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1979 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1980 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1981 | server = nfs4_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1982 | if (IS_ERR(server)) { |
| 1983 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1984 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1985 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1986 | sb_mntdata.server = server; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1987 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1988 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 1989 | compare_super = NULL; |
| 1990 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1991 | /* 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] | 1992 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1993 | if (IS_ERR(s)) { |
| 1994 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1995 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1996 | } |
| 1997 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 1998 | if (s->s_fs_info != server) { |
| 1999 | nfs_free_server(server); |
| 2000 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2001 | } else { |
| 2002 | error = nfs_bdi_register(server); |
| 2003 | if (error) |
| 2004 | goto error_splat_super; |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 2005 | } |
| 2006 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2007 | if (!s->s_root) { |
| 2008 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2009 | nfs4_fill_super(s); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2010 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2011 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2012 | mntroot = nfs4_get_root(s, &mntfh); |
| 2013 | if (IS_ERR(mntroot)) { |
| 2014 | error = PTR_ERR(mntroot); |
| 2015 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2016 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2017 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2018 | error = security_sb_set_mnt_opts(s, &data.lsm_opts); |
| 2019 | if (error) |
| 2020 | goto error_splat_root; |
| 2021 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2022 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2023 | mnt->mnt_sb = s; |
| 2024 | mnt->mnt_root = mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2025 | error = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2026 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2027 | out: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2028 | kfree(data.client_address); |
| 2029 | kfree(data.nfs_server.export_path); |
| 2030 | kfree(data.nfs_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2031 | security_free_mnt_opts(&data.lsm_opts); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2032 | return error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2033 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2034 | out_free: |
| 2035 | nfs_free_server(server); |
| 2036 | goto out; |
| 2037 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2038 | error_splat_root: |
| 2039 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2040 | error_splat_super: |
| 2041 | up_write(&s->s_umount); |
| 2042 | deactivate_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2043 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | static void nfs4_kill_super(struct super_block *sb) |
| 2047 | { |
| 2048 | struct nfs_server *server = NFS_SB(sb); |
| 2049 | |
| 2050 | nfs_return_all_delegations(sb); |
| 2051 | kill_anon_super(sb); |
| 2052 | |
| 2053 | nfs4_renewd_prepare_shutdown(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2054 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2058 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2059 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2060 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 2061 | const char *dev_name, void *raw_data, |
| 2062 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2063 | { |
| 2064 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2065 | struct super_block *s; |
| 2066 | struct nfs_server *server; |
| 2067 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2068 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2069 | struct nfs_sb_mountdata sb_mntdata = { |
| 2070 | .mntflags = flags, |
| 2071 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2072 | int error; |
| 2073 | |
| 2074 | dprintk("--> nfs4_xdev_get_sb()\n"); |
| 2075 | |
| 2076 | /* create a new volume representation */ |
| 2077 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2078 | if (IS_ERR(server)) { |
| 2079 | error = PTR_ERR(server); |
| 2080 | goto out_err_noserver; |
| 2081 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2082 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2083 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2084 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2085 | compare_super = NULL; |
| 2086 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2087 | /* 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] | 2088 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2089 | if (IS_ERR(s)) { |
| 2090 | error = PTR_ERR(s); |
| 2091 | goto out_err_nosb; |
| 2092 | } |
| 2093 | |
| 2094 | if (s->s_fs_info != server) { |
| 2095 | nfs_free_server(server); |
| 2096 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2097 | } else { |
| 2098 | error = nfs_bdi_register(server); |
| 2099 | if (error) |
| 2100 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | if (!s->s_root) { |
| 2104 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2105 | nfs4_clone_super(s, data->sb); |
| 2106 | } |
| 2107 | |
| 2108 | mntroot = nfs4_get_root(s, data->fh); |
| 2109 | if (IS_ERR(mntroot)) { |
| 2110 | error = PTR_ERR(mntroot); |
| 2111 | goto error_splat_super; |
| 2112 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2113 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2114 | dput(mntroot); |
| 2115 | error = -ESTALE; |
| 2116 | goto error_splat_super; |
| 2117 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2118 | |
| 2119 | s->s_flags |= MS_ACTIVE; |
| 2120 | mnt->mnt_sb = s; |
| 2121 | mnt->mnt_root = mntroot; |
| 2122 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2123 | security_sb_clone_mnt_opts(data->sb, s); |
| 2124 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2125 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); |
| 2126 | return 0; |
| 2127 | |
| 2128 | out_err_nosb: |
| 2129 | nfs_free_server(server); |
| 2130 | out_err_noserver: |
| 2131 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); |
| 2132 | return error; |
| 2133 | |
| 2134 | error_splat_super: |
| 2135 | up_write(&s->s_umount); |
| 2136 | deactivate_super(s); |
| 2137 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
| 2138 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2139 | } |
| 2140 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2141 | /* |
| 2142 | * Create an NFS4 server record on referral traversal |
| 2143 | */ |
| 2144 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags, |
| 2145 | const char *dev_name, void *raw_data, |
| 2146 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2147 | { |
| 2148 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2149 | struct super_block *s; |
| 2150 | struct nfs_server *server; |
| 2151 | struct dentry *mntroot; |
| 2152 | struct nfs_fh mntfh; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2153 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2154 | struct nfs_sb_mountdata sb_mntdata = { |
| 2155 | .mntflags = flags, |
| 2156 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2157 | int error; |
| 2158 | |
| 2159 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2160 | |
| 2161 | /* create a new volume representation */ |
| 2162 | server = nfs4_create_referral_server(data, &mntfh); |
| 2163 | if (IS_ERR(server)) { |
| 2164 | error = PTR_ERR(server); |
| 2165 | goto out_err_noserver; |
| 2166 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2167 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2168 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2169 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2170 | compare_super = NULL; |
| 2171 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2172 | /* 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] | 2173 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2174 | if (IS_ERR(s)) { |
| 2175 | error = PTR_ERR(s); |
| 2176 | goto out_err_nosb; |
| 2177 | } |
| 2178 | |
| 2179 | if (s->s_fs_info != server) { |
| 2180 | nfs_free_server(server); |
| 2181 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2182 | } else { |
| 2183 | error = nfs_bdi_register(server); |
| 2184 | if (error) |
| 2185 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | if (!s->s_root) { |
| 2189 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2190 | nfs4_fill_super(s); |
| 2191 | } |
| 2192 | |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 2193 | mntroot = nfs4_get_root(s, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2194 | if (IS_ERR(mntroot)) { |
| 2195 | error = PTR_ERR(mntroot); |
| 2196 | goto error_splat_super; |
| 2197 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2198 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2199 | dput(mntroot); |
| 2200 | error = -ESTALE; |
| 2201 | goto error_splat_super; |
| 2202 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2203 | |
| 2204 | s->s_flags |= MS_ACTIVE; |
| 2205 | mnt->mnt_sb = s; |
| 2206 | mnt->mnt_root = mntroot; |
| 2207 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2208 | security_sb_clone_mnt_opts(data->sb, s); |
| 2209 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2210 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
| 2211 | return 0; |
| 2212 | |
| 2213 | out_err_nosb: |
| 2214 | nfs_free_server(server); |
| 2215 | out_err_noserver: |
| 2216 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
| 2217 | return error; |
| 2218 | |
| 2219 | error_splat_super: |
| 2220 | up_write(&s->s_umount); |
| 2221 | deactivate_super(s); |
| 2222 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
| 2223 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2224 | } |
| 2225 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2226 | #endif /* CONFIG_NFS_V4 */ |