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