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 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 444 | /* |
| 445 | * Describe the mount options in force on this server representation |
| 446 | */ |
| 447 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) |
| 448 | { |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 449 | static const struct proc_nfs_info { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 450 | int flag; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 451 | const char *str; |
| 452 | const char *nostr; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 453 | } nfs_info[] = { |
| 454 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 455 | { NFS_MOUNT_NOCTO, ",nocto", "" }, |
| 456 | { NFS_MOUNT_NOAC, ",noac", "" }, |
| 457 | { NFS_MOUNT_NONLM, ",nolock", "" }, |
| 458 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
Steve Dickson | 74dd34e | 2007-04-14 17:01:15 -0400 | [diff] [blame] | 459 | { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 460 | { NFS_MOUNT_UNSHARED, ",nosharecache", ""}, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 461 | { 0, NULL, NULL } |
| 462 | }; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 463 | const struct proc_nfs_info *nfs_infop; |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 464 | struct nfs_client *clp = nfss->nfs_client; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 465 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 466 | seq_printf(m, ",vers=%d", clp->rpc_ops->version); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 467 | seq_printf(m, ",rsize=%d", nfss->rsize); |
| 468 | seq_printf(m, ",wsize=%d", nfss->wsize); |
| 469 | if (nfss->acregmin != 3*HZ || showdefaults) |
| 470 | seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ); |
| 471 | if (nfss->acregmax != 60*HZ || showdefaults) |
| 472 | seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ); |
| 473 | if (nfss->acdirmin != 30*HZ || showdefaults) |
| 474 | seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ); |
| 475 | if (nfss->acdirmax != 60*HZ || showdefaults) |
| 476 | seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ); |
| 477 | for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { |
| 478 | if (nfss->flags & nfs_infop->flag) |
| 479 | seq_puts(m, nfs_infop->str); |
| 480 | else |
| 481 | seq_puts(m, nfs_infop->nostr); |
| 482 | } |
\"Talpey, Thomas\ | 56928ed | 2007-09-10 13:48:47 -0400 | [diff] [blame] | 483 | seq_printf(m, ",proto=%s", |
| 484 | rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO)); |
Trond Myklebust | 3317023 | 2007-12-20 16:03:59 -0500 | [diff] [blame] | 485 | seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ); |
| 486 | seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries); |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 487 | seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor)); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /* |
| 491 | * Describe the mount options on this VFS mountpoint |
| 492 | */ |
| 493 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 494 | { |
| 495 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 496 | |
| 497 | nfs_show_mount_options(m, nfss, 0); |
| 498 | |
Chuck Lever | 5d8515c | 2007-12-10 14:57:16 -0500 | [diff] [blame] | 499 | seq_printf(m, ",addr=%s", |
| 500 | rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient, |
| 501 | RPC_DISPLAY_ADDR)); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Present statistical information for this VFS mountpoint |
| 508 | */ |
| 509 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 510 | { |
| 511 | int i, cpu; |
| 512 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 513 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 514 | struct nfs_iostats totals = { }; |
| 515 | |
| 516 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 517 | |
| 518 | /* |
| 519 | * Display all mount option settings |
| 520 | */ |
| 521 | seq_printf(m, "\n\topts:\t"); |
| 522 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 523 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 524 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 525 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 526 | nfs_show_mount_options(m, nfss, 1); |
| 527 | |
| 528 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 529 | |
| 530 | seq_printf(m, "\n\tcaps:\t"); |
| 531 | seq_printf(m, "caps=0x%x", nfss->caps); |
| 532 | seq_printf(m, ",wtmult=%d", nfss->wtmult); |
| 533 | seq_printf(m, ",dtsize=%d", nfss->dtsize); |
| 534 | seq_printf(m, ",bsize=%d", nfss->bsize); |
| 535 | seq_printf(m, ",namelen=%d", nfss->namelen); |
| 536 | |
| 537 | #ifdef CONFIG_NFS_V4 |
Trond Myklebust | 40c55319 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 538 | if (nfss->nfs_client->rpc_ops->version == 4) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 539 | seq_printf(m, "\n\tnfsv4:\t"); |
| 540 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 541 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 542 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 543 | } |
| 544 | #endif |
| 545 | |
| 546 | /* |
| 547 | * Display security flavor in effect for this mount |
| 548 | */ |
| 549 | seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor); |
| 550 | if (auth->au_flavor) |
| 551 | seq_printf(m, ",pseudoflavor=%d", auth->au_flavor); |
| 552 | |
| 553 | /* |
| 554 | * Display superblock I/O counters |
| 555 | */ |
| 556 | for_each_possible_cpu(cpu) { |
| 557 | struct nfs_iostats *stats; |
| 558 | |
| 559 | preempt_disable(); |
| 560 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 561 | |
| 562 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 563 | totals.events[i] += stats->events[i]; |
| 564 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 565 | totals.bytes[i] += stats->bytes[i]; |
| 566 | |
| 567 | preempt_enable(); |
| 568 | } |
| 569 | |
| 570 | seq_printf(m, "\n\tevents:\t"); |
| 571 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 572 | seq_printf(m, "%lu ", totals.events[i]); |
| 573 | seq_printf(m, "\n\tbytes:\t"); |
| 574 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 575 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 576 | seq_printf(m, "\n"); |
| 577 | |
| 578 | rpc_print_iostats(m, nfss->client); |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Begin unmount by attempting to remove all automounted mountpoints we added |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 585 | * in response to xdev traversals and referrals |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 586 | */ |
| 587 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) |
| 588 | { |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 589 | struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb); |
| 590 | struct rpc_clnt *rpc; |
| 591 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 592 | shrink_submounts(vfsmnt, &nfs_automount_list); |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 593 | |
| 594 | if (!(flags & MNT_FORCE)) |
| 595 | return; |
| 596 | /* -EIO all pending I/O */ |
| 597 | rpc = server->client_acl; |
| 598 | if (!IS_ERR(rpc)) |
| 599 | rpc_killall_tasks(rpc); |
| 600 | rpc = server->client; |
| 601 | if (!IS_ERR(rpc)) |
| 602 | rpc_killall_tasks(rpc); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /* |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 606 | * Set the port number in an address. Be agnostic about the address family. |
| 607 | */ |
| 608 | static void nfs_set_port(struct sockaddr *sap, unsigned short port) |
| 609 | { |
| 610 | switch (sap->sa_family) { |
| 611 | case AF_INET: { |
| 612 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; |
| 613 | ap->sin_port = htons(port); |
| 614 | break; |
| 615 | } |
| 616 | case AF_INET6: { |
| 617 | struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; |
| 618 | ap->sin6_port = htons(port); |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /* |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 625 | * Sanity-check a server address provided by the mount command. |
| 626 | * |
| 627 | * Address family must be initialized, and address must not be |
| 628 | * the ANY address for that family. |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 629 | */ |
| 630 | static int nfs_verify_server_address(struct sockaddr *addr) |
| 631 | { |
| 632 | switch (addr->sa_family) { |
| 633 | case AF_INET: { |
Chuck Lever | cdcd7f9 | 2007-12-10 14:57:45 -0500 | [diff] [blame] | 634 | struct sockaddr_in *sa = (struct sockaddr_in *)addr; |
| 635 | return sa->sin_addr.s_addr != INADDR_ANY; |
| 636 | } |
| 637 | case AF_INET6: { |
| 638 | struct in6_addr *sa = &((struct sockaddr_in6 *)addr)->sin6_addr; |
| 639 | return !ipv6_addr_any(sa); |
Chuck Lever | fc50d58 | 2007-07-01 12:12:46 -0400 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | /* |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 647 | * Parse string addresses passed in via a mount option, |
| 648 | * and construct a sockaddr based on the result. |
| 649 | * |
| 650 | * If address parsing fails, set the sockaddr's address |
| 651 | * family to AF_UNSPEC to force nfs_verify_server_address() |
| 652 | * to punt the mount. |
| 653 | */ |
| 654 | static void nfs_parse_server_address(char *value, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 655 | struct sockaddr *sap, |
| 656 | size_t *len) |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 657 | { |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 658 | if (strchr(value, ':')) { |
| 659 | struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; |
| 660 | u8 *addr = (u8 *)&ap->sin6_addr.in6_u; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 661 | |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 662 | ap->sin6_family = AF_INET6; |
| 663 | *len = sizeof(*ap); |
| 664 | if (in6_pton(value, -1, addr, '\0', NULL)) |
| 665 | return; |
| 666 | } else { |
| 667 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; |
| 668 | u8 *addr = (u8 *)&ap->sin_addr.s_addr; |
| 669 | |
| 670 | ap->sin_family = AF_INET; |
| 671 | *len = sizeof(*ap); |
| 672 | if (in4_pton(value, -1, addr, '\0', NULL)) |
| 673 | return; |
| 674 | } |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 675 | |
| 676 | sap->sa_family = AF_UNSPEC; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 677 | *len = 0; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | /* |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 681 | * Error-check and convert a string of mount options from user space into |
| 682 | * a data structure |
| 683 | */ |
| 684 | static int nfs_parse_mount_options(char *raw, |
| 685 | struct nfs_parsed_mount_data *mnt) |
| 686 | { |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 687 | char *p, *string, *secdata; |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 688 | unsigned short port = 0; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 689 | int rc; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 690 | |
| 691 | if (!raw) { |
| 692 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 693 | return 1; |
| 694 | } |
| 695 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 696 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 697 | secdata = alloc_secdata(); |
| 698 | if (!secdata) |
| 699 | goto out_nomem; |
| 700 | |
| 701 | rc = security_sb_copy_data(raw, secdata); |
| 702 | if (rc) |
| 703 | goto out_security_failure; |
| 704 | |
| 705 | rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts); |
| 706 | if (rc) |
| 707 | goto out_security_failure; |
| 708 | |
| 709 | free_secdata(secdata); |
| 710 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 711 | while ((p = strsep(&raw, ",")) != NULL) { |
| 712 | substring_t args[MAX_OPT_ARGS]; |
| 713 | int option, token; |
| 714 | |
| 715 | if (!*p) |
| 716 | continue; |
| 717 | |
| 718 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 719 | |
| 720 | token = match_token(p, nfs_mount_option_tokens, args); |
| 721 | switch (token) { |
| 722 | case Opt_soft: |
| 723 | mnt->flags |= NFS_MOUNT_SOFT; |
| 724 | break; |
| 725 | case Opt_hard: |
| 726 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 727 | break; |
| 728 | case Opt_intr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 729 | case Opt_nointr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 730 | break; |
| 731 | case Opt_posix: |
| 732 | mnt->flags |= NFS_MOUNT_POSIX; |
| 733 | break; |
| 734 | case Opt_noposix: |
| 735 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 736 | break; |
| 737 | case Opt_cto: |
| 738 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 739 | break; |
| 740 | case Opt_nocto: |
| 741 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 742 | break; |
| 743 | case Opt_ac: |
| 744 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 745 | break; |
| 746 | case Opt_noac: |
| 747 | mnt->flags |= NFS_MOUNT_NOAC; |
| 748 | break; |
| 749 | case Opt_lock: |
| 750 | mnt->flags &= ~NFS_MOUNT_NONLM; |
| 751 | break; |
| 752 | case Opt_nolock: |
| 753 | mnt->flags |= NFS_MOUNT_NONLM; |
| 754 | break; |
| 755 | case Opt_v2: |
| 756 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 757 | break; |
| 758 | case Opt_v3: |
| 759 | mnt->flags |= NFS_MOUNT_VER3; |
| 760 | break; |
| 761 | case Opt_udp: |
| 762 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 763 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 764 | mnt->timeo = 7; |
| 765 | mnt->retrans = 5; |
| 766 | break; |
| 767 | case Opt_tcp: |
| 768 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 769 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 770 | mnt->timeo = 600; |
| 771 | mnt->retrans = 2; |
| 772 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 773 | case Opt_rdma: |
| 774 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 775 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 776 | mnt->timeo = 600; |
| 777 | mnt->retrans = 2; |
| 778 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 779 | case Opt_acl: |
| 780 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 781 | break; |
| 782 | case Opt_noacl: |
| 783 | mnt->flags |= NFS_MOUNT_NOACL; |
| 784 | break; |
| 785 | case Opt_rdirplus: |
| 786 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 787 | break; |
| 788 | case Opt_nordirplus: |
| 789 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 790 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 791 | case Opt_sharecache: |
| 792 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 793 | break; |
| 794 | case Opt_nosharecache: |
| 795 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 796 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 797 | |
| 798 | case Opt_port: |
| 799 | if (match_int(args, &option)) |
| 800 | return 0; |
| 801 | if (option < 0 || option > 65535) |
| 802 | return 0; |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 803 | port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 804 | break; |
| 805 | case Opt_rsize: |
| 806 | if (match_int(args, &mnt->rsize)) |
| 807 | return 0; |
| 808 | break; |
| 809 | case Opt_wsize: |
| 810 | if (match_int(args, &mnt->wsize)) |
| 811 | return 0; |
| 812 | break; |
| 813 | case Opt_bsize: |
| 814 | if (match_int(args, &option)) |
| 815 | return 0; |
| 816 | if (option < 0) |
| 817 | return 0; |
| 818 | mnt->bsize = option; |
| 819 | break; |
| 820 | case Opt_timeo: |
| 821 | if (match_int(args, &mnt->timeo)) |
| 822 | return 0; |
| 823 | break; |
| 824 | case Opt_retrans: |
| 825 | if (match_int(args, &mnt->retrans)) |
| 826 | return 0; |
| 827 | break; |
| 828 | case Opt_acregmin: |
| 829 | if (match_int(args, &mnt->acregmin)) |
| 830 | return 0; |
| 831 | break; |
| 832 | case Opt_acregmax: |
| 833 | if (match_int(args, &mnt->acregmax)) |
| 834 | return 0; |
| 835 | break; |
| 836 | case Opt_acdirmin: |
| 837 | if (match_int(args, &mnt->acdirmin)) |
| 838 | return 0; |
| 839 | break; |
| 840 | case Opt_acdirmax: |
| 841 | if (match_int(args, &mnt->acdirmax)) |
| 842 | return 0; |
| 843 | break; |
| 844 | case Opt_actimeo: |
| 845 | if (match_int(args, &option)) |
| 846 | return 0; |
| 847 | if (option < 0) |
| 848 | return 0; |
| 849 | mnt->acregmin = |
| 850 | mnt->acregmax = |
| 851 | mnt->acdirmin = |
| 852 | mnt->acdirmax = option; |
| 853 | break; |
| 854 | case Opt_namelen: |
| 855 | if (match_int(args, &mnt->namlen)) |
| 856 | return 0; |
| 857 | break; |
| 858 | case Opt_mountport: |
| 859 | if (match_int(args, &option)) |
| 860 | return 0; |
| 861 | if (option < 0 || option > 65535) |
| 862 | return 0; |
| 863 | mnt->mount_server.port = option; |
| 864 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 865 | case Opt_mountvers: |
| 866 | if (match_int(args, &option)) |
| 867 | return 0; |
| 868 | if (option < 0) |
| 869 | return 0; |
| 870 | mnt->mount_server.version = option; |
| 871 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 872 | case Opt_nfsvers: |
| 873 | if (match_int(args, &option)) |
| 874 | return 0; |
| 875 | switch (option) { |
| 876 | case 2: |
| 877 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 878 | break; |
| 879 | case 3: |
| 880 | mnt->flags |= NFS_MOUNT_VER3; |
| 881 | break; |
| 882 | default: |
| 883 | goto out_unrec_vers; |
| 884 | } |
| 885 | break; |
| 886 | |
| 887 | case Opt_sec: |
| 888 | string = match_strdup(args); |
| 889 | if (string == NULL) |
| 890 | goto out_nomem; |
| 891 | token = match_token(string, nfs_secflavor_tokens, args); |
| 892 | kfree(string); |
| 893 | |
| 894 | /* |
| 895 | * The flags setting is for v2/v3. The flavor_len |
| 896 | * setting is for v4. v2/v3 also need to know the |
| 897 | * difference between NULL and UNIX. |
| 898 | */ |
| 899 | switch (token) { |
| 900 | case Opt_sec_none: |
| 901 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 902 | mnt->auth_flavor_len = 0; |
| 903 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 904 | break; |
| 905 | case Opt_sec_sys: |
| 906 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 907 | mnt->auth_flavor_len = 0; |
| 908 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 909 | break; |
| 910 | case Opt_sec_krb5: |
| 911 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 912 | mnt->auth_flavor_len = 1; |
| 913 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 914 | break; |
| 915 | case Opt_sec_krb5i: |
| 916 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 917 | mnt->auth_flavor_len = 1; |
| 918 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 919 | break; |
| 920 | case Opt_sec_krb5p: |
| 921 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 922 | mnt->auth_flavor_len = 1; |
| 923 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 924 | break; |
| 925 | case Opt_sec_lkey: |
| 926 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 927 | mnt->auth_flavor_len = 1; |
| 928 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 929 | break; |
| 930 | case Opt_sec_lkeyi: |
| 931 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 932 | mnt->auth_flavor_len = 1; |
| 933 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 934 | break; |
| 935 | case Opt_sec_lkeyp: |
| 936 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 937 | mnt->auth_flavor_len = 1; |
| 938 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 939 | break; |
| 940 | case Opt_sec_spkm: |
| 941 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 942 | mnt->auth_flavor_len = 1; |
| 943 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 944 | break; |
| 945 | case Opt_sec_spkmi: |
| 946 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 947 | mnt->auth_flavor_len = 1; |
| 948 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 949 | break; |
| 950 | case Opt_sec_spkmp: |
| 951 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 952 | mnt->auth_flavor_len = 1; |
| 953 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 954 | break; |
| 955 | default: |
| 956 | goto out_unrec_sec; |
| 957 | } |
| 958 | break; |
| 959 | case Opt_proto: |
| 960 | string = match_strdup(args); |
| 961 | if (string == NULL) |
| 962 | goto out_nomem; |
| 963 | token = match_token(string, |
| 964 | nfs_xprt_protocol_tokens, args); |
| 965 | kfree(string); |
| 966 | |
| 967 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 968 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 969 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 970 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 971 | mnt->timeo = 7; |
| 972 | mnt->retrans = 5; |
| 973 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 974 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 975 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 976 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 977 | mnt->timeo = 600; |
| 978 | mnt->retrans = 2; |
| 979 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 980 | case Opt_xprt_rdma: |
| 981 | /* vector side protocols to TCP */ |
| 982 | mnt->flags |= NFS_MOUNT_TCP; |
| 983 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 984 | mnt->timeo = 600; |
| 985 | mnt->retrans = 2; |
| 986 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 987 | default: |
| 988 | goto out_unrec_xprt; |
| 989 | } |
| 990 | break; |
| 991 | case Opt_mountproto: |
| 992 | string = match_strdup(args); |
| 993 | if (string == NULL) |
| 994 | goto out_nomem; |
| 995 | token = match_token(string, |
| 996 | nfs_xprt_protocol_tokens, args); |
| 997 | kfree(string); |
| 998 | |
| 999 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1000 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1001 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1002 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1003 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1004 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1005 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1006 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1007 | default: |
| 1008 | goto out_unrec_xprt; |
| 1009 | } |
| 1010 | break; |
| 1011 | case Opt_addr: |
| 1012 | string = match_strdup(args); |
| 1013 | if (string == NULL) |
| 1014 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1015 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1016 | &mnt->nfs_server.address, |
| 1017 | &mnt->nfs_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1018 | kfree(string); |
| 1019 | break; |
| 1020 | case Opt_clientaddr: |
| 1021 | string = match_strdup(args); |
| 1022 | if (string == NULL) |
| 1023 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1024 | kfree(mnt->client_address); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1025 | mnt->client_address = string; |
| 1026 | break; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1027 | case Opt_mounthost: |
| 1028 | string = match_strdup(args); |
| 1029 | if (string == NULL) |
| 1030 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1031 | kfree(mnt->mount_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1032 | mnt->mount_server.hostname = string; |
| 1033 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 1034 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1035 | string = match_strdup(args); |
| 1036 | if (string == NULL) |
| 1037 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1038 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1039 | &mnt->mount_server.address, |
| 1040 | &mnt->mount_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1041 | kfree(string); |
| 1042 | break; |
| 1043 | |
| 1044 | case Opt_userspace: |
| 1045 | case Opt_deprecated: |
| 1046 | break; |
| 1047 | |
| 1048 | default: |
| 1049 | goto out_unknown; |
| 1050 | } |
| 1051 | } |
| 1052 | |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 1053 | nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port); |
| 1054 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1055 | return 1; |
| 1056 | |
| 1057 | out_nomem: |
| 1058 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| 1059 | return 0; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1060 | out_security_failure: |
| 1061 | free_secdata(secdata); |
| 1062 | printk(KERN_INFO "NFS: security options invalid: %d\n", rc); |
| 1063 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1064 | out_unrec_vers: |
| 1065 | printk(KERN_INFO "NFS: unrecognized NFS version number\n"); |
| 1066 | return 0; |
| 1067 | |
| 1068 | out_unrec_xprt: |
| 1069 | printk(KERN_INFO "NFS: unrecognized transport protocol\n"); |
| 1070 | return 0; |
| 1071 | |
| 1072 | out_unrec_sec: |
| 1073 | printk(KERN_INFO "NFS: unrecognized security flavor\n"); |
| 1074 | return 0; |
| 1075 | |
| 1076 | out_unknown: |
| 1077 | printk(KERN_INFO "NFS: unknown mount option: %s\n", p); |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | /* |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1082 | * Use the remote server's MOUNT service to request the NFS file handle |
| 1083 | * corresponding to the provided path. |
| 1084 | */ |
| 1085 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 1086 | struct nfs_fh *root_fh) |
| 1087 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1088 | struct sockaddr *sap = (struct sockaddr *)&args->mount_server.address; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1089 | char *hostname; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1090 | int status; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1091 | |
| 1092 | if (args->mount_server.version == 0) { |
| 1093 | if (args->flags & NFS_MOUNT_VER3) |
| 1094 | args->mount_server.version = NFS_MNT3_VERSION; |
| 1095 | else |
| 1096 | args->mount_server.version = NFS_MNT_VERSION; |
| 1097 | } |
| 1098 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1099 | if (args->mount_server.hostname) |
| 1100 | hostname = args->mount_server.hostname; |
| 1101 | else |
| 1102 | hostname = args->nfs_server.hostname; |
| 1103 | |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1104 | /* |
| 1105 | * Construct the mount server's address. |
| 1106 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1107 | if (args->mount_server.address.ss_family == AF_UNSPEC) { |
| 1108 | memcpy(sap, &args->nfs_server.address, |
| 1109 | args->nfs_server.addrlen); |
| 1110 | args->mount_server.addrlen = args->nfs_server.addrlen; |
| 1111 | } |
| 1112 | |
James Lentini | aad7000 | 2007-09-24 17:32:49 -0400 | [diff] [blame] | 1113 | /* |
| 1114 | * autobind will be used if mount_server.port == 0 |
| 1115 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1116 | nfs_set_port(sap, args->mount_server.port); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1117 | |
| 1118 | /* |
| 1119 | * Now ask the mount server to map our export path |
| 1120 | * to a file handle. |
| 1121 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1122 | status = nfs_mount(sap, |
| 1123 | args->mount_server.addrlen, |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1124 | hostname, |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1125 | args->nfs_server.export_path, |
| 1126 | args->mount_server.version, |
| 1127 | args->mount_server.protocol, |
| 1128 | root_fh); |
Chuck Lever | efd8340 | 2007-09-11 18:00:58 -0400 | [diff] [blame] | 1129 | if (status == 0) |
| 1130 | return 0; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1131 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1132 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d", |
| 1133 | hostname, status); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1134 | return status; |
| 1135 | } |
| 1136 | |
| 1137 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1138 | * Validate the NFS2/NFS3 mount data |
| 1139 | * - fills in the mount root filehandle |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1140 | * |
| 1141 | * For option strings, user space handles the following behaviors: |
| 1142 | * |
| 1143 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 1144 | * |
| 1145 | * + failure mode: how to behave if a mount request can't be handled |
| 1146 | * immediately ("fg/bg" option) |
| 1147 | * |
| 1148 | * + retry: how often to retry a mount request ("retry=" option) |
| 1149 | * |
| 1150 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 1151 | * mountproto=tcp after mountproto=udp, and so on |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1152 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1153 | static int nfs_validate_mount_data(void *options, |
| 1154 | struct nfs_parsed_mount_data *args, |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1155 | struct nfs_fh *mntfh, |
| 1156 | const char *dev_name) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1157 | { |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1158 | struct nfs_mount_data *data = (struct nfs_mount_data *)options; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1159 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1160 | memset(args, 0, sizeof(*args)); |
| 1161 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1162 | if (data == NULL) |
| 1163 | goto out_no_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1164 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1165 | args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP); |
| 1166 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1167 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1168 | args->timeo = 600; |
| 1169 | args->retrans = 2; |
| 1170 | args->acregmin = 3; |
| 1171 | args->acregmax = 60; |
| 1172 | args->acdirmin = 30; |
| 1173 | args->acdirmax = 60; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1174 | args->mount_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1175 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1176 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1177 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1178 | case 1: |
| 1179 | data->namlen = 0; |
| 1180 | case 2: |
| 1181 | data->bsize = 0; |
| 1182 | case 3: |
| 1183 | if (data->flags & NFS_MOUNT_VER3) |
| 1184 | goto out_no_v3; |
| 1185 | data->root.size = NFS2_FHSIZE; |
| 1186 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1187 | case 4: |
| 1188 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1189 | goto out_no_sec; |
| 1190 | case 5: |
| 1191 | memset(data->context, 0, sizeof(data->context)); |
| 1192 | case 6: |
| 1193 | if (data->flags & NFS_MOUNT_VER3) |
| 1194 | mntfh->size = data->root.size; |
| 1195 | else |
| 1196 | mntfh->size = NFS2_FHSIZE; |
| 1197 | |
| 1198 | if (mntfh->size > sizeof(mntfh->data)) |
| 1199 | goto out_invalid_fh; |
| 1200 | |
| 1201 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1202 | if (mntfh->size < sizeof(mntfh->data)) |
| 1203 | memset(mntfh->data + mntfh->size, 0, |
| 1204 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1205 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1206 | /* |
| 1207 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1208 | * can deal with. |
| 1209 | */ |
| 1210 | args->flags = data->flags; |
| 1211 | args->rsize = data->rsize; |
| 1212 | args->wsize = data->wsize; |
| 1213 | args->flags = data->flags; |
| 1214 | args->timeo = data->timeo; |
| 1215 | args->retrans = data->retrans; |
| 1216 | args->acregmin = data->acregmin; |
| 1217 | args->acregmax = data->acregmax; |
| 1218 | args->acdirmin = data->acdirmin; |
| 1219 | args->acdirmax = data->acdirmax; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1220 | |
| 1221 | memcpy(&args->nfs_server.address, &data->addr, |
| 1222 | sizeof(data->addr)); |
| 1223 | args->nfs_server.addrlen = sizeof(data->addr); |
| 1224 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1225 | &args->nfs_server.address)) |
| 1226 | goto out_no_address; |
| 1227 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1228 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1229 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1230 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1231 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1232 | args->namlen = data->namlen; |
| 1233 | args->bsize = data->bsize; |
| 1234 | args->auth_flavors[0] = data->pseudoflavor; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1235 | |
| 1236 | /* |
| 1237 | * The legacy version 6 binary mount data from userspace has a |
| 1238 | * field used only to transport selinux information into the |
| 1239 | * the kernel. To continue to support that functionality we |
| 1240 | * have a touch of selinux knowledge here in the NFS code. The |
| 1241 | * userspace code converted context=blah to just blah so we are |
| 1242 | * converting back to the full string selinux understands. |
| 1243 | */ |
| 1244 | if (data->context[0]){ |
| 1245 | #ifdef CONFIG_SECURITY_SELINUX |
| 1246 | int rc; |
| 1247 | char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL); |
| 1248 | if (!opts_str) |
| 1249 | return -ENOMEM; |
| 1250 | strcpy(opts_str, "context="); |
| 1251 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
| 1252 | strcat(opts_str, &data->context[0]); |
| 1253 | rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts); |
| 1254 | kfree(opts_str); |
| 1255 | if (rc) |
| 1256 | return rc; |
| 1257 | #else |
| 1258 | return -EINVAL; |
| 1259 | #endif |
| 1260 | } |
| 1261 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1262 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1263 | default: { |
| 1264 | unsigned int len; |
| 1265 | char *c; |
| 1266 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1267 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1268 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1269 | return -EINVAL; |
| 1270 | |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1271 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1272 | &args->nfs_server.address)) |
| 1273 | goto out_no_address; |
| 1274 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1275 | c = strchr(dev_name, ':'); |
| 1276 | if (c == NULL) |
| 1277 | return -EINVAL; |
Chuck Lever | 350c73a | 2007-08-29 17:59:01 -0400 | [diff] [blame] | 1278 | len = c - dev_name; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1279 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1280 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1281 | |
| 1282 | c++; |
| 1283 | if (strlen(c) > NFS_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1284 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1285 | args->nfs_server.export_path = c; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1286 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1287 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1288 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1289 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1290 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1291 | break; |
| 1292 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1293 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1294 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1295 | if (!(args->flags & NFS_MOUNT_SECFLAVOUR)) |
| 1296 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Trond Myklebust | 36b15c5 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1297 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1298 | #ifndef CONFIG_NFS_V3 |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1299 | if (args->flags & NFS_MOUNT_VER3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1300 | goto out_v3_not_compiled; |
| 1301 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1302 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1303 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1304 | |
| 1305 | out_no_data: |
| 1306 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1307 | return -EINVAL; |
| 1308 | |
| 1309 | out_no_v3: |
| 1310 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1311 | data->version); |
| 1312 | return -EINVAL; |
| 1313 | |
| 1314 | out_no_sec: |
| 1315 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1316 | return -EINVAL; |
| 1317 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1318 | #ifndef CONFIG_NFS_V3 |
| 1319 | out_v3_not_compiled: |
| 1320 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1321 | return -EPROTONOSUPPORT; |
| 1322 | #endif /* !CONFIG_NFS_V3 */ |
| 1323 | |
| 1324 | out_no_address: |
| 1325 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1326 | return -EINVAL; |
| 1327 | |
| 1328 | out_invalid_fh: |
| 1329 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1330 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | /* |
| 1334 | * Initialise the common bits of the superblock |
| 1335 | */ |
| 1336 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 1337 | { |
| 1338 | struct nfs_server *server = NFS_SB(sb); |
| 1339 | |
| 1340 | sb->s_magic = NFS_SUPER_MAGIC; |
| 1341 | |
| 1342 | /* We probably want something more informative here */ |
| 1343 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 1344 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 1345 | |
| 1346 | if (sb->s_blocksize == 0) |
| 1347 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 1348 | &sb->s_blocksize_bits); |
| 1349 | |
| 1350 | if (server->flags & NFS_MOUNT_NOAC) |
| 1351 | sb->s_flags |= MS_SYNCHRONOUS; |
| 1352 | |
| 1353 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 1354 | } |
| 1355 | |
| 1356 | /* |
| 1357 | * Finish setting up an NFS2/3 superblock |
| 1358 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1359 | static void nfs_fill_super(struct super_block *sb, |
| 1360 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1361 | { |
| 1362 | struct nfs_server *server = NFS_SB(sb); |
| 1363 | |
| 1364 | sb->s_blocksize_bits = 0; |
| 1365 | sb->s_blocksize = 0; |
| 1366 | if (data->bsize) |
| 1367 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 1368 | |
| 1369 | if (server->flags & NFS_MOUNT_VER3) { |
| 1370 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1371 | * so ourselves when necessary. |
| 1372 | */ |
| 1373 | sb->s_flags |= MS_POSIXACL; |
| 1374 | sb->s_time_gran = 1; |
| 1375 | } |
| 1376 | |
| 1377 | sb->s_op = &nfs_sops; |
| 1378 | nfs_initialise_sb(sb); |
| 1379 | } |
| 1380 | |
| 1381 | /* |
| 1382 | * Finish setting up a cloned NFS2/3 superblock |
| 1383 | */ |
| 1384 | static void nfs_clone_super(struct super_block *sb, |
| 1385 | const struct super_block *old_sb) |
| 1386 | { |
| 1387 | struct nfs_server *server = NFS_SB(sb); |
| 1388 | |
| 1389 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1390 | sb->s_blocksize = old_sb->s_blocksize; |
| 1391 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1392 | |
| 1393 | if (server->flags & NFS_MOUNT_VER3) { |
| 1394 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1395 | * so ourselves when necessary. |
| 1396 | */ |
| 1397 | sb->s_flags |= MS_POSIXACL; |
| 1398 | sb->s_time_gran = 1; |
| 1399 | } |
| 1400 | |
| 1401 | sb->s_op = old_sb->s_op; |
| 1402 | nfs_initialise_sb(sb); |
| 1403 | } |
| 1404 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1405 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) |
| 1406 | |
| 1407 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 1408 | { |
| 1409 | const struct nfs_server *a = s->s_fs_info; |
| 1410 | const struct rpc_clnt *clnt_a = a->client; |
| 1411 | const struct rpc_clnt *clnt_b = b->client; |
| 1412 | |
| 1413 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 1414 | goto Ebusy; |
| 1415 | if (a->nfs_client != b->nfs_client) |
| 1416 | goto Ebusy; |
| 1417 | if (a->flags != b->flags) |
| 1418 | goto Ebusy; |
| 1419 | if (a->wsize != b->wsize) |
| 1420 | goto Ebusy; |
| 1421 | if (a->rsize != b->rsize) |
| 1422 | goto Ebusy; |
| 1423 | if (a->acregmin != b->acregmin) |
| 1424 | goto Ebusy; |
| 1425 | if (a->acregmax != b->acregmax) |
| 1426 | goto Ebusy; |
| 1427 | if (a->acdirmin != b->acdirmin) |
| 1428 | goto Ebusy; |
| 1429 | if (a->acdirmax != b->acdirmax) |
| 1430 | goto Ebusy; |
| 1431 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 1432 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1433 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1434 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | struct nfs_sb_mountdata { |
| 1439 | struct nfs_server *server; |
| 1440 | int mntflags; |
| 1441 | }; |
| 1442 | |
| 1443 | static int nfs_set_super(struct super_block *s, void *data) |
| 1444 | { |
| 1445 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1446 | struct nfs_server *server = sb_mntdata->server; |
| 1447 | int ret; |
| 1448 | |
| 1449 | s->s_flags = sb_mntdata->mntflags; |
| 1450 | s->s_fs_info = server; |
| 1451 | ret = set_anon_super(s, server); |
| 1452 | if (ret == 0) |
| 1453 | server->s_dev = s->s_dev; |
| 1454 | return ret; |
| 1455 | } |
| 1456 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1457 | static int nfs_compare_super_address(struct nfs_server *server1, |
| 1458 | struct nfs_server *server2) |
| 1459 | { |
| 1460 | struct sockaddr *sap1, *sap2; |
| 1461 | |
| 1462 | sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr; |
| 1463 | sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr; |
| 1464 | |
| 1465 | if (sap1->sa_family != sap2->sa_family) |
| 1466 | return 0; |
| 1467 | |
| 1468 | switch (sap1->sa_family) { |
| 1469 | case AF_INET: { |
| 1470 | struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1; |
| 1471 | struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2; |
| 1472 | if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) |
| 1473 | return 0; |
| 1474 | if (sin1->sin_port != sin2->sin_port) |
| 1475 | return 0; |
| 1476 | break; |
| 1477 | } |
| 1478 | case AF_INET6: { |
| 1479 | struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1; |
| 1480 | struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2; |
| 1481 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
| 1482 | return 0; |
| 1483 | if (sin1->sin6_port != sin2->sin6_port) |
| 1484 | return 0; |
| 1485 | break; |
| 1486 | } |
| 1487 | default: |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
| 1491 | return 1; |
| 1492 | } |
| 1493 | |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1494 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 1495 | { |
| 1496 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1497 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 1498 | int mntflags = sb_mntdata->mntflags; |
| 1499 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1500 | if (!nfs_compare_super_address(old, server)) |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1501 | return 0; |
| 1502 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 1503 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 1504 | return 0; |
| 1505 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 1506 | return 0; |
| 1507 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1508 | } |
| 1509 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1510 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 1511 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 1512 | { |
| 1513 | struct nfs_server *server = NULL; |
| 1514 | struct super_block *s; |
| 1515 | struct nfs_fh mntfh; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1516 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1517 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1518 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1519 | struct nfs_sb_mountdata sb_mntdata = { |
| 1520 | .mntflags = flags, |
| 1521 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1522 | int error; |
| 1523 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1524 | security_init_mnt_opts(&data.lsm_opts); |
| 1525 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1526 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1527 | error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1528 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1529 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1530 | |
| 1531 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1532 | server = nfs_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1533 | if (IS_ERR(server)) { |
| 1534 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1535 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1536 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1537 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1538 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1539 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1540 | compare_super = NULL; |
| 1541 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1542 | /* 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] | 1543 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1544 | if (IS_ERR(s)) { |
| 1545 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1546 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1547 | } |
| 1548 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1549 | if (s->s_fs_info != server) { |
| 1550 | nfs_free_server(server); |
| 1551 | server = NULL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1552 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1553 | |
| 1554 | if (!s->s_root) { |
| 1555 | /* initial superblock/root creation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1556 | nfs_fill_super(s, &data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | mntroot = nfs_get_root(s, &mntfh); |
| 1560 | if (IS_ERR(mntroot)) { |
| 1561 | error = PTR_ERR(mntroot); |
| 1562 | goto error_splat_super; |
| 1563 | } |
| 1564 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1565 | error = security_sb_set_mnt_opts(s, &data.lsm_opts); |
| 1566 | if (error) |
| 1567 | goto error_splat_root; |
| 1568 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1569 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1570 | mnt->mnt_sb = s; |
| 1571 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1572 | error = 0; |
| 1573 | |
| 1574 | out: |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1575 | kfree(data.nfs_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1576 | kfree(data.mount_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1577 | security_free_mnt_opts(&data.lsm_opts); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1578 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1579 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1580 | out_err_nosb: |
| 1581 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1582 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1583 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1584 | error_splat_root: |
| 1585 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1586 | error_splat_super: |
| 1587 | up_write(&s->s_umount); |
| 1588 | deactivate_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1589 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1590 | } |
| 1591 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1592 | /* |
| 1593 | * Destroy an NFS2/3 superblock |
| 1594 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1595 | static void nfs_kill_super(struct super_block *s) |
| 1596 | { |
| 1597 | struct nfs_server *server = NFS_SB(s); |
| 1598 | |
| 1599 | kill_anon_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1600 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1601 | } |
| 1602 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1603 | /* |
| 1604 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 1605 | */ |
| 1606 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1607 | const char *dev_name, void *raw_data, |
| 1608 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1609 | { |
| 1610 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1611 | struct super_block *s; |
| 1612 | struct nfs_server *server; |
| 1613 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1614 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1615 | struct nfs_sb_mountdata sb_mntdata = { |
| 1616 | .mntflags = flags, |
| 1617 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1618 | int error; |
| 1619 | |
| 1620 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 1621 | |
| 1622 | /* create a new volume representation */ |
| 1623 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 1624 | if (IS_ERR(server)) { |
| 1625 | error = PTR_ERR(server); |
| 1626 | goto out_err_noserver; |
| 1627 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1628 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1629 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1630 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1631 | compare_super = NULL; |
| 1632 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1633 | /* 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] | 1634 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1635 | if (IS_ERR(s)) { |
| 1636 | error = PTR_ERR(s); |
| 1637 | goto out_err_nosb; |
| 1638 | } |
| 1639 | |
| 1640 | if (s->s_fs_info != server) { |
| 1641 | nfs_free_server(server); |
| 1642 | server = NULL; |
| 1643 | } |
| 1644 | |
| 1645 | if (!s->s_root) { |
| 1646 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1647 | nfs_clone_super(s, data->sb); |
| 1648 | } |
| 1649 | |
| 1650 | mntroot = nfs_get_root(s, data->fh); |
| 1651 | if (IS_ERR(mntroot)) { |
| 1652 | error = PTR_ERR(mntroot); |
| 1653 | goto error_splat_super; |
| 1654 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 1655 | 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] | 1656 | dput(mntroot); |
| 1657 | error = -ESTALE; |
| 1658 | goto error_splat_super; |
| 1659 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1660 | |
| 1661 | s->s_flags |= MS_ACTIVE; |
| 1662 | mnt->mnt_sb = s; |
| 1663 | mnt->mnt_root = mntroot; |
| 1664 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1665 | /* clone any lsm security options from the parent to the new sb */ |
| 1666 | security_sb_clone_mnt_opts(data->sb, s); |
| 1667 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1668 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 1669 | return 0; |
| 1670 | |
| 1671 | out_err_nosb: |
| 1672 | nfs_free_server(server); |
| 1673 | out_err_noserver: |
| 1674 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 1675 | return error; |
| 1676 | |
| 1677 | error_splat_super: |
| 1678 | up_write(&s->s_umount); |
| 1679 | deactivate_super(s); |
| 1680 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 1681 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1685 | |
| 1686 | /* |
| 1687 | * Finish setting up a cloned NFS4 superblock |
| 1688 | */ |
| 1689 | static void nfs4_clone_super(struct super_block *sb, |
| 1690 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1691 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1692 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1693 | sb->s_blocksize = old_sb->s_blocksize; |
| 1694 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1695 | sb->s_time_gran = 1; |
| 1696 | sb->s_op = old_sb->s_op; |
| 1697 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /* |
| 1701 | * Set up an NFS4 superblock |
| 1702 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1703 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1704 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1705 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1706 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1707 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1710 | /* |
Chuck Lever | 0d0f0c1 | 2007-12-10 14:58:00 -0500 | [diff] [blame] | 1711 | * If the user didn't specify a port, set the port number to |
| 1712 | * the NFS version 4 default port. |
| 1713 | */ |
| 1714 | static void nfs4_default_port(struct sockaddr *sap) |
| 1715 | { |
| 1716 | switch (sap->sa_family) { |
| 1717 | case AF_INET: { |
| 1718 | struct sockaddr_in *ap = (struct sockaddr_in *)sap; |
| 1719 | if (ap->sin_port == 0) |
| 1720 | ap->sin_port = htons(NFS_PORT); |
| 1721 | break; |
| 1722 | } |
| 1723 | case AF_INET6: { |
| 1724 | struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap; |
| 1725 | if (ap->sin6_port == 0) |
| 1726 | ap->sin6_port = htons(NFS_PORT); |
| 1727 | break; |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1733 | * Validate NFSv4 mount options |
| 1734 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1735 | static int nfs4_validate_mount_data(void *options, |
| 1736 | struct nfs_parsed_mount_data *args, |
| 1737 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1738 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1739 | struct sockaddr_in *ap; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1740 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1741 | char *c; |
| 1742 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1743 | memset(args, 0, sizeof(*args)); |
| 1744 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1745 | if (data == NULL) |
| 1746 | goto out_no_data; |
| 1747 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1748 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1749 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1750 | args->timeo = 600; |
| 1751 | args->retrans = 2; |
| 1752 | args->acregmin = 3; |
| 1753 | args->acregmax = 60; |
| 1754 | args->acdirmin = 30; |
| 1755 | args->acdirmax = 60; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1756 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1757 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1758 | switch (data->version) { |
| 1759 | case 1: |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1760 | ap = (struct sockaddr_in *)&args->nfs_server.address; |
| 1761 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1762 | goto out_no_address; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1763 | if (data->host_addrlen == 0) |
| 1764 | goto out_no_address; |
| 1765 | args->nfs_server.addrlen = data->host_addrlen; |
| 1766 | if (copy_from_user(ap, data->host_addr, data->host_addrlen)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1767 | return -EFAULT; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1768 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1769 | &args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1770 | goto out_no_address; |
| 1771 | |
Chuck Lever | 0d0f0c1 | 2007-12-10 14:58:00 -0500 | [diff] [blame] | 1772 | nfs4_default_port((struct sockaddr *) |
| 1773 | &args->nfs_server.address); |
| 1774 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1775 | switch (data->auth_flavourlen) { |
| 1776 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1777 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1778 | break; |
| 1779 | case 1: |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1780 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1781 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1782 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1783 | return -EFAULT; |
| 1784 | break; |
| 1785 | default: |
| 1786 | goto out_inval_auth; |
| 1787 | } |
| 1788 | |
| 1789 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 1790 | if (IS_ERR(c)) |
| 1791 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1792 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1793 | |
| 1794 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 1795 | if (IS_ERR(c)) |
| 1796 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1797 | args->nfs_server.export_path = c; |
| 1798 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1799 | |
| 1800 | c = strndup_user(data->client_addr.data, 16); |
| 1801 | if (IS_ERR(c)) |
| 1802 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1803 | args->client_address = c; |
| 1804 | |
| 1805 | /* |
| 1806 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 1807 | * can deal with. |
| 1808 | */ |
| 1809 | |
| 1810 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 1811 | args->rsize = data->rsize; |
| 1812 | args->wsize = data->wsize; |
| 1813 | args->timeo = data->timeo; |
| 1814 | args->retrans = data->retrans; |
| 1815 | args->acregmin = data->acregmin; |
| 1816 | args->acregmax = data->acregmax; |
| 1817 | args->acdirmin = data->acdirmin; |
| 1818 | args->acdirmax = data->acdirmax; |
| 1819 | args->nfs_server.protocol = data->proto; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1820 | |
| 1821 | break; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1822 | default: { |
| 1823 | unsigned int len; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1824 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1825 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1826 | return -EINVAL; |
| 1827 | |
| 1828 | if (!nfs_verify_server_address((struct sockaddr *) |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1829 | &args->nfs_server.address)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1830 | return -EINVAL; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1831 | |
Chuck Lever | 0d0f0c1 | 2007-12-10 14:58:00 -0500 | [diff] [blame] | 1832 | nfs4_default_port((struct sockaddr *) |
| 1833 | &args->nfs_server.address); |
| 1834 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1835 | switch (args->auth_flavor_len) { |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1836 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1837 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1838 | break; |
| 1839 | case 1: |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1840 | break; |
| 1841 | default: |
| 1842 | goto out_inval_auth; |
| 1843 | } |
| 1844 | |
| 1845 | /* |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1846 | * Split "dev_name" into "hostname:mntpath". |
| 1847 | */ |
| 1848 | c = strchr(dev_name, ':'); |
| 1849 | if (c == NULL) |
| 1850 | return -EINVAL; |
| 1851 | /* while calculating len, pretend ':' is '\0' */ |
| 1852 | len = c - dev_name; |
| 1853 | if (len > NFS4_MAXNAMLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1854 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1855 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1856 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1857 | |
| 1858 | c++; /* step over the ':' */ |
| 1859 | len = strlen(c); |
| 1860 | if (len > NFS4_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1861 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1862 | args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1863 | |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1864 | dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path); |
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 (args->client_address == NULL) |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1867 | goto out_no_client_address; |
| 1868 | |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1869 | break; |
| 1870 | } |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | return 0; |
| 1874 | |
| 1875 | out_no_data: |
| 1876 | dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n"); |
| 1877 | return -EINVAL; |
| 1878 | |
| 1879 | out_inval_auth: |
| 1880 | dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n", |
| 1881 | data->auth_flavourlen); |
| 1882 | return -EINVAL; |
| 1883 | |
| 1884 | out_no_address: |
| 1885 | dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); |
| 1886 | return -EINVAL; |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1887 | |
| 1888 | out_no_client_address: |
| 1889 | dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n"); |
| 1890 | return -EINVAL; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1894 | * Get the superblock for an NFS4 mountpoint |
| 1895 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1896 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 1897 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1898 | { |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1899 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1900 | struct super_block *s; |
| 1901 | struct nfs_server *server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1902 | struct nfs_fh mntfh; |
| 1903 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1904 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1905 | struct nfs_sb_mountdata sb_mntdata = { |
| 1906 | .mntflags = flags, |
| 1907 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1908 | int error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1909 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1910 | security_init_mnt_opts(&data.lsm_opts); |
| 1911 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1912 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1913 | error = nfs4_validate_mount_data(raw_data, &data, dev_name); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1914 | if (error < 0) |
| 1915 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1916 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1917 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1918 | server = nfs4_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1919 | if (IS_ERR(server)) { |
| 1920 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1921 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1922 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1923 | sb_mntdata.server = server; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1924 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1925 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 1926 | compare_super = NULL; |
| 1927 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1928 | /* 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] | 1929 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1930 | if (IS_ERR(s)) { |
| 1931 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1932 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1933 | } |
| 1934 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 1935 | if (s->s_fs_info != server) { |
| 1936 | nfs_free_server(server); |
| 1937 | server = NULL; |
| 1938 | } |
| 1939 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1940 | if (!s->s_root) { |
| 1941 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1942 | nfs4_fill_super(s); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1943 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1944 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1945 | mntroot = nfs4_get_root(s, &mntfh); |
| 1946 | if (IS_ERR(mntroot)) { |
| 1947 | error = PTR_ERR(mntroot); |
| 1948 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1949 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1950 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1951 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1952 | mnt->mnt_sb = s; |
| 1953 | mnt->mnt_root = mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1954 | error = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1955 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1956 | out: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1957 | kfree(data.client_address); |
| 1958 | kfree(data.nfs_server.export_path); |
| 1959 | kfree(data.nfs_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1960 | security_free_mnt_opts(&data.lsm_opts); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1961 | return error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1962 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1963 | out_free: |
| 1964 | nfs_free_server(server); |
| 1965 | goto out; |
| 1966 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1967 | error_splat_super: |
| 1968 | up_write(&s->s_umount); |
| 1969 | deactivate_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1970 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static void nfs4_kill_super(struct super_block *sb) |
| 1974 | { |
| 1975 | struct nfs_server *server = NFS_SB(sb); |
| 1976 | |
| 1977 | nfs_return_all_delegations(sb); |
| 1978 | kill_anon_super(sb); |
| 1979 | |
| 1980 | nfs4_renewd_prepare_shutdown(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1981 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1985 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1986 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1987 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1988 | const char *dev_name, void *raw_data, |
| 1989 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1990 | { |
| 1991 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1992 | struct super_block *s; |
| 1993 | struct nfs_server *server; |
| 1994 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1995 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1996 | struct nfs_sb_mountdata sb_mntdata = { |
| 1997 | .mntflags = flags, |
| 1998 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1999 | int error; |
| 2000 | |
| 2001 | dprintk("--> nfs4_xdev_get_sb()\n"); |
| 2002 | |
| 2003 | /* create a new volume representation */ |
| 2004 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2005 | if (IS_ERR(server)) { |
| 2006 | error = PTR_ERR(server); |
| 2007 | goto out_err_noserver; |
| 2008 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2009 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2010 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2011 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2012 | compare_super = NULL; |
| 2013 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2014 | /* 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] | 2015 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2016 | if (IS_ERR(s)) { |
| 2017 | error = PTR_ERR(s); |
| 2018 | goto out_err_nosb; |
| 2019 | } |
| 2020 | |
| 2021 | if (s->s_fs_info != server) { |
| 2022 | nfs_free_server(server); |
| 2023 | server = NULL; |
| 2024 | } |
| 2025 | |
| 2026 | if (!s->s_root) { |
| 2027 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2028 | nfs4_clone_super(s, data->sb); |
| 2029 | } |
| 2030 | |
| 2031 | mntroot = nfs4_get_root(s, data->fh); |
| 2032 | if (IS_ERR(mntroot)) { |
| 2033 | error = PTR_ERR(mntroot); |
| 2034 | goto error_splat_super; |
| 2035 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2036 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2037 | dput(mntroot); |
| 2038 | error = -ESTALE; |
| 2039 | goto error_splat_super; |
| 2040 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2041 | |
| 2042 | s->s_flags |= MS_ACTIVE; |
| 2043 | mnt->mnt_sb = s; |
| 2044 | mnt->mnt_root = mntroot; |
| 2045 | |
| 2046 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); |
| 2047 | return 0; |
| 2048 | |
| 2049 | out_err_nosb: |
| 2050 | nfs_free_server(server); |
| 2051 | out_err_noserver: |
| 2052 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); |
| 2053 | return error; |
| 2054 | |
| 2055 | error_splat_super: |
| 2056 | up_write(&s->s_umount); |
| 2057 | deactivate_super(s); |
| 2058 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
| 2059 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2060 | } |
| 2061 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2062 | /* |
| 2063 | * Create an NFS4 server record on referral traversal |
| 2064 | */ |
| 2065 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags, |
| 2066 | const char *dev_name, void *raw_data, |
| 2067 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2068 | { |
| 2069 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2070 | struct super_block *s; |
| 2071 | struct nfs_server *server; |
| 2072 | struct dentry *mntroot; |
| 2073 | struct nfs_fh mntfh; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2074 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2075 | struct nfs_sb_mountdata sb_mntdata = { |
| 2076 | .mntflags = flags, |
| 2077 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2078 | int error; |
| 2079 | |
| 2080 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2081 | |
| 2082 | /* create a new volume representation */ |
| 2083 | server = nfs4_create_referral_server(data, &mntfh); |
| 2084 | if (IS_ERR(server)) { |
| 2085 | error = PTR_ERR(server); |
| 2086 | goto out_err_noserver; |
| 2087 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2088 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2089 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2090 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2091 | compare_super = NULL; |
| 2092 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2093 | /* 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] | 2094 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2095 | if (IS_ERR(s)) { |
| 2096 | error = PTR_ERR(s); |
| 2097 | goto out_err_nosb; |
| 2098 | } |
| 2099 | |
| 2100 | if (s->s_fs_info != server) { |
| 2101 | nfs_free_server(server); |
| 2102 | server = NULL; |
| 2103 | } |
| 2104 | |
| 2105 | if (!s->s_root) { |
| 2106 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2107 | nfs4_fill_super(s); |
| 2108 | } |
| 2109 | |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 2110 | mntroot = nfs4_get_root(s, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2111 | if (IS_ERR(mntroot)) { |
| 2112 | error = PTR_ERR(mntroot); |
| 2113 | goto error_splat_super; |
| 2114 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2115 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2116 | dput(mntroot); |
| 2117 | error = -ESTALE; |
| 2118 | goto error_splat_super; |
| 2119 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2120 | |
| 2121 | s->s_flags |= MS_ACTIVE; |
| 2122 | mnt->mnt_sb = s; |
| 2123 | mnt->mnt_root = mntroot; |
| 2124 | |
| 2125 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
| 2126 | return 0; |
| 2127 | |
| 2128 | out_err_nosb: |
| 2129 | nfs_free_server(server); |
| 2130 | out_err_noserver: |
| 2131 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
| 2132 | return error; |
| 2133 | |
| 2134 | error_splat_super: |
| 2135 | up_write(&s->s_umount); |
| 2136 | deactivate_super(s); |
| 2137 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
| 2138 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2139 | } |
| 2140 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2141 | #endif /* CONFIG_NFS_V4 */ |