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