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