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