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