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