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, |
| 86 | Opt_mountprog, Opt_mountvers, |
| 87 | Opt_nfsprog, Opt_nfsvers, |
| 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" }, |
| 140 | { Opt_mountprog, "mountprog=%u" }, |
| 141 | { Opt_mountvers, "mountvers=%u" }, |
| 142 | { Opt_nfsprog, "nfsprog=%u" }, |
| 143 | { Opt_nfsvers, "nfsvers=%u" }, |
| 144 | { Opt_nfsvers, "vers=%u" }, |
| 145 | |
| 146 | { Opt_sec, "sec=%s" }, |
| 147 | { Opt_proto, "proto=%s" }, |
| 148 | { Opt_mountproto, "mountproto=%s" }, |
| 149 | { Opt_addr, "addr=%s" }, |
| 150 | { Opt_clientaddr, "clientaddr=%s" }, |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 151 | { Opt_userspace, "mounthost=%s" }, |
| 152 | { Opt_mountaddr, "mountaddr=%s" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 153 | |
| 154 | { Opt_err, NULL } |
| 155 | }; |
| 156 | |
| 157 | enum { |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 158 | Opt_xprt_udp, Opt_xprt_tcp, Opt_xprt_rdma, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 159 | |
| 160 | Opt_xprt_err |
| 161 | }; |
| 162 | |
| 163 | static match_table_t nfs_xprt_protocol_tokens = { |
| 164 | { Opt_xprt_udp, "udp" }, |
| 165 | { Opt_xprt_tcp, "tcp" }, |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 166 | { Opt_xprt_rdma, "rdma" }, |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 167 | |
| 168 | { Opt_xprt_err, NULL } |
| 169 | }; |
| 170 | |
| 171 | enum { |
| 172 | Opt_sec_none, Opt_sec_sys, |
| 173 | Opt_sec_krb5, Opt_sec_krb5i, Opt_sec_krb5p, |
| 174 | Opt_sec_lkey, Opt_sec_lkeyi, Opt_sec_lkeyp, |
| 175 | Opt_sec_spkm, Opt_sec_spkmi, Opt_sec_spkmp, |
| 176 | |
| 177 | Opt_sec_err |
| 178 | }; |
| 179 | |
| 180 | static match_table_t nfs_secflavor_tokens = { |
| 181 | { Opt_sec_none, "none" }, |
| 182 | { Opt_sec_none, "null" }, |
| 183 | { Opt_sec_sys, "sys" }, |
| 184 | |
| 185 | { Opt_sec_krb5, "krb5" }, |
| 186 | { Opt_sec_krb5i, "krb5i" }, |
| 187 | { Opt_sec_krb5p, "krb5p" }, |
| 188 | |
| 189 | { Opt_sec_lkey, "lkey" }, |
| 190 | { Opt_sec_lkeyi, "lkeyi" }, |
| 191 | { Opt_sec_lkeyp, "lkeyp" }, |
| 192 | |
| 193 | { Opt_sec_err, NULL } |
| 194 | }; |
| 195 | |
| 196 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 197 | static void nfs_umount_begin(struct vfsmount *, int); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 198 | static int nfs_statfs(struct dentry *, struct kstatfs *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 199 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
| 200 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 201 | 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] | 202 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 203 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 204 | static void nfs_kill_super(struct super_block *); |
| 205 | |
| 206 | static struct file_system_type nfs_fs_type = { |
| 207 | .owner = THIS_MODULE, |
| 208 | .name = "nfs", |
| 209 | .get_sb = nfs_get_sb, |
| 210 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 211 | .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] | 212 | }; |
| 213 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 214 | struct file_system_type nfs_xdev_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 215 | .owner = THIS_MODULE, |
| 216 | .name = "nfs", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 217 | .get_sb = nfs_xdev_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 218 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 219 | .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] | 220 | }; |
| 221 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 222 | static const struct super_operations nfs_sops = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 223 | .alloc_inode = nfs_alloc_inode, |
| 224 | .destroy_inode = nfs_destroy_inode, |
| 225 | .write_inode = nfs_write_inode, |
| 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 | |
| 328 | /* |
| 329 | * Deliver file system statistics to userspace |
| 330 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 331 | static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 332 | { |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 333 | struct nfs_server *server = NFS_SB(dentry->d_sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 334 | unsigned char blockbits; |
| 335 | unsigned long blockres; |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 336 | struct nfs_fh *fh = NFS_FH(dentry->d_inode); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 337 | struct nfs_fattr fattr; |
| 338 | struct nfs_fsstat res = { |
| 339 | .fattr = &fattr, |
| 340 | }; |
| 341 | int error; |
| 342 | |
| 343 | lock_kernel(); |
| 344 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 345 | error = server->nfs_client->rpc_ops->statfs(server, fh, &res); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 346 | if (error < 0) |
| 347 | goto out_err; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 348 | buf->f_type = NFS_SUPER_MAGIC; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * Current versions of glibc do not correctly handle the |
| 352 | * case where f_frsize != f_bsize. Eventually we want to |
| 353 | * report the value of wtmult in this field. |
| 354 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 355 | buf->f_frsize = dentry->d_sb->s_blocksize; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 356 | |
| 357 | /* |
| 358 | * On most *nix systems, f_blocks, f_bfree, and f_bavail |
| 359 | * are reported in units of f_frsize. Linux hasn't had |
| 360 | * an f_frsize field in its statfs struct until recently, |
| 361 | * thus historically Linux's sys_statfs reports these |
| 362 | * fields in units of f_bsize. |
| 363 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 364 | buf->f_bsize = dentry->d_sb->s_blocksize; |
| 365 | blockbits = dentry->d_sb->s_blocksize_bits; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 366 | blockres = (1 << blockbits) - 1; |
| 367 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; |
| 368 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; |
| 369 | buf->f_bavail = (res.abytes + blockres) >> blockbits; |
| 370 | |
| 371 | buf->f_files = res.tfiles; |
| 372 | buf->f_ffree = res.afiles; |
| 373 | |
| 374 | buf->f_namelen = server->namelen; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 375 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 376 | unlock_kernel(); |
| 377 | return 0; |
| 378 | |
| 379 | out_err: |
| 380 | dprintk("%s: statfs error = %d\n", __FUNCTION__, -error); |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 381 | unlock_kernel(); |
| 382 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 383 | } |
| 384 | |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 385 | /* |
| 386 | * Map the security flavour number to a name |
| 387 | */ |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 388 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) |
| 389 | { |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 390 | static const struct { |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 391 | rpc_authflavor_t flavour; |
| 392 | const char *str; |
| 393 | } sec_flavours[] = { |
| 394 | { RPC_AUTH_NULL, "null" }, |
| 395 | { RPC_AUTH_UNIX, "sys" }, |
| 396 | { RPC_AUTH_GSS_KRB5, "krb5" }, |
| 397 | { RPC_AUTH_GSS_KRB5I, "krb5i" }, |
| 398 | { RPC_AUTH_GSS_KRB5P, "krb5p" }, |
| 399 | { RPC_AUTH_GSS_LKEY, "lkey" }, |
| 400 | { RPC_AUTH_GSS_LKEYI, "lkeyi" }, |
| 401 | { RPC_AUTH_GSS_LKEYP, "lkeyp" }, |
| 402 | { RPC_AUTH_GSS_SPKM, "spkm" }, |
| 403 | { RPC_AUTH_GSS_SPKMI, "spkmi" }, |
| 404 | { RPC_AUTH_GSS_SPKMP, "spkmp" }, |
Chuck Lever | 4d81cd1 | 2007-07-01 12:12:40 -0400 | [diff] [blame] | 405 | { UINT_MAX, "unknown" } |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 406 | }; |
| 407 | int i; |
| 408 | |
Chuck Lever | 4d81cd1 | 2007-07-01 12:12:40 -0400 | [diff] [blame] | 409 | for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) { |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 410 | if (sec_flavours[i].flavour == flavour) |
| 411 | break; |
| 412 | } |
| 413 | return sec_flavours[i].str; |
| 414 | } |
| 415 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 416 | /* |
| 417 | * Describe the mount options in force on this server representation |
| 418 | */ |
| 419 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) |
| 420 | { |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 421 | static const struct proc_nfs_info { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 422 | int flag; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 423 | const char *str; |
| 424 | const char *nostr; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 425 | } nfs_info[] = { |
| 426 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
Chuck Lever | bcf3561 | 2007-09-24 15:39:55 -0400 | [diff] [blame] | 427 | { NFS_MOUNT_INTR, ",intr", ",nointr" }, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 428 | { NFS_MOUNT_NOCTO, ",nocto", "" }, |
| 429 | { NFS_MOUNT_NOAC, ",noac", "" }, |
| 430 | { NFS_MOUNT_NONLM, ",nolock", "" }, |
| 431 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
Steve Dickson | 74dd34e | 2007-04-14 17:01:15 -0400 | [diff] [blame] | 432 | { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 433 | { NFS_MOUNT_UNSHARED, ",nosharecache", ""}, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 434 | { 0, NULL, NULL } |
| 435 | }; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 436 | const struct proc_nfs_info *nfs_infop; |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 437 | struct nfs_client *clp = nfss->nfs_client; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 438 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 439 | seq_printf(m, ",vers=%d", clp->rpc_ops->version); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 440 | seq_printf(m, ",rsize=%d", nfss->rsize); |
| 441 | seq_printf(m, ",wsize=%d", nfss->wsize); |
| 442 | if (nfss->acregmin != 3*HZ || showdefaults) |
| 443 | seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ); |
| 444 | if (nfss->acregmax != 60*HZ || showdefaults) |
| 445 | seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ); |
| 446 | if (nfss->acdirmin != 30*HZ || showdefaults) |
| 447 | seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ); |
| 448 | if (nfss->acdirmax != 60*HZ || showdefaults) |
| 449 | seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ); |
| 450 | for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { |
| 451 | if (nfss->flags & nfs_infop->flag) |
| 452 | seq_puts(m, nfs_infop->str); |
| 453 | else |
| 454 | seq_puts(m, nfs_infop->nostr); |
| 455 | } |
\"Talpey, Thomas\ | 56928ed | 2007-09-10 13:48:47 -0400 | [diff] [blame] | 456 | seq_printf(m, ",proto=%s", |
| 457 | rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO)); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 458 | seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ); |
| 459 | seq_printf(m, ",retrans=%u", clp->retrans_count); |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 460 | 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] | 461 | } |
| 462 | |
| 463 | /* |
| 464 | * Describe the mount options on this VFS mountpoint |
| 465 | */ |
| 466 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 467 | { |
| 468 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 469 | |
| 470 | nfs_show_mount_options(m, nfss, 0); |
| 471 | |
Jeff Layton | ddc01c0 | 2007-07-30 08:47:38 -0400 | [diff] [blame] | 472 | seq_printf(m, ",addr="NIPQUAD_FMT, |
| 473 | NIPQUAD(nfss->nfs_client->cl_addr.sin_addr)); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * Present statistical information for this VFS mountpoint |
| 480 | */ |
| 481 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 482 | { |
| 483 | int i, cpu; |
| 484 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 485 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 486 | struct nfs_iostats totals = { }; |
| 487 | |
| 488 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 489 | |
| 490 | /* |
| 491 | * Display all mount option settings |
| 492 | */ |
| 493 | seq_printf(m, "\n\topts:\t"); |
| 494 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 495 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 496 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 497 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 498 | nfs_show_mount_options(m, nfss, 1); |
| 499 | |
| 500 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 501 | |
| 502 | seq_printf(m, "\n\tcaps:\t"); |
| 503 | seq_printf(m, "caps=0x%x", nfss->caps); |
| 504 | seq_printf(m, ",wtmult=%d", nfss->wtmult); |
| 505 | seq_printf(m, ",dtsize=%d", nfss->dtsize); |
| 506 | seq_printf(m, ",bsize=%d", nfss->bsize); |
| 507 | seq_printf(m, ",namelen=%d", nfss->namelen); |
| 508 | |
| 509 | #ifdef CONFIG_NFS_V4 |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 510 | if (nfss->nfs_client->cl_nfsversion == 4) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 511 | seq_printf(m, "\n\tnfsv4:\t"); |
| 512 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 513 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 514 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 515 | } |
| 516 | #endif |
| 517 | |
| 518 | /* |
| 519 | * Display security flavor in effect for this mount |
| 520 | */ |
| 521 | seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor); |
| 522 | if (auth->au_flavor) |
| 523 | seq_printf(m, ",pseudoflavor=%d", auth->au_flavor); |
| 524 | |
| 525 | /* |
| 526 | * Display superblock I/O counters |
| 527 | */ |
| 528 | for_each_possible_cpu(cpu) { |
| 529 | struct nfs_iostats *stats; |
| 530 | |
| 531 | preempt_disable(); |
| 532 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 533 | |
| 534 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 535 | totals.events[i] += stats->events[i]; |
| 536 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 537 | totals.bytes[i] += stats->bytes[i]; |
| 538 | |
| 539 | preempt_enable(); |
| 540 | } |
| 541 | |
| 542 | seq_printf(m, "\n\tevents:\t"); |
| 543 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 544 | seq_printf(m, "%lu ", totals.events[i]); |
| 545 | seq_printf(m, "\n\tbytes:\t"); |
| 546 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 547 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 548 | seq_printf(m, "\n"); |
| 549 | |
| 550 | rpc_print_iostats(m, nfss->client); |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /* |
| 556 | * Begin unmount by attempting to remove all automounted mountpoints we added |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 557 | * in response to xdev traversals and referrals |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 558 | */ |
| 559 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) |
| 560 | { |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 561 | struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb); |
| 562 | struct rpc_clnt *rpc; |
| 563 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 564 | shrink_submounts(vfsmnt, &nfs_automount_list); |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 565 | |
| 566 | if (!(flags & MNT_FORCE)) |
| 567 | return; |
| 568 | /* -EIO all pending I/O */ |
| 569 | rpc = server->client_acl; |
| 570 | if (!IS_ERR(rpc)) |
| 571 | rpc_killall_tasks(rpc); |
| 572 | rpc = server->client; |
| 573 | if (!IS_ERR(rpc)) |
| 574 | rpc_killall_tasks(rpc); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 578 | * Sanity-check a server address provided by the mount command |
| 579 | */ |
| 580 | static int nfs_verify_server_address(struct sockaddr *addr) |
| 581 | { |
| 582 | switch (addr->sa_family) { |
| 583 | case AF_INET: { |
| 584 | struct sockaddr_in *sa = (struct sockaddr_in *) addr; |
| 585 | if (sa->sin_addr.s_addr != INADDR_ANY) |
| 586 | return 1; |
| 587 | break; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | /* |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 595 | * Error-check and convert a string of mount options from user space into |
| 596 | * a data structure |
| 597 | */ |
| 598 | static int nfs_parse_mount_options(char *raw, |
| 599 | struct nfs_parsed_mount_data *mnt) |
| 600 | { |
| 601 | char *p, *string; |
| 602 | |
| 603 | if (!raw) { |
| 604 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 605 | return 1; |
| 606 | } |
| 607 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 608 | |
| 609 | while ((p = strsep(&raw, ",")) != NULL) { |
| 610 | substring_t args[MAX_OPT_ARGS]; |
| 611 | int option, token; |
| 612 | |
| 613 | if (!*p) |
| 614 | continue; |
| 615 | |
| 616 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 617 | |
| 618 | token = match_token(p, nfs_mount_option_tokens, args); |
| 619 | switch (token) { |
| 620 | case Opt_soft: |
| 621 | mnt->flags |= NFS_MOUNT_SOFT; |
| 622 | break; |
| 623 | case Opt_hard: |
| 624 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 625 | break; |
| 626 | case Opt_intr: |
| 627 | mnt->flags |= NFS_MOUNT_INTR; |
| 628 | break; |
| 629 | case Opt_nointr: |
| 630 | mnt->flags &= ~NFS_MOUNT_INTR; |
| 631 | break; |
| 632 | case Opt_posix: |
| 633 | mnt->flags |= NFS_MOUNT_POSIX; |
| 634 | break; |
| 635 | case Opt_noposix: |
| 636 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 637 | break; |
| 638 | case Opt_cto: |
| 639 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 640 | break; |
| 641 | case Opt_nocto: |
| 642 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 643 | break; |
| 644 | case Opt_ac: |
| 645 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 646 | break; |
| 647 | case Opt_noac: |
| 648 | mnt->flags |= NFS_MOUNT_NOAC; |
| 649 | break; |
| 650 | case Opt_lock: |
| 651 | mnt->flags &= ~NFS_MOUNT_NONLM; |
| 652 | break; |
| 653 | case Opt_nolock: |
| 654 | mnt->flags |= NFS_MOUNT_NONLM; |
| 655 | break; |
| 656 | case Opt_v2: |
| 657 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 658 | break; |
| 659 | case Opt_v3: |
| 660 | mnt->flags |= NFS_MOUNT_VER3; |
| 661 | break; |
| 662 | case Opt_udp: |
| 663 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 664 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 665 | mnt->timeo = 7; |
| 666 | mnt->retrans = 5; |
| 667 | break; |
| 668 | case Opt_tcp: |
| 669 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 670 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 671 | mnt->timeo = 600; |
| 672 | mnt->retrans = 2; |
| 673 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 674 | case Opt_rdma: |
| 675 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 676 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 677 | mnt->timeo = 600; |
| 678 | mnt->retrans = 2; |
| 679 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 680 | case Opt_acl: |
| 681 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 682 | break; |
| 683 | case Opt_noacl: |
| 684 | mnt->flags |= NFS_MOUNT_NOACL; |
| 685 | break; |
| 686 | case Opt_rdirplus: |
| 687 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 688 | break; |
| 689 | case Opt_nordirplus: |
| 690 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 691 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 692 | case Opt_sharecache: |
| 693 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 694 | break; |
| 695 | case Opt_nosharecache: |
| 696 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 697 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 698 | |
| 699 | case Opt_port: |
| 700 | if (match_int(args, &option)) |
| 701 | return 0; |
| 702 | if (option < 0 || option > 65535) |
| 703 | return 0; |
Al Viro | 4108964 | 2007-07-22 10:59:06 +0100 | [diff] [blame] | 704 | mnt->nfs_server.address.sin_port = htons(option); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 705 | break; |
| 706 | case Opt_rsize: |
| 707 | if (match_int(args, &mnt->rsize)) |
| 708 | return 0; |
| 709 | break; |
| 710 | case Opt_wsize: |
| 711 | if (match_int(args, &mnt->wsize)) |
| 712 | return 0; |
| 713 | break; |
| 714 | case Opt_bsize: |
| 715 | if (match_int(args, &option)) |
| 716 | return 0; |
| 717 | if (option < 0) |
| 718 | return 0; |
| 719 | mnt->bsize = option; |
| 720 | break; |
| 721 | case Opt_timeo: |
| 722 | if (match_int(args, &mnt->timeo)) |
| 723 | return 0; |
| 724 | break; |
| 725 | case Opt_retrans: |
| 726 | if (match_int(args, &mnt->retrans)) |
| 727 | return 0; |
| 728 | break; |
| 729 | case Opt_acregmin: |
| 730 | if (match_int(args, &mnt->acregmin)) |
| 731 | return 0; |
| 732 | break; |
| 733 | case Opt_acregmax: |
| 734 | if (match_int(args, &mnt->acregmax)) |
| 735 | return 0; |
| 736 | break; |
| 737 | case Opt_acdirmin: |
| 738 | if (match_int(args, &mnt->acdirmin)) |
| 739 | return 0; |
| 740 | break; |
| 741 | case Opt_acdirmax: |
| 742 | if (match_int(args, &mnt->acdirmax)) |
| 743 | return 0; |
| 744 | break; |
| 745 | case Opt_actimeo: |
| 746 | if (match_int(args, &option)) |
| 747 | return 0; |
| 748 | if (option < 0) |
| 749 | return 0; |
| 750 | mnt->acregmin = |
| 751 | mnt->acregmax = |
| 752 | mnt->acdirmin = |
| 753 | mnt->acdirmax = option; |
| 754 | break; |
| 755 | case Opt_namelen: |
| 756 | if (match_int(args, &mnt->namlen)) |
| 757 | return 0; |
| 758 | break; |
| 759 | case Opt_mountport: |
| 760 | if (match_int(args, &option)) |
| 761 | return 0; |
| 762 | if (option < 0 || option > 65535) |
| 763 | return 0; |
| 764 | mnt->mount_server.port = option; |
| 765 | break; |
| 766 | case Opt_mountprog: |
| 767 | if (match_int(args, &option)) |
| 768 | return 0; |
| 769 | if (option < 0) |
| 770 | return 0; |
| 771 | mnt->mount_server.program = option; |
| 772 | break; |
| 773 | case Opt_mountvers: |
| 774 | if (match_int(args, &option)) |
| 775 | return 0; |
| 776 | if (option < 0) |
| 777 | return 0; |
| 778 | mnt->mount_server.version = option; |
| 779 | break; |
| 780 | case Opt_nfsprog: |
| 781 | if (match_int(args, &option)) |
| 782 | return 0; |
| 783 | if (option < 0) |
| 784 | return 0; |
| 785 | mnt->nfs_server.program = option; |
| 786 | break; |
| 787 | case Opt_nfsvers: |
| 788 | if (match_int(args, &option)) |
| 789 | return 0; |
| 790 | switch (option) { |
| 791 | case 2: |
| 792 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 793 | break; |
| 794 | case 3: |
| 795 | mnt->flags |= NFS_MOUNT_VER3; |
| 796 | break; |
| 797 | default: |
| 798 | goto out_unrec_vers; |
| 799 | } |
| 800 | break; |
| 801 | |
| 802 | case Opt_sec: |
| 803 | string = match_strdup(args); |
| 804 | if (string == NULL) |
| 805 | goto out_nomem; |
| 806 | token = match_token(string, nfs_secflavor_tokens, args); |
| 807 | kfree(string); |
| 808 | |
| 809 | /* |
| 810 | * The flags setting is for v2/v3. The flavor_len |
| 811 | * setting is for v4. v2/v3 also need to know the |
| 812 | * difference between NULL and UNIX. |
| 813 | */ |
| 814 | switch (token) { |
| 815 | case Opt_sec_none: |
| 816 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 817 | mnt->auth_flavor_len = 0; |
| 818 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 819 | break; |
| 820 | case Opt_sec_sys: |
| 821 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 822 | mnt->auth_flavor_len = 0; |
| 823 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 824 | break; |
| 825 | case Opt_sec_krb5: |
| 826 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 827 | mnt->auth_flavor_len = 1; |
| 828 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 829 | break; |
| 830 | case Opt_sec_krb5i: |
| 831 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 832 | mnt->auth_flavor_len = 1; |
| 833 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 834 | break; |
| 835 | case Opt_sec_krb5p: |
| 836 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 837 | mnt->auth_flavor_len = 1; |
| 838 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 839 | break; |
| 840 | case Opt_sec_lkey: |
| 841 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 842 | mnt->auth_flavor_len = 1; |
| 843 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 844 | break; |
| 845 | case Opt_sec_lkeyi: |
| 846 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 847 | mnt->auth_flavor_len = 1; |
| 848 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 849 | break; |
| 850 | case Opt_sec_lkeyp: |
| 851 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 852 | mnt->auth_flavor_len = 1; |
| 853 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 854 | break; |
| 855 | case Opt_sec_spkm: |
| 856 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 857 | mnt->auth_flavor_len = 1; |
| 858 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 859 | break; |
| 860 | case Opt_sec_spkmi: |
| 861 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 862 | mnt->auth_flavor_len = 1; |
| 863 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 864 | break; |
| 865 | case Opt_sec_spkmp: |
| 866 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 867 | mnt->auth_flavor_len = 1; |
| 868 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 869 | break; |
| 870 | default: |
| 871 | goto out_unrec_sec; |
| 872 | } |
| 873 | break; |
| 874 | case Opt_proto: |
| 875 | string = match_strdup(args); |
| 876 | if (string == NULL) |
| 877 | goto out_nomem; |
| 878 | token = match_token(string, |
| 879 | nfs_xprt_protocol_tokens, args); |
| 880 | kfree(string); |
| 881 | |
| 882 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 883 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 884 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 885 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 886 | mnt->timeo = 7; |
| 887 | mnt->retrans = 5; |
| 888 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 889 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 890 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 891 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 892 | mnt->timeo = 600; |
| 893 | mnt->retrans = 2; |
| 894 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 895 | case Opt_xprt_rdma: |
| 896 | /* vector side protocols to TCP */ |
| 897 | mnt->flags |= NFS_MOUNT_TCP; |
| 898 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 899 | mnt->timeo = 600; |
| 900 | mnt->retrans = 2; |
| 901 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 902 | default: |
| 903 | goto out_unrec_xprt; |
| 904 | } |
| 905 | break; |
| 906 | case Opt_mountproto: |
| 907 | string = match_strdup(args); |
| 908 | if (string == NULL) |
| 909 | goto out_nomem; |
| 910 | token = match_token(string, |
| 911 | nfs_xprt_protocol_tokens, args); |
| 912 | kfree(string); |
| 913 | |
| 914 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 915 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 916 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 917 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 918 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 919 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 920 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 921 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 922 | default: |
| 923 | goto out_unrec_xprt; |
| 924 | } |
| 925 | break; |
| 926 | case Opt_addr: |
| 927 | string = match_strdup(args); |
| 928 | if (string == NULL) |
| 929 | goto out_nomem; |
| 930 | mnt->nfs_server.address.sin_family = AF_INET; |
| 931 | mnt->nfs_server.address.sin_addr.s_addr = |
| 932 | in_aton(string); |
| 933 | kfree(string); |
| 934 | break; |
| 935 | case Opt_clientaddr: |
| 936 | string = match_strdup(args); |
| 937 | if (string == NULL) |
| 938 | goto out_nomem; |
| 939 | mnt->client_address = string; |
| 940 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 941 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 942 | string = match_strdup(args); |
| 943 | if (string == NULL) |
| 944 | goto out_nomem; |
| 945 | mnt->mount_server.address.sin_family = AF_INET; |
| 946 | mnt->mount_server.address.sin_addr.s_addr = |
| 947 | in_aton(string); |
| 948 | kfree(string); |
| 949 | break; |
| 950 | |
| 951 | case Opt_userspace: |
| 952 | case Opt_deprecated: |
| 953 | break; |
| 954 | |
| 955 | default: |
| 956 | goto out_unknown; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | return 1; |
| 961 | |
| 962 | out_nomem: |
| 963 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| 964 | return 0; |
| 965 | |
| 966 | out_unrec_vers: |
| 967 | printk(KERN_INFO "NFS: unrecognized NFS version number\n"); |
| 968 | return 0; |
| 969 | |
| 970 | out_unrec_xprt: |
| 971 | printk(KERN_INFO "NFS: unrecognized transport protocol\n"); |
| 972 | return 0; |
| 973 | |
| 974 | out_unrec_sec: |
| 975 | printk(KERN_INFO "NFS: unrecognized security flavor\n"); |
| 976 | return 0; |
| 977 | |
| 978 | out_unknown: |
| 979 | printk(KERN_INFO "NFS: unknown mount option: %s\n", p); |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | /* |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 984 | * Use the remote server's MOUNT service to request the NFS file handle |
| 985 | * corresponding to the provided path. |
| 986 | */ |
| 987 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 988 | struct nfs_fh *root_fh) |
| 989 | { |
| 990 | struct sockaddr_in sin; |
| 991 | int status; |
| 992 | |
| 993 | if (args->mount_server.version == 0) { |
| 994 | if (args->flags & NFS_MOUNT_VER3) |
| 995 | args->mount_server.version = NFS_MNT3_VERSION; |
| 996 | else |
| 997 | args->mount_server.version = NFS_MNT_VERSION; |
| 998 | } |
| 999 | |
| 1000 | /* |
| 1001 | * Construct the mount server's address. |
| 1002 | */ |
| 1003 | if (args->mount_server.address.sin_addr.s_addr != INADDR_ANY) |
| 1004 | sin = args->mount_server.address; |
| 1005 | else |
| 1006 | sin = args->nfs_server.address; |
James Lentini | aad7000 | 2007-09-24 17:32:49 -0400 | [diff] [blame] | 1007 | /* |
| 1008 | * autobind will be used if mount_server.port == 0 |
| 1009 | */ |
| 1010 | sin.sin_port = htons(args->mount_server.port); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1011 | |
| 1012 | /* |
| 1013 | * Now ask the mount server to map our export path |
| 1014 | * to a file handle. |
| 1015 | */ |
| 1016 | status = nfs_mount((struct sockaddr *) &sin, |
| 1017 | sizeof(sin), |
| 1018 | args->nfs_server.hostname, |
| 1019 | args->nfs_server.export_path, |
| 1020 | args->mount_server.version, |
| 1021 | args->mount_server.protocol, |
| 1022 | root_fh); |
Chuck Lever | efd8340 | 2007-09-11 18:00:58 -0400 | [diff] [blame] | 1023 | if (status == 0) |
| 1024 | return 0; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1025 | |
Chuck Lever | efd8340 | 2007-09-11 18:00:58 -0400 | [diff] [blame] | 1026 | dfprintk(MOUNT, "NFS: unable to mount server " NIPQUAD_FMT |
| 1027 | ", error %d\n", NIPQUAD(sin.sin_addr.s_addr), status); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1028 | return status; |
| 1029 | } |
| 1030 | |
| 1031 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1032 | * Validate the NFS2/NFS3 mount data |
| 1033 | * - fills in the mount root filehandle |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1034 | * |
| 1035 | * For option strings, user space handles the following behaviors: |
| 1036 | * |
| 1037 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 1038 | * |
| 1039 | * + failure mode: how to behave if a mount request can't be handled |
| 1040 | * immediately ("fg/bg" option) |
| 1041 | * |
| 1042 | * + retry: how often to retry a mount request ("retry=" option) |
| 1043 | * |
| 1044 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 1045 | * mountproto=tcp after mountproto=udp, and so on |
| 1046 | * |
| 1047 | * XXX: as far as I can tell, changing the NFS program number is not |
| 1048 | * supported in the NFS client. |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1049 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1050 | static int nfs_validate_mount_data(void *options, |
| 1051 | struct nfs_parsed_mount_data *args, |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1052 | struct nfs_fh *mntfh, |
| 1053 | const char *dev_name) |
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 | struct nfs_mount_data *data = (struct nfs_mount_data *)options; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1056 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1057 | memset(args, 0, sizeof(*args)); |
| 1058 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1059 | if (data == NULL) |
| 1060 | goto out_no_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1061 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1062 | args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP); |
| 1063 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1064 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1065 | args->timeo = 600; |
| 1066 | args->retrans = 2; |
| 1067 | args->acregmin = 3; |
| 1068 | args->acregmax = 60; |
| 1069 | args->acdirmin = 30; |
| 1070 | args->acdirmax = 60; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1071 | args->mount_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1072 | args->mount_server.program = NFS_MNT_PROGRAM; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1073 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1074 | args->nfs_server.program = NFS_PROGRAM; |
| 1075 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1076 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1077 | case 1: |
| 1078 | data->namlen = 0; |
| 1079 | case 2: |
| 1080 | data->bsize = 0; |
| 1081 | case 3: |
| 1082 | if (data->flags & NFS_MOUNT_VER3) |
| 1083 | goto out_no_v3; |
| 1084 | data->root.size = NFS2_FHSIZE; |
| 1085 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1086 | case 4: |
| 1087 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1088 | goto out_no_sec; |
| 1089 | case 5: |
| 1090 | memset(data->context, 0, sizeof(data->context)); |
| 1091 | case 6: |
| 1092 | if (data->flags & NFS_MOUNT_VER3) |
| 1093 | mntfh->size = data->root.size; |
| 1094 | else |
| 1095 | mntfh->size = NFS2_FHSIZE; |
| 1096 | |
| 1097 | if (mntfh->size > sizeof(mntfh->data)) |
| 1098 | goto out_invalid_fh; |
| 1099 | |
| 1100 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1101 | if (mntfh->size < sizeof(mntfh->data)) |
| 1102 | memset(mntfh->data + mntfh->size, 0, |
| 1103 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1104 | |
| 1105 | if (!nfs_verify_server_address((struct sockaddr *) &data->addr)) |
| 1106 | goto out_no_address; |
| 1107 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1108 | /* |
| 1109 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1110 | * can deal with. |
| 1111 | */ |
| 1112 | args->flags = data->flags; |
| 1113 | args->rsize = data->rsize; |
| 1114 | args->wsize = data->wsize; |
| 1115 | args->flags = data->flags; |
| 1116 | args->timeo = data->timeo; |
| 1117 | args->retrans = data->retrans; |
| 1118 | args->acregmin = data->acregmin; |
| 1119 | args->acregmax = data->acregmax; |
| 1120 | args->acdirmin = data->acdirmin; |
| 1121 | args->acdirmax = data->acdirmax; |
| 1122 | args->nfs_server.address = data->addr; |
| 1123 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1124 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1125 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1126 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1127 | args->namlen = data->namlen; |
| 1128 | args->bsize = data->bsize; |
| 1129 | args->auth_flavors[0] = data->pseudoflavor; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1130 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1131 | default: { |
| 1132 | unsigned int len; |
| 1133 | char *c; |
| 1134 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1135 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1136 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1137 | return -EINVAL; |
| 1138 | |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1139 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1140 | &args->nfs_server.address)) |
| 1141 | goto out_no_address; |
| 1142 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1143 | c = strchr(dev_name, ':'); |
| 1144 | if (c == NULL) |
| 1145 | return -EINVAL; |
Chuck Lever | 350c73a | 2007-08-29 17:59:01 -0400 | [diff] [blame] | 1146 | len = c - dev_name; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1147 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1148 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1149 | |
| 1150 | c++; |
| 1151 | if (strlen(c) > NFS_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1152 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1153 | args->nfs_server.export_path = c; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1154 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1155 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1156 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1157 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1158 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1159 | break; |
| 1160 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1161 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1162 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1163 | if (!(args->flags & NFS_MOUNT_SECFLAVOUR)) |
| 1164 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Trond Myklebust | 36b15c5 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1165 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1166 | #ifndef CONFIG_NFS_V3 |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1167 | if (args->flags & NFS_MOUNT_VER3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1168 | goto out_v3_not_compiled; |
| 1169 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1170 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1171 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1172 | |
| 1173 | out_no_data: |
| 1174 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1175 | return -EINVAL; |
| 1176 | |
| 1177 | out_no_v3: |
| 1178 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1179 | data->version); |
| 1180 | return -EINVAL; |
| 1181 | |
| 1182 | out_no_sec: |
| 1183 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1184 | return -EINVAL; |
| 1185 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1186 | #ifndef CONFIG_NFS_V3 |
| 1187 | out_v3_not_compiled: |
| 1188 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1189 | return -EPROTONOSUPPORT; |
| 1190 | #endif /* !CONFIG_NFS_V3 */ |
| 1191 | |
| 1192 | out_no_address: |
| 1193 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1194 | return -EINVAL; |
| 1195 | |
| 1196 | out_invalid_fh: |
| 1197 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1198 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | /* |
| 1202 | * Initialise the common bits of the superblock |
| 1203 | */ |
| 1204 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 1205 | { |
| 1206 | struct nfs_server *server = NFS_SB(sb); |
| 1207 | |
| 1208 | sb->s_magic = NFS_SUPER_MAGIC; |
| 1209 | |
| 1210 | /* We probably want something more informative here */ |
| 1211 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 1212 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 1213 | |
| 1214 | if (sb->s_blocksize == 0) |
| 1215 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 1216 | &sb->s_blocksize_bits); |
| 1217 | |
| 1218 | if (server->flags & NFS_MOUNT_NOAC) |
| 1219 | sb->s_flags |= MS_SYNCHRONOUS; |
| 1220 | |
| 1221 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 1222 | } |
| 1223 | |
| 1224 | /* |
| 1225 | * Finish setting up an NFS2/3 superblock |
| 1226 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1227 | static void nfs_fill_super(struct super_block *sb, |
| 1228 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1229 | { |
| 1230 | struct nfs_server *server = NFS_SB(sb); |
| 1231 | |
| 1232 | sb->s_blocksize_bits = 0; |
| 1233 | sb->s_blocksize = 0; |
| 1234 | if (data->bsize) |
| 1235 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 1236 | |
| 1237 | if (server->flags & NFS_MOUNT_VER3) { |
| 1238 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1239 | * so ourselves when necessary. |
| 1240 | */ |
| 1241 | sb->s_flags |= MS_POSIXACL; |
| 1242 | sb->s_time_gran = 1; |
| 1243 | } |
| 1244 | |
| 1245 | sb->s_op = &nfs_sops; |
| 1246 | nfs_initialise_sb(sb); |
| 1247 | } |
| 1248 | |
| 1249 | /* |
| 1250 | * Finish setting up a cloned NFS2/3 superblock |
| 1251 | */ |
| 1252 | static void nfs_clone_super(struct super_block *sb, |
| 1253 | const struct super_block *old_sb) |
| 1254 | { |
| 1255 | struct nfs_server *server = NFS_SB(sb); |
| 1256 | |
| 1257 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1258 | sb->s_blocksize = old_sb->s_blocksize; |
| 1259 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1260 | |
| 1261 | if (server->flags & NFS_MOUNT_VER3) { |
| 1262 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1263 | * so ourselves when necessary. |
| 1264 | */ |
| 1265 | sb->s_flags |= MS_POSIXACL; |
| 1266 | sb->s_time_gran = 1; |
| 1267 | } |
| 1268 | |
| 1269 | sb->s_op = old_sb->s_op; |
| 1270 | nfs_initialise_sb(sb); |
| 1271 | } |
| 1272 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1273 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) |
| 1274 | |
| 1275 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 1276 | { |
| 1277 | const struct nfs_server *a = s->s_fs_info; |
| 1278 | const struct rpc_clnt *clnt_a = a->client; |
| 1279 | const struct rpc_clnt *clnt_b = b->client; |
| 1280 | |
| 1281 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 1282 | goto Ebusy; |
| 1283 | if (a->nfs_client != b->nfs_client) |
| 1284 | goto Ebusy; |
| 1285 | if (a->flags != b->flags) |
| 1286 | goto Ebusy; |
| 1287 | if (a->wsize != b->wsize) |
| 1288 | goto Ebusy; |
| 1289 | if (a->rsize != b->rsize) |
| 1290 | goto Ebusy; |
| 1291 | if (a->acregmin != b->acregmin) |
| 1292 | goto Ebusy; |
| 1293 | if (a->acregmax != b->acregmax) |
| 1294 | goto Ebusy; |
| 1295 | if (a->acdirmin != b->acdirmin) |
| 1296 | goto Ebusy; |
| 1297 | if (a->acdirmax != b->acdirmax) |
| 1298 | goto Ebusy; |
| 1299 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 1300 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1301 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1302 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | struct nfs_sb_mountdata { |
| 1307 | struct nfs_server *server; |
| 1308 | int mntflags; |
| 1309 | }; |
| 1310 | |
| 1311 | static int nfs_set_super(struct super_block *s, void *data) |
| 1312 | { |
| 1313 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1314 | struct nfs_server *server = sb_mntdata->server; |
| 1315 | int ret; |
| 1316 | |
| 1317 | s->s_flags = sb_mntdata->mntflags; |
| 1318 | s->s_fs_info = server; |
| 1319 | ret = set_anon_super(s, server); |
| 1320 | if (ret == 0) |
| 1321 | server->s_dev = s->s_dev; |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
| 1325 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 1326 | { |
| 1327 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1328 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 1329 | int mntflags = sb_mntdata->mntflags; |
| 1330 | |
| 1331 | if (memcmp(&old->nfs_client->cl_addr, |
| 1332 | &server->nfs_client->cl_addr, |
| 1333 | sizeof(old->nfs_client->cl_addr)) != 0) |
| 1334 | return 0; |
| 1335 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 1336 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 1337 | return 0; |
| 1338 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 1339 | return 0; |
| 1340 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1343 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 1344 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 1345 | { |
| 1346 | struct nfs_server *server = NULL; |
| 1347 | struct super_block *s; |
| 1348 | struct nfs_fh mntfh; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1349 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1350 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1351 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1352 | struct nfs_sb_mountdata sb_mntdata = { |
| 1353 | .mntflags = flags, |
| 1354 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1355 | int error; |
| 1356 | |
| 1357 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1358 | error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1359 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1360 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1361 | |
| 1362 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1363 | server = nfs_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1364 | if (IS_ERR(server)) { |
| 1365 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1366 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1367 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1368 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1369 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1370 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1371 | compare_super = NULL; |
| 1372 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1373 | /* 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] | 1374 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1375 | if (IS_ERR(s)) { |
| 1376 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1377 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1378 | } |
| 1379 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1380 | if (s->s_fs_info != server) { |
| 1381 | nfs_free_server(server); |
| 1382 | server = NULL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1383 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1384 | |
| 1385 | if (!s->s_root) { |
| 1386 | /* initial superblock/root creation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1387 | nfs_fill_super(s, &data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | mntroot = nfs_get_root(s, &mntfh); |
| 1391 | if (IS_ERR(mntroot)) { |
| 1392 | error = PTR_ERR(mntroot); |
| 1393 | goto error_splat_super; |
| 1394 | } |
| 1395 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1396 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1397 | mnt->mnt_sb = s; |
| 1398 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1399 | error = 0; |
| 1400 | |
| 1401 | out: |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1402 | kfree(data.nfs_server.hostname); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1403 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1404 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1405 | out_err_nosb: |
| 1406 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1407 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1408 | |
| 1409 | error_splat_super: |
| 1410 | up_write(&s->s_umount); |
| 1411 | deactivate_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1412 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1415 | /* |
| 1416 | * Destroy an NFS2/3 superblock |
| 1417 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1418 | static void nfs_kill_super(struct super_block *s) |
| 1419 | { |
| 1420 | struct nfs_server *server = NFS_SB(s); |
| 1421 | |
| 1422 | kill_anon_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1423 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1424 | } |
| 1425 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1426 | /* |
| 1427 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 1428 | */ |
| 1429 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1430 | const char *dev_name, void *raw_data, |
| 1431 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1432 | { |
| 1433 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1434 | struct super_block *s; |
| 1435 | struct nfs_server *server; |
| 1436 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1437 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1438 | struct nfs_sb_mountdata sb_mntdata = { |
| 1439 | .mntflags = flags, |
| 1440 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1441 | int error; |
| 1442 | |
| 1443 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 1444 | |
| 1445 | /* create a new volume representation */ |
| 1446 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 1447 | if (IS_ERR(server)) { |
| 1448 | error = PTR_ERR(server); |
| 1449 | goto out_err_noserver; |
| 1450 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1451 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1452 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1453 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1454 | compare_super = NULL; |
| 1455 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1456 | /* 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] | 1457 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1458 | if (IS_ERR(s)) { |
| 1459 | error = PTR_ERR(s); |
| 1460 | goto out_err_nosb; |
| 1461 | } |
| 1462 | |
| 1463 | if (s->s_fs_info != server) { |
| 1464 | nfs_free_server(server); |
| 1465 | server = NULL; |
| 1466 | } |
| 1467 | |
| 1468 | if (!s->s_root) { |
| 1469 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1470 | nfs_clone_super(s, data->sb); |
| 1471 | } |
| 1472 | |
| 1473 | mntroot = nfs_get_root(s, data->fh); |
| 1474 | if (IS_ERR(mntroot)) { |
| 1475 | error = PTR_ERR(mntroot); |
| 1476 | goto error_splat_super; |
| 1477 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 1478 | 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] | 1479 | dput(mntroot); |
| 1480 | error = -ESTALE; |
| 1481 | goto error_splat_super; |
| 1482 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1483 | |
| 1484 | s->s_flags |= MS_ACTIVE; |
| 1485 | mnt->mnt_sb = s; |
| 1486 | mnt->mnt_root = mntroot; |
| 1487 | |
| 1488 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 1489 | return 0; |
| 1490 | |
| 1491 | out_err_nosb: |
| 1492 | nfs_free_server(server); |
| 1493 | out_err_noserver: |
| 1494 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 1495 | return error; |
| 1496 | |
| 1497 | error_splat_super: |
| 1498 | up_write(&s->s_umount); |
| 1499 | deactivate_super(s); |
| 1500 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 1501 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1505 | |
| 1506 | /* |
| 1507 | * Finish setting up a cloned NFS4 superblock |
| 1508 | */ |
| 1509 | static void nfs4_clone_super(struct super_block *sb, |
| 1510 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1511 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1512 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1513 | sb->s_blocksize = old_sb->s_blocksize; |
| 1514 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1515 | sb->s_time_gran = 1; |
| 1516 | sb->s_op = old_sb->s_op; |
| 1517 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | /* |
| 1521 | * Set up an NFS4 superblock |
| 1522 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1523 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1524 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1525 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1526 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1527 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1528 | } |
| 1529 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1530 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1531 | * Validate NFSv4 mount options |
| 1532 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1533 | static int nfs4_validate_mount_data(void *options, |
| 1534 | struct nfs_parsed_mount_data *args, |
| 1535 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1536 | { |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1537 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1538 | char *c; |
| 1539 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1540 | memset(args, 0, sizeof(*args)); |
| 1541 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1542 | if (data == NULL) |
| 1543 | goto out_no_data; |
| 1544 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1545 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1546 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1547 | args->timeo = 600; |
| 1548 | args->retrans = 2; |
| 1549 | args->acregmin = 3; |
| 1550 | args->acregmax = 60; |
| 1551 | args->acdirmin = 30; |
| 1552 | args->acdirmax = 60; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1553 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1554 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1555 | switch (data->version) { |
| 1556 | case 1: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1557 | if (data->host_addrlen != sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1558 | goto out_no_address; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1559 | if (copy_from_user(&args->nfs_server.address, |
| 1560 | data->host_addr, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1561 | sizeof(args->nfs_server.address))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1562 | return -EFAULT; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1563 | if (args->nfs_server.address.sin_port == 0) |
| 1564 | args->nfs_server.address.sin_port = htons(NFS_PORT); |
| 1565 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1566 | &args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1567 | goto out_no_address; |
| 1568 | |
| 1569 | switch (data->auth_flavourlen) { |
| 1570 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1571 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1572 | break; |
| 1573 | case 1: |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1574 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1575 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1576 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1577 | return -EFAULT; |
| 1578 | break; |
| 1579 | default: |
| 1580 | goto out_inval_auth; |
| 1581 | } |
| 1582 | |
| 1583 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 1584 | if (IS_ERR(c)) |
| 1585 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1586 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1587 | |
| 1588 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 1589 | if (IS_ERR(c)) |
| 1590 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1591 | args->nfs_server.export_path = c; |
| 1592 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1593 | |
| 1594 | c = strndup_user(data->client_addr.data, 16); |
| 1595 | if (IS_ERR(c)) |
| 1596 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1597 | args->client_address = c; |
| 1598 | |
| 1599 | /* |
| 1600 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 1601 | * can deal with. |
| 1602 | */ |
| 1603 | |
| 1604 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 1605 | args->rsize = data->rsize; |
| 1606 | args->wsize = data->wsize; |
| 1607 | args->timeo = data->timeo; |
| 1608 | args->retrans = data->retrans; |
| 1609 | args->acregmin = data->acregmin; |
| 1610 | args->acregmax = data->acregmax; |
| 1611 | args->acdirmin = data->acdirmin; |
| 1612 | args->acdirmax = data->acdirmax; |
| 1613 | args->nfs_server.protocol = data->proto; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1614 | |
| 1615 | break; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1616 | default: { |
| 1617 | unsigned int len; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1618 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1619 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1620 | return -EINVAL; |
| 1621 | |
| 1622 | if (!nfs_verify_server_address((struct sockaddr *) |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1623 | &args->nfs_server.address)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1624 | return -EINVAL; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1625 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1626 | switch (args->auth_flavor_len) { |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1627 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1628 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1629 | break; |
| 1630 | case 1: |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1631 | break; |
| 1632 | default: |
| 1633 | goto out_inval_auth; |
| 1634 | } |
| 1635 | |
| 1636 | /* |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1637 | * Split "dev_name" into "hostname:mntpath". |
| 1638 | */ |
| 1639 | c = strchr(dev_name, ':'); |
| 1640 | if (c == NULL) |
| 1641 | return -EINVAL; |
| 1642 | /* while calculating len, pretend ':' is '\0' */ |
| 1643 | len = c - dev_name; |
| 1644 | if (len > NFS4_MAXNAMLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1645 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1646 | args->nfs_server.hostname = kzalloc(len, GFP_KERNEL); |
| 1647 | if (args->nfs_server.hostname == NULL) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1648 | return -ENOMEM; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1649 | strncpy(args->nfs_server.hostname, dev_name, len - 1); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1650 | |
| 1651 | c++; /* step over the ':' */ |
| 1652 | len = strlen(c); |
| 1653 | if (len > NFS4_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1654 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1655 | args->nfs_server.export_path = kzalloc(len + 1, GFP_KERNEL); |
| 1656 | if (args->nfs_server.export_path == NULL) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1657 | return -ENOMEM; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1658 | strncpy(args->nfs_server.export_path, c, len); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1659 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1660 | dprintk("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 */ |