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