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