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