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