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