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