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