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