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 | |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 466 | seq_printf(m, ",vers=%u", clp->rpc_ops->version); |
| 467 | seq_printf(m, ",rsize=%u", nfss->rsize); |
| 468 | seq_printf(m, ",wsize=%u", nfss->wsize); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 469 | if (nfss->acregmin != 3*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 470 | seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 471 | if (nfss->acregmax != 60*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 472 | seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 473 | if (nfss->acdirmin != 30*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 474 | seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 475 | if (nfss->acdirmax != 60*HZ || showdefaults) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 476 | seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 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); |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 532 | seq_printf(m, ",wtmult=%u", nfss->wtmult); |
| 533 | seq_printf(m, ",dtsize=%u", nfss->dtsize); |
| 534 | seq_printf(m, ",bsize=%u", nfss->bsize); |
| 535 | seq_printf(m, ",namlen=%u", nfss->namelen); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 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 | */ |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 549 | seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 550 | if (auth->au_flavor) |
Chuck Lever | 2d76743 | 2008-03-14 14:10:08 -0400 | [diff] [blame] | 551 | seq_printf(m, ",pseudoflavor=%u", auth->au_flavor); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 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; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 688 | int rc; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 689 | |
| 690 | if (!raw) { |
| 691 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 692 | return 1; |
| 693 | } |
| 694 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 695 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 696 | secdata = alloc_secdata(); |
| 697 | if (!secdata) |
| 698 | goto out_nomem; |
| 699 | |
| 700 | rc = security_sb_copy_data(raw, secdata); |
| 701 | if (rc) |
| 702 | goto out_security_failure; |
| 703 | |
| 704 | rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts); |
| 705 | if (rc) |
| 706 | goto out_security_failure; |
| 707 | |
| 708 | free_secdata(secdata); |
| 709 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 710 | while ((p = strsep(&raw, ",")) != NULL) { |
| 711 | substring_t args[MAX_OPT_ARGS]; |
| 712 | int option, token; |
| 713 | |
| 714 | if (!*p) |
| 715 | continue; |
| 716 | |
| 717 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 718 | |
| 719 | token = match_token(p, nfs_mount_option_tokens, args); |
| 720 | switch (token) { |
| 721 | case Opt_soft: |
| 722 | mnt->flags |= NFS_MOUNT_SOFT; |
| 723 | break; |
| 724 | case Opt_hard: |
| 725 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 726 | break; |
| 727 | case Opt_intr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 728 | case Opt_nointr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 729 | break; |
| 730 | case Opt_posix: |
| 731 | mnt->flags |= NFS_MOUNT_POSIX; |
| 732 | break; |
| 733 | case Opt_noposix: |
| 734 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 735 | break; |
| 736 | case Opt_cto: |
| 737 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 738 | break; |
| 739 | case Opt_nocto: |
| 740 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 741 | break; |
| 742 | case Opt_ac: |
| 743 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 744 | break; |
| 745 | case Opt_noac: |
| 746 | mnt->flags |= NFS_MOUNT_NOAC; |
| 747 | break; |
| 748 | case Opt_lock: |
| 749 | mnt->flags &= ~NFS_MOUNT_NONLM; |
| 750 | break; |
| 751 | case Opt_nolock: |
| 752 | mnt->flags |= NFS_MOUNT_NONLM; |
| 753 | break; |
| 754 | case Opt_v2: |
| 755 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 756 | break; |
| 757 | case Opt_v3: |
| 758 | mnt->flags |= NFS_MOUNT_VER3; |
| 759 | break; |
| 760 | case Opt_udp: |
| 761 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 762 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 763 | mnt->timeo = 7; |
| 764 | mnt->retrans = 5; |
| 765 | break; |
| 766 | case Opt_tcp: |
| 767 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 768 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 769 | mnt->timeo = 600; |
| 770 | mnt->retrans = 2; |
| 771 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 772 | case Opt_rdma: |
| 773 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 774 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 775 | mnt->timeo = 600; |
| 776 | mnt->retrans = 2; |
| 777 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 778 | case Opt_acl: |
| 779 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 780 | break; |
| 781 | case Opt_noacl: |
| 782 | mnt->flags |= NFS_MOUNT_NOACL; |
| 783 | break; |
| 784 | case Opt_rdirplus: |
| 785 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 786 | break; |
| 787 | case Opt_nordirplus: |
| 788 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 789 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 790 | case Opt_sharecache: |
| 791 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 792 | break; |
| 793 | case Opt_nosharecache: |
| 794 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 795 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 796 | |
| 797 | case Opt_port: |
| 798 | if (match_int(args, &option)) |
| 799 | return 0; |
| 800 | if (option < 0 || option > 65535) |
| 801 | return 0; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame^] | 802 | mnt->nfs_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 803 | break; |
| 804 | case Opt_rsize: |
| 805 | if (match_int(args, &mnt->rsize)) |
| 806 | return 0; |
| 807 | break; |
| 808 | case Opt_wsize: |
| 809 | if (match_int(args, &mnt->wsize)) |
| 810 | return 0; |
| 811 | break; |
| 812 | case Opt_bsize: |
| 813 | if (match_int(args, &option)) |
| 814 | return 0; |
| 815 | if (option < 0) |
| 816 | return 0; |
| 817 | mnt->bsize = option; |
| 818 | break; |
| 819 | case Opt_timeo: |
| 820 | if (match_int(args, &mnt->timeo)) |
| 821 | return 0; |
| 822 | break; |
| 823 | case Opt_retrans: |
| 824 | if (match_int(args, &mnt->retrans)) |
| 825 | return 0; |
| 826 | break; |
| 827 | case Opt_acregmin: |
| 828 | if (match_int(args, &mnt->acregmin)) |
| 829 | return 0; |
| 830 | break; |
| 831 | case Opt_acregmax: |
| 832 | if (match_int(args, &mnt->acregmax)) |
| 833 | return 0; |
| 834 | break; |
| 835 | case Opt_acdirmin: |
| 836 | if (match_int(args, &mnt->acdirmin)) |
| 837 | return 0; |
| 838 | break; |
| 839 | case Opt_acdirmax: |
| 840 | if (match_int(args, &mnt->acdirmax)) |
| 841 | return 0; |
| 842 | break; |
| 843 | case Opt_actimeo: |
| 844 | if (match_int(args, &option)) |
| 845 | return 0; |
| 846 | if (option < 0) |
| 847 | return 0; |
| 848 | mnt->acregmin = |
| 849 | mnt->acregmax = |
| 850 | mnt->acdirmin = |
| 851 | mnt->acdirmax = option; |
| 852 | break; |
| 853 | case Opt_namelen: |
| 854 | if (match_int(args, &mnt->namlen)) |
| 855 | return 0; |
| 856 | break; |
| 857 | case Opt_mountport: |
| 858 | if (match_int(args, &option)) |
| 859 | return 0; |
| 860 | if (option < 0 || option > 65535) |
| 861 | return 0; |
| 862 | mnt->mount_server.port = option; |
| 863 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 864 | case Opt_mountvers: |
| 865 | if (match_int(args, &option)) |
| 866 | return 0; |
| 867 | if (option < 0) |
| 868 | return 0; |
| 869 | mnt->mount_server.version = option; |
| 870 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 871 | case Opt_nfsvers: |
| 872 | if (match_int(args, &option)) |
| 873 | return 0; |
| 874 | switch (option) { |
| 875 | case 2: |
| 876 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 877 | break; |
| 878 | case 3: |
| 879 | mnt->flags |= NFS_MOUNT_VER3; |
| 880 | break; |
| 881 | default: |
| 882 | goto out_unrec_vers; |
| 883 | } |
| 884 | break; |
| 885 | |
| 886 | case Opt_sec: |
| 887 | string = match_strdup(args); |
| 888 | if (string == NULL) |
| 889 | goto out_nomem; |
| 890 | token = match_token(string, nfs_secflavor_tokens, args); |
| 891 | kfree(string); |
| 892 | |
| 893 | /* |
| 894 | * The flags setting is for v2/v3. The flavor_len |
| 895 | * setting is for v4. v2/v3 also need to know the |
| 896 | * difference between NULL and UNIX. |
| 897 | */ |
| 898 | switch (token) { |
| 899 | case Opt_sec_none: |
| 900 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 901 | mnt->auth_flavor_len = 0; |
| 902 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 903 | break; |
| 904 | case Opt_sec_sys: |
| 905 | mnt->flags &= ~NFS_MOUNT_SECFLAVOUR; |
| 906 | mnt->auth_flavor_len = 0; |
| 907 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 908 | break; |
| 909 | case Opt_sec_krb5: |
| 910 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 911 | mnt->auth_flavor_len = 1; |
| 912 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 913 | break; |
| 914 | case Opt_sec_krb5i: |
| 915 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 916 | mnt->auth_flavor_len = 1; |
| 917 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 918 | break; |
| 919 | case Opt_sec_krb5p: |
| 920 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 921 | mnt->auth_flavor_len = 1; |
| 922 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 923 | break; |
| 924 | case Opt_sec_lkey: |
| 925 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 926 | mnt->auth_flavor_len = 1; |
| 927 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 928 | break; |
| 929 | case Opt_sec_lkeyi: |
| 930 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 931 | mnt->auth_flavor_len = 1; |
| 932 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 933 | break; |
| 934 | case Opt_sec_lkeyp: |
| 935 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 936 | mnt->auth_flavor_len = 1; |
| 937 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 938 | break; |
| 939 | case Opt_sec_spkm: |
| 940 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 941 | mnt->auth_flavor_len = 1; |
| 942 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 943 | break; |
| 944 | case Opt_sec_spkmi: |
| 945 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 946 | mnt->auth_flavor_len = 1; |
| 947 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 948 | break; |
| 949 | case Opt_sec_spkmp: |
| 950 | mnt->flags |= NFS_MOUNT_SECFLAVOUR; |
| 951 | mnt->auth_flavor_len = 1; |
| 952 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 953 | break; |
| 954 | default: |
| 955 | goto out_unrec_sec; |
| 956 | } |
| 957 | break; |
| 958 | case Opt_proto: |
| 959 | string = match_strdup(args); |
| 960 | if (string == NULL) |
| 961 | goto out_nomem; |
| 962 | token = match_token(string, |
| 963 | nfs_xprt_protocol_tokens, args); |
| 964 | kfree(string); |
| 965 | |
| 966 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 967 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 968 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 969 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 970 | mnt->timeo = 7; |
| 971 | mnt->retrans = 5; |
| 972 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 973 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 974 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 975 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 976 | mnt->timeo = 600; |
| 977 | mnt->retrans = 2; |
| 978 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 979 | case Opt_xprt_rdma: |
| 980 | /* vector side protocols to TCP */ |
| 981 | mnt->flags |= NFS_MOUNT_TCP; |
| 982 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
| 983 | mnt->timeo = 600; |
| 984 | mnt->retrans = 2; |
| 985 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 986 | default: |
| 987 | goto out_unrec_xprt; |
| 988 | } |
| 989 | break; |
| 990 | case Opt_mountproto: |
| 991 | string = match_strdup(args); |
| 992 | if (string == NULL) |
| 993 | goto out_nomem; |
| 994 | token = match_token(string, |
| 995 | nfs_xprt_protocol_tokens, args); |
| 996 | kfree(string); |
| 997 | |
| 998 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 999 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1000 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1001 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1002 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1003 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1004 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1005 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1006 | default: |
| 1007 | goto out_unrec_xprt; |
| 1008 | } |
| 1009 | break; |
| 1010 | case Opt_addr: |
| 1011 | string = match_strdup(args); |
| 1012 | if (string == NULL) |
| 1013 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1014 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1015 | &mnt->nfs_server.address, |
| 1016 | &mnt->nfs_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1017 | kfree(string); |
| 1018 | break; |
| 1019 | case Opt_clientaddr: |
| 1020 | string = match_strdup(args); |
| 1021 | if (string == NULL) |
| 1022 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1023 | kfree(mnt->client_address); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1024 | mnt->client_address = string; |
| 1025 | break; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1026 | case Opt_mounthost: |
| 1027 | string = match_strdup(args); |
| 1028 | if (string == NULL) |
| 1029 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1030 | kfree(mnt->mount_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1031 | mnt->mount_server.hostname = string; |
| 1032 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 1033 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1034 | string = match_strdup(args); |
| 1035 | if (string == NULL) |
| 1036 | goto out_nomem; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 1037 | nfs_parse_server_address(string, (struct sockaddr *) |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1038 | &mnt->mount_server.address, |
| 1039 | &mnt->mount_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1040 | kfree(string); |
| 1041 | break; |
| 1042 | |
| 1043 | case Opt_userspace: |
| 1044 | case Opt_deprecated: |
| 1045 | break; |
| 1046 | |
| 1047 | default: |
| 1048 | goto out_unknown; |
| 1049 | } |
| 1050 | } |
| 1051 | |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame^] | 1052 | nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, |
| 1053 | mnt->nfs_server.port); |
Chuck Lever | 04dcd6e | 2007-12-10 14:57:53 -0500 | [diff] [blame] | 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; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame^] | 1174 | args->mount_server.port = 0; /* autobind unless user sets port */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1175 | args->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame^] | 1176 | args->nfs_server.port = 0; /* autobind unless user sets port */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1177 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1178 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1179 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1180 | case 1: |
| 1181 | data->namlen = 0; |
| 1182 | case 2: |
| 1183 | data->bsize = 0; |
| 1184 | case 3: |
| 1185 | if (data->flags & NFS_MOUNT_VER3) |
| 1186 | goto out_no_v3; |
| 1187 | data->root.size = NFS2_FHSIZE; |
| 1188 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1189 | case 4: |
| 1190 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1191 | goto out_no_sec; |
| 1192 | case 5: |
| 1193 | memset(data->context, 0, sizeof(data->context)); |
| 1194 | case 6: |
| 1195 | if (data->flags & NFS_MOUNT_VER3) |
| 1196 | mntfh->size = data->root.size; |
| 1197 | else |
| 1198 | mntfh->size = NFS2_FHSIZE; |
| 1199 | |
| 1200 | if (mntfh->size > sizeof(mntfh->data)) |
| 1201 | goto out_invalid_fh; |
| 1202 | |
| 1203 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1204 | if (mntfh->size < sizeof(mntfh->data)) |
| 1205 | memset(mntfh->data + mntfh->size, 0, |
| 1206 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1207 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1208 | /* |
| 1209 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1210 | * can deal with. |
| 1211 | */ |
| 1212 | args->flags = data->flags; |
| 1213 | args->rsize = data->rsize; |
| 1214 | args->wsize = data->wsize; |
| 1215 | args->flags = data->flags; |
| 1216 | args->timeo = data->timeo; |
| 1217 | args->retrans = data->retrans; |
| 1218 | args->acregmin = data->acregmin; |
| 1219 | args->acregmax = data->acregmax; |
| 1220 | args->acdirmin = data->acdirmin; |
| 1221 | args->acdirmax = data->acdirmax; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1222 | |
| 1223 | memcpy(&args->nfs_server.address, &data->addr, |
| 1224 | sizeof(data->addr)); |
| 1225 | args->nfs_server.addrlen = sizeof(data->addr); |
| 1226 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1227 | &args->nfs_server.address)) |
| 1228 | goto out_no_address; |
| 1229 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1230 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1231 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1232 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1233 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1234 | args->namlen = data->namlen; |
| 1235 | args->bsize = data->bsize; |
| 1236 | args->auth_flavors[0] = data->pseudoflavor; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1237 | |
| 1238 | /* |
| 1239 | * The legacy version 6 binary mount data from userspace has a |
| 1240 | * field used only to transport selinux information into the |
| 1241 | * the kernel. To continue to support that functionality we |
| 1242 | * have a touch of selinux knowledge here in the NFS code. The |
| 1243 | * userspace code converted context=blah to just blah so we are |
| 1244 | * converting back to the full string selinux understands. |
| 1245 | */ |
| 1246 | if (data->context[0]){ |
| 1247 | #ifdef CONFIG_SECURITY_SELINUX |
| 1248 | int rc; |
| 1249 | char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL); |
| 1250 | if (!opts_str) |
| 1251 | return -ENOMEM; |
| 1252 | strcpy(opts_str, "context="); |
| 1253 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
| 1254 | strcat(opts_str, &data->context[0]); |
| 1255 | rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts); |
| 1256 | kfree(opts_str); |
| 1257 | if (rc) |
| 1258 | return rc; |
| 1259 | #else |
| 1260 | return -EINVAL; |
| 1261 | #endif |
| 1262 | } |
| 1263 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1264 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1265 | default: { |
| 1266 | unsigned int len; |
| 1267 | char *c; |
| 1268 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1269 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1270 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1271 | return -EINVAL; |
| 1272 | |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1273 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1274 | &args->nfs_server.address)) |
| 1275 | goto out_no_address; |
| 1276 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1277 | c = strchr(dev_name, ':'); |
| 1278 | if (c == NULL) |
| 1279 | return -EINVAL; |
Chuck Lever | 350c73a | 2007-08-29 17:59:01 -0400 | [diff] [blame] | 1280 | len = c - dev_name; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1281 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1282 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1283 | |
| 1284 | c++; |
| 1285 | if (strlen(c) > NFS_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1286 | return -ENAMETOOLONG; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1287 | args->nfs_server.export_path = c; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1288 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1289 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1290 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1291 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1292 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1293 | break; |
| 1294 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1295 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1296 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1297 | if (!(args->flags & NFS_MOUNT_SECFLAVOUR)) |
| 1298 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Trond Myklebust | 36b15c5 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 1299 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1300 | #ifndef CONFIG_NFS_V3 |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1301 | if (args->flags & NFS_MOUNT_VER3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1302 | goto out_v3_not_compiled; |
| 1303 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1304 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1305 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1306 | |
| 1307 | out_no_data: |
| 1308 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1309 | return -EINVAL; |
| 1310 | |
| 1311 | out_no_v3: |
| 1312 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1313 | data->version); |
| 1314 | return -EINVAL; |
| 1315 | |
| 1316 | out_no_sec: |
| 1317 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1318 | return -EINVAL; |
| 1319 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1320 | #ifndef CONFIG_NFS_V3 |
| 1321 | out_v3_not_compiled: |
| 1322 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1323 | return -EPROTONOSUPPORT; |
| 1324 | #endif /* !CONFIG_NFS_V3 */ |
| 1325 | |
| 1326 | out_no_address: |
| 1327 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1328 | return -EINVAL; |
| 1329 | |
| 1330 | out_invalid_fh: |
| 1331 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1332 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | /* |
| 1336 | * Initialise the common bits of the superblock |
| 1337 | */ |
| 1338 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 1339 | { |
| 1340 | struct nfs_server *server = NFS_SB(sb); |
| 1341 | |
| 1342 | sb->s_magic = NFS_SUPER_MAGIC; |
| 1343 | |
| 1344 | /* We probably want something more informative here */ |
| 1345 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 1346 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 1347 | |
| 1348 | if (sb->s_blocksize == 0) |
| 1349 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 1350 | &sb->s_blocksize_bits); |
| 1351 | |
| 1352 | if (server->flags & NFS_MOUNT_NOAC) |
| 1353 | sb->s_flags |= MS_SYNCHRONOUS; |
| 1354 | |
| 1355 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 1356 | } |
| 1357 | |
| 1358 | /* |
| 1359 | * Finish setting up an NFS2/3 superblock |
| 1360 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1361 | static void nfs_fill_super(struct super_block *sb, |
| 1362 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1363 | { |
| 1364 | struct nfs_server *server = NFS_SB(sb); |
| 1365 | |
| 1366 | sb->s_blocksize_bits = 0; |
| 1367 | sb->s_blocksize = 0; |
| 1368 | if (data->bsize) |
| 1369 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 1370 | |
| 1371 | if (server->flags & NFS_MOUNT_VER3) { |
| 1372 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1373 | * so ourselves when necessary. |
| 1374 | */ |
| 1375 | sb->s_flags |= MS_POSIXACL; |
| 1376 | sb->s_time_gran = 1; |
| 1377 | } |
| 1378 | |
| 1379 | sb->s_op = &nfs_sops; |
| 1380 | nfs_initialise_sb(sb); |
| 1381 | } |
| 1382 | |
| 1383 | /* |
| 1384 | * Finish setting up a cloned NFS2/3 superblock |
| 1385 | */ |
| 1386 | static void nfs_clone_super(struct super_block *sb, |
| 1387 | const struct super_block *old_sb) |
| 1388 | { |
| 1389 | struct nfs_server *server = NFS_SB(sb); |
| 1390 | |
| 1391 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1392 | sb->s_blocksize = old_sb->s_blocksize; |
| 1393 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1394 | |
| 1395 | if (server->flags & NFS_MOUNT_VER3) { |
| 1396 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1397 | * so ourselves when necessary. |
| 1398 | */ |
| 1399 | sb->s_flags |= MS_POSIXACL; |
| 1400 | sb->s_time_gran = 1; |
| 1401 | } |
| 1402 | |
| 1403 | sb->s_op = old_sb->s_op; |
| 1404 | nfs_initialise_sb(sb); |
| 1405 | } |
| 1406 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1407 | #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) |
| 1408 | |
| 1409 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 1410 | { |
| 1411 | const struct nfs_server *a = s->s_fs_info; |
| 1412 | const struct rpc_clnt *clnt_a = a->client; |
| 1413 | const struct rpc_clnt *clnt_b = b->client; |
| 1414 | |
| 1415 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 1416 | goto Ebusy; |
| 1417 | if (a->nfs_client != b->nfs_client) |
| 1418 | goto Ebusy; |
| 1419 | if (a->flags != b->flags) |
| 1420 | goto Ebusy; |
| 1421 | if (a->wsize != b->wsize) |
| 1422 | goto Ebusy; |
| 1423 | if (a->rsize != b->rsize) |
| 1424 | goto Ebusy; |
| 1425 | if (a->acregmin != b->acregmin) |
| 1426 | goto Ebusy; |
| 1427 | if (a->acregmax != b->acregmax) |
| 1428 | goto Ebusy; |
| 1429 | if (a->acdirmin != b->acdirmin) |
| 1430 | goto Ebusy; |
| 1431 | if (a->acdirmax != b->acdirmax) |
| 1432 | goto Ebusy; |
| 1433 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 1434 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1435 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1436 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1437 | return 0; |
| 1438 | } |
| 1439 | |
| 1440 | struct nfs_sb_mountdata { |
| 1441 | struct nfs_server *server; |
| 1442 | int mntflags; |
| 1443 | }; |
| 1444 | |
| 1445 | static int nfs_set_super(struct super_block *s, void *data) |
| 1446 | { |
| 1447 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1448 | struct nfs_server *server = sb_mntdata->server; |
| 1449 | int ret; |
| 1450 | |
| 1451 | s->s_flags = sb_mntdata->mntflags; |
| 1452 | s->s_fs_info = server; |
| 1453 | ret = set_anon_super(s, server); |
| 1454 | if (ret == 0) |
| 1455 | server->s_dev = s->s_dev; |
| 1456 | return ret; |
| 1457 | } |
| 1458 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1459 | static int nfs_compare_super_address(struct nfs_server *server1, |
| 1460 | struct nfs_server *server2) |
| 1461 | { |
| 1462 | struct sockaddr *sap1, *sap2; |
| 1463 | |
| 1464 | sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr; |
| 1465 | sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr; |
| 1466 | |
| 1467 | if (sap1->sa_family != sap2->sa_family) |
| 1468 | return 0; |
| 1469 | |
| 1470 | switch (sap1->sa_family) { |
| 1471 | case AF_INET: { |
| 1472 | struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1; |
| 1473 | struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2; |
| 1474 | if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) |
| 1475 | return 0; |
| 1476 | if (sin1->sin_port != sin2->sin_port) |
| 1477 | return 0; |
| 1478 | break; |
| 1479 | } |
| 1480 | case AF_INET6: { |
| 1481 | struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1; |
| 1482 | struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2; |
| 1483 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
| 1484 | return 0; |
| 1485 | if (sin1->sin6_port != sin2->sin6_port) |
| 1486 | return 0; |
| 1487 | break; |
| 1488 | } |
| 1489 | default: |
| 1490 | return 0; |
| 1491 | } |
| 1492 | |
| 1493 | return 1; |
| 1494 | } |
| 1495 | |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1496 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 1497 | { |
| 1498 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 1499 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 1500 | int mntflags = sb_mntdata->mntflags; |
| 1501 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 1502 | if (!nfs_compare_super_address(old, server)) |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1503 | return 0; |
| 1504 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 1505 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 1506 | return 0; |
| 1507 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 1508 | return 0; |
| 1509 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1510 | } |
| 1511 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1512 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 1513 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 1514 | { |
| 1515 | struct nfs_server *server = NULL; |
| 1516 | struct super_block *s; |
| 1517 | struct nfs_fh mntfh; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1518 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1519 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1520 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1521 | struct nfs_sb_mountdata sb_mntdata = { |
| 1522 | .mntflags = flags, |
| 1523 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1524 | int error; |
| 1525 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1526 | security_init_mnt_opts(&data.lsm_opts); |
| 1527 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1528 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1529 | error = nfs_validate_mount_data(raw_data, &data, &mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1530 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1531 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1532 | |
| 1533 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1534 | server = nfs_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1535 | if (IS_ERR(server)) { |
| 1536 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1537 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1538 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1539 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1540 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1541 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1542 | compare_super = NULL; |
| 1543 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1544 | /* 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] | 1545 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1546 | if (IS_ERR(s)) { |
| 1547 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1548 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1549 | } |
| 1550 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1551 | if (s->s_fs_info != server) { |
| 1552 | nfs_free_server(server); |
| 1553 | server = NULL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1554 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1555 | |
| 1556 | if (!s->s_root) { |
| 1557 | /* initial superblock/root creation */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1558 | nfs_fill_super(s, &data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | mntroot = nfs_get_root(s, &mntfh); |
| 1562 | if (IS_ERR(mntroot)) { |
| 1563 | error = PTR_ERR(mntroot); |
| 1564 | goto error_splat_super; |
| 1565 | } |
| 1566 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1567 | error = security_sb_set_mnt_opts(s, &data.lsm_opts); |
| 1568 | if (error) |
| 1569 | goto error_splat_root; |
| 1570 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1571 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1572 | mnt->mnt_sb = s; |
| 1573 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1574 | error = 0; |
| 1575 | |
| 1576 | out: |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1577 | kfree(data.nfs_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1578 | kfree(data.mount_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1579 | security_free_mnt_opts(&data.lsm_opts); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1580 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1581 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1582 | out_err_nosb: |
| 1583 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1584 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1585 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1586 | error_splat_root: |
| 1587 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1588 | error_splat_super: |
| 1589 | up_write(&s->s_umount); |
| 1590 | deactivate_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 1591 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1592 | } |
| 1593 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1594 | /* |
| 1595 | * Destroy an NFS2/3 superblock |
| 1596 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1597 | static void nfs_kill_super(struct super_block *s) |
| 1598 | { |
| 1599 | struct nfs_server *server = NFS_SB(s); |
| 1600 | |
| 1601 | kill_anon_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1602 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1605 | /* |
| 1606 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 1607 | */ |
| 1608 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1609 | const char *dev_name, void *raw_data, |
| 1610 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1611 | { |
| 1612 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1613 | struct super_block *s; |
| 1614 | struct nfs_server *server; |
| 1615 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1616 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1617 | struct nfs_sb_mountdata sb_mntdata = { |
| 1618 | .mntflags = flags, |
| 1619 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1620 | int error; |
| 1621 | |
| 1622 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 1623 | |
| 1624 | /* create a new volume representation */ |
| 1625 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 1626 | if (IS_ERR(server)) { |
| 1627 | error = PTR_ERR(server); |
| 1628 | goto out_err_noserver; |
| 1629 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1630 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1631 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1632 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 1633 | compare_super = NULL; |
| 1634 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1635 | /* 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] | 1636 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1637 | if (IS_ERR(s)) { |
| 1638 | error = PTR_ERR(s); |
| 1639 | goto out_err_nosb; |
| 1640 | } |
| 1641 | |
| 1642 | if (s->s_fs_info != server) { |
| 1643 | nfs_free_server(server); |
| 1644 | server = NULL; |
| 1645 | } |
| 1646 | |
| 1647 | if (!s->s_root) { |
| 1648 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1649 | nfs_clone_super(s, data->sb); |
| 1650 | } |
| 1651 | |
| 1652 | mntroot = nfs_get_root(s, data->fh); |
| 1653 | if (IS_ERR(mntroot)) { |
| 1654 | error = PTR_ERR(mntroot); |
| 1655 | goto error_splat_super; |
| 1656 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 1657 | 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] | 1658 | dput(mntroot); |
| 1659 | error = -ESTALE; |
| 1660 | goto error_splat_super; |
| 1661 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1662 | |
| 1663 | s->s_flags |= MS_ACTIVE; |
| 1664 | mnt->mnt_sb = s; |
| 1665 | mnt->mnt_root = mntroot; |
| 1666 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1667 | /* clone any lsm security options from the parent to the new sb */ |
| 1668 | security_sb_clone_mnt_opts(data->sb, s); |
| 1669 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1670 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 1671 | return 0; |
| 1672 | |
| 1673 | out_err_nosb: |
| 1674 | nfs_free_server(server); |
| 1675 | out_err_noserver: |
| 1676 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 1677 | return error; |
| 1678 | |
| 1679 | error_splat_super: |
| 1680 | up_write(&s->s_umount); |
| 1681 | deactivate_super(s); |
| 1682 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 1683 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1687 | |
| 1688 | /* |
| 1689 | * Finish setting up a cloned NFS4 superblock |
| 1690 | */ |
| 1691 | static void nfs4_clone_super(struct super_block *sb, |
| 1692 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1693 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1694 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1695 | sb->s_blocksize = old_sb->s_blocksize; |
| 1696 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1697 | sb->s_time_gran = 1; |
| 1698 | sb->s_op = old_sb->s_op; |
| 1699 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | /* |
| 1703 | * Set up an NFS4 superblock |
| 1704 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1705 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1706 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1707 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1708 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1709 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1710 | } |
| 1711 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1712 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1713 | * Validate NFSv4 mount options |
| 1714 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1715 | static int nfs4_validate_mount_data(void *options, |
| 1716 | struct nfs_parsed_mount_data *args, |
| 1717 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1718 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1719 | struct sockaddr_in *ap; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1720 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1721 | char *c; |
| 1722 | |
Russell King | f16c960 | 2007-11-16 22:13:24 +0000 | [diff] [blame] | 1723 | memset(args, 0, sizeof(*args)); |
| 1724 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1725 | if (data == NULL) |
| 1726 | goto out_no_data; |
| 1727 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1728 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1729 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
| 1730 | args->timeo = 600; |
| 1731 | args->retrans = 2; |
| 1732 | args->acregmin = 3; |
| 1733 | args->acregmax = 60; |
| 1734 | args->acdirmin = 30; |
| 1735 | args->acdirmax = 60; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame^] | 1736 | args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1737 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1738 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1739 | switch (data->version) { |
| 1740 | case 1: |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1741 | ap = (struct sockaddr_in *)&args->nfs_server.address; |
| 1742 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1743 | goto out_no_address; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1744 | if (data->host_addrlen == 0) |
| 1745 | goto out_no_address; |
| 1746 | args->nfs_server.addrlen = data->host_addrlen; |
| 1747 | if (copy_from_user(ap, data->host_addr, data->host_addrlen)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1748 | return -EFAULT; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1749 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1750 | &args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1751 | goto out_no_address; |
| 1752 | |
| 1753 | switch (data->auth_flavourlen) { |
| 1754 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1755 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1756 | break; |
| 1757 | case 1: |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1758 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1759 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 1760 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1761 | return -EFAULT; |
| 1762 | break; |
| 1763 | default: |
| 1764 | goto out_inval_auth; |
| 1765 | } |
| 1766 | |
| 1767 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 1768 | if (IS_ERR(c)) |
| 1769 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1770 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1771 | |
| 1772 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 1773 | if (IS_ERR(c)) |
| 1774 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1775 | args->nfs_server.export_path = c; |
| 1776 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1777 | |
| 1778 | c = strndup_user(data->client_addr.data, 16); |
| 1779 | if (IS_ERR(c)) |
| 1780 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1781 | args->client_address = c; |
| 1782 | |
| 1783 | /* |
| 1784 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 1785 | * can deal with. |
| 1786 | */ |
| 1787 | |
| 1788 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 1789 | args->rsize = data->rsize; |
| 1790 | args->wsize = data->wsize; |
| 1791 | args->timeo = data->timeo; |
| 1792 | args->retrans = data->retrans; |
| 1793 | args->acregmin = data->acregmin; |
| 1794 | args->acregmax = data->acregmax; |
| 1795 | args->acdirmin = data->acdirmin; |
| 1796 | args->acdirmax = data->acdirmax; |
| 1797 | args->nfs_server.protocol = data->proto; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1798 | |
| 1799 | break; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1800 | default: { |
| 1801 | unsigned int len; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1802 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1803 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1804 | return -EINVAL; |
| 1805 | |
| 1806 | if (!nfs_verify_server_address((struct sockaddr *) |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1807 | &args->nfs_server.address)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1808 | return -EINVAL; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1809 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1810 | switch (args->auth_flavor_len) { |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1811 | case 0: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1812 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1813 | break; |
| 1814 | case 1: |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1815 | break; |
| 1816 | default: |
| 1817 | goto out_inval_auth; |
| 1818 | } |
| 1819 | |
| 1820 | /* |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1821 | * Split "dev_name" into "hostname:mntpath". |
| 1822 | */ |
| 1823 | c = strchr(dev_name, ':'); |
| 1824 | if (c == NULL) |
| 1825 | return -EINVAL; |
| 1826 | /* while calculating len, pretend ':' is '\0' */ |
| 1827 | len = c - dev_name; |
| 1828 | if (len > NFS4_MAXNAMLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1829 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1830 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1831 | args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1832 | |
| 1833 | c++; /* step over the ':' */ |
| 1834 | len = strlen(c); |
| 1835 | if (len > NFS4_MAXPATHLEN) |
Chuck Lever | 7d1cca72 | 2007-08-29 17:59:03 -0400 | [diff] [blame] | 1836 | return -ENAMETOOLONG; |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1837 | args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1838 | |
Chuck Lever | 6a0ed1d | 2007-10-26 13:32:40 -0400 | [diff] [blame] | 1839 | dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path); |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1840 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1841 | if (args->client_address == NULL) |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1842 | goto out_no_client_address; |
| 1843 | |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 1844 | break; |
| 1845 | } |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | return 0; |
| 1849 | |
| 1850 | out_no_data: |
| 1851 | dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n"); |
| 1852 | return -EINVAL; |
| 1853 | |
| 1854 | out_inval_auth: |
| 1855 | dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n", |
| 1856 | data->auth_flavourlen); |
| 1857 | return -EINVAL; |
| 1858 | |
| 1859 | out_no_address: |
| 1860 | dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); |
| 1861 | return -EINVAL; |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 1862 | |
| 1863 | out_no_client_address: |
| 1864 | dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n"); |
| 1865 | return -EINVAL; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1869 | * Get the superblock for an NFS4 mountpoint |
| 1870 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1871 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 1872 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1873 | { |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1874 | struct nfs_parsed_mount_data data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1875 | struct super_block *s; |
| 1876 | struct nfs_server *server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1877 | struct nfs_fh mntfh; |
| 1878 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1879 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1880 | struct nfs_sb_mountdata sb_mntdata = { |
| 1881 | .mntflags = flags, |
| 1882 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1883 | int error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1884 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1885 | security_init_mnt_opts(&data.lsm_opts); |
| 1886 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1887 | /* Validate the mount data */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1888 | error = nfs4_validate_mount_data(raw_data, &data, dev_name); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 1889 | if (error < 0) |
| 1890 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1891 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1892 | /* Get a volume representation */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1893 | server = nfs4_create_server(&data, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1894 | if (IS_ERR(server)) { |
| 1895 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1896 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1897 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1898 | sb_mntdata.server = server; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1899 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1900 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 1901 | compare_super = NULL; |
| 1902 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1903 | /* 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] | 1904 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1905 | if (IS_ERR(s)) { |
| 1906 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1907 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1908 | } |
| 1909 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 1910 | if (s->s_fs_info != server) { |
| 1911 | nfs_free_server(server); |
| 1912 | server = NULL; |
| 1913 | } |
| 1914 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1915 | if (!s->s_root) { |
| 1916 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1917 | nfs4_fill_super(s); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1918 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1919 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1920 | mntroot = nfs4_get_root(s, &mntfh); |
| 1921 | if (IS_ERR(mntroot)) { |
| 1922 | error = PTR_ERR(mntroot); |
| 1923 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1924 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1925 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1926 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1927 | mnt->mnt_sb = s; |
| 1928 | mnt->mnt_root = mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1929 | error = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1930 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1931 | out: |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 1932 | kfree(data.client_address); |
| 1933 | kfree(data.nfs_server.export_path); |
| 1934 | kfree(data.nfs_server.hostname); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1935 | security_free_mnt_opts(&data.lsm_opts); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 1936 | return error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1937 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1938 | out_free: |
| 1939 | nfs_free_server(server); |
| 1940 | goto out; |
| 1941 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1942 | error_splat_super: |
| 1943 | up_write(&s->s_umount); |
| 1944 | deactivate_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 1945 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static void nfs4_kill_super(struct super_block *sb) |
| 1949 | { |
| 1950 | struct nfs_server *server = NFS_SB(sb); |
| 1951 | |
| 1952 | nfs_return_all_delegations(sb); |
| 1953 | kill_anon_super(sb); |
| 1954 | |
| 1955 | nfs4_renewd_prepare_shutdown(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1956 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1960 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1961 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1962 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 1963 | const char *dev_name, void *raw_data, |
| 1964 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1965 | { |
| 1966 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1967 | struct super_block *s; |
| 1968 | struct nfs_server *server; |
| 1969 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1970 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1971 | struct nfs_sb_mountdata sb_mntdata = { |
| 1972 | .mntflags = flags, |
| 1973 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1974 | int error; |
| 1975 | |
| 1976 | dprintk("--> nfs4_xdev_get_sb()\n"); |
| 1977 | |
| 1978 | /* create a new volume representation */ |
| 1979 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 1980 | if (IS_ERR(server)) { |
| 1981 | error = PTR_ERR(server); |
| 1982 | goto out_err_noserver; |
| 1983 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 1984 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1985 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1986 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 1987 | compare_super = NULL; |
| 1988 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1989 | /* 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] | 1990 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1991 | if (IS_ERR(s)) { |
| 1992 | error = PTR_ERR(s); |
| 1993 | goto out_err_nosb; |
| 1994 | } |
| 1995 | |
| 1996 | if (s->s_fs_info != server) { |
| 1997 | nfs_free_server(server); |
| 1998 | server = NULL; |
| 1999 | } |
| 2000 | |
| 2001 | if (!s->s_root) { |
| 2002 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2003 | nfs4_clone_super(s, data->sb); |
| 2004 | } |
| 2005 | |
| 2006 | mntroot = nfs4_get_root(s, data->fh); |
| 2007 | if (IS_ERR(mntroot)) { |
| 2008 | error = PTR_ERR(mntroot); |
| 2009 | goto error_splat_super; |
| 2010 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2011 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2012 | dput(mntroot); |
| 2013 | error = -ESTALE; |
| 2014 | goto error_splat_super; |
| 2015 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2016 | |
| 2017 | s->s_flags |= MS_ACTIVE; |
| 2018 | mnt->mnt_sb = s; |
| 2019 | mnt->mnt_root = mntroot; |
| 2020 | |
| 2021 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); |
| 2022 | return 0; |
| 2023 | |
| 2024 | out_err_nosb: |
| 2025 | nfs_free_server(server); |
| 2026 | out_err_noserver: |
| 2027 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); |
| 2028 | return error; |
| 2029 | |
| 2030 | error_splat_super: |
| 2031 | up_write(&s->s_umount); |
| 2032 | deactivate_super(s); |
| 2033 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
| 2034 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2035 | } |
| 2036 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2037 | /* |
| 2038 | * Create an NFS4 server record on referral traversal |
| 2039 | */ |
| 2040 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags, |
| 2041 | const char *dev_name, void *raw_data, |
| 2042 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2043 | { |
| 2044 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2045 | struct super_block *s; |
| 2046 | struct nfs_server *server; |
| 2047 | struct dentry *mntroot; |
| 2048 | struct nfs_fh mntfh; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2049 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2050 | struct nfs_sb_mountdata sb_mntdata = { |
| 2051 | .mntflags = flags, |
| 2052 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2053 | int error; |
| 2054 | |
| 2055 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2056 | |
| 2057 | /* create a new volume representation */ |
| 2058 | server = nfs4_create_referral_server(data, &mntfh); |
| 2059 | if (IS_ERR(server)) { |
| 2060 | error = PTR_ERR(server); |
| 2061 | goto out_err_noserver; |
| 2062 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2063 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2064 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2065 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2066 | compare_super = NULL; |
| 2067 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2068 | /* 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] | 2069 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2070 | if (IS_ERR(s)) { |
| 2071 | error = PTR_ERR(s); |
| 2072 | goto out_err_nosb; |
| 2073 | } |
| 2074 | |
| 2075 | if (s->s_fs_info != server) { |
| 2076 | nfs_free_server(server); |
| 2077 | server = NULL; |
| 2078 | } |
| 2079 | |
| 2080 | if (!s->s_root) { |
| 2081 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2082 | nfs4_fill_super(s); |
| 2083 | } |
| 2084 | |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 2085 | mntroot = nfs4_get_root(s, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2086 | if (IS_ERR(mntroot)) { |
| 2087 | error = PTR_ERR(mntroot); |
| 2088 | goto error_splat_super; |
| 2089 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2090 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2091 | dput(mntroot); |
| 2092 | error = -ESTALE; |
| 2093 | goto error_splat_super; |
| 2094 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2095 | |
| 2096 | s->s_flags |= MS_ACTIVE; |
| 2097 | mnt->mnt_sb = s; |
| 2098 | mnt->mnt_root = mntroot; |
| 2099 | |
| 2100 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
| 2101 | return 0; |
| 2102 | |
| 2103 | out_err_nosb: |
| 2104 | nfs_free_server(server); |
| 2105 | out_err_noserver: |
| 2106 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
| 2107 | return error; |
| 2108 | |
| 2109 | error_splat_super: |
| 2110 | up_write(&s->s_umount); |
| 2111 | deactivate_super(s); |
| 2112 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
| 2113 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2114 | } |
| 2115 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2116 | #endif /* CONFIG_NFS_V4 */ |