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