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" }, |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 161 | { Opt_minorversion, "minorversion=%u" }, |
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 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 748 | static void nfs_parse_ipv4_address(char *string, size_t str_len, |
| 749 | struct sockaddr *sap, size_t *addr_len) |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 750 | { |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 751 | struct sockaddr_in *sin = (struct sockaddr_in *)sap; |
| 752 | u8 *addr = (u8 *)&sin->sin_addr.s_addr; |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 753 | |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 754 | if (str_len <= INET_ADDRSTRLEN) { |
| 755 | dfprintk(MOUNT, "NFS: parsing IPv4 address %*s\n", |
| 756 | (int)str_len, string); |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 757 | |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 758 | sin->sin_family = AF_INET; |
| 759 | *addr_len = sizeof(*sin); |
| 760 | if (in4_pton(string, str_len, addr, '\0', NULL)) |
Chuck Lever | 3c7c7e4 | 2007-12-10 14:59:35 -0500 | [diff] [blame] | 761 | return; |
| 762 | } |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 763 | |
| 764 | sap->sa_family = AF_UNSPEC; |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 765 | *addr_len = 0; |
| 766 | } |
| 767 | |
| 768 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 769 | static int nfs_parse_ipv6_scope_id(const char *string, const size_t str_len, |
| 770 | const char *delim, |
| 771 | struct sockaddr_in6 *sin6) |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 772 | { |
| 773 | char *p; |
| 774 | size_t len; |
| 775 | |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 776 | if ((string + str_len) == delim) |
| 777 | return 1; |
| 778 | |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 779 | if (*delim != IPV6_SCOPE_DELIMITER) |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 780 | return 0; |
| 781 | |
| 782 | if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)) |
| 783 | return 0; |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 784 | |
| 785 | len = (string + str_len) - delim - 1; |
| 786 | p = kstrndup(delim + 1, len, GFP_KERNEL); |
| 787 | if (p) { |
| 788 | unsigned long scope_id = 0; |
| 789 | struct net_device *dev; |
| 790 | |
| 791 | dev = dev_get_by_name(&init_net, p); |
| 792 | if (dev != NULL) { |
| 793 | scope_id = dev->ifindex; |
| 794 | dev_put(dev); |
| 795 | } else { |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 796 | if (strict_strtoul(p, 10, &scope_id) == 0) { |
| 797 | kfree(p); |
| 798 | return 0; |
| 799 | } |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | kfree(p); |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 803 | |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 804 | sin6->sin6_scope_id = scope_id; |
| 805 | dfprintk(MOUNT, "NFS: IPv6 scope ID = %lu\n", scope_id); |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 806 | return 1; |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 807 | } |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 808 | |
| 809 | return 0; |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 810 | } |
| 811 | |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 812 | static void nfs_parse_ipv6_address(char *string, size_t str_len, |
| 813 | struct sockaddr *sap, size_t *addr_len) |
| 814 | { |
| 815 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap; |
| 816 | u8 *addr = (u8 *)&sin6->sin6_addr.in6_u; |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 817 | const char *delim; |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 818 | |
| 819 | if (str_len <= INET6_ADDRSTRLEN) { |
| 820 | dfprintk(MOUNT, "NFS: parsing IPv6 address %*s\n", |
| 821 | (int)str_len, string); |
| 822 | |
| 823 | sin6->sin6_family = AF_INET6; |
| 824 | *addr_len = sizeof(*sin6); |
Chuck Lever | 5e2e772 | 2008-10-08 15:38:10 -0400 | [diff] [blame] | 825 | if (in6_pton(string, str_len, addr, |
| 826 | IPV6_SCOPE_DELIMITER, &delim) != 0) { |
| 827 | if (nfs_parse_ipv6_scope_id(string, str_len, |
| 828 | delim, sin6) != 0) |
| 829 | return; |
Chuck Lever | d8e7748 | 2008-06-23 12:37:01 -0400 | [diff] [blame] | 830 | } |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | sap->sa_family = AF_UNSPEC; |
| 834 | *addr_len = 0; |
| 835 | } |
| 836 | #else |
| 837 | static void nfs_parse_ipv6_address(char *string, size_t str_len, |
| 838 | struct sockaddr *sap, size_t *addr_len) |
| 839 | { |
| 840 | sap->sa_family = AF_UNSPEC; |
| 841 | *addr_len = 0; |
| 842 | } |
| 843 | #endif |
| 844 | |
| 845 | /* |
| 846 | * Construct a sockaddr based on the contents of a string that contains |
| 847 | * an IP address in presentation format. |
| 848 | * |
| 849 | * If there is a problem constructing the new sockaddr, set the address |
| 850 | * family to AF_UNSPEC. |
| 851 | */ |
J. Bruce Fields | ea31a443 | 2008-08-20 16:10:23 -0400 | [diff] [blame] | 852 | void nfs_parse_ip_address(char *string, size_t str_len, |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 853 | struct sockaddr *sap, size_t *addr_len) |
| 854 | { |
| 855 | unsigned int i, colons; |
| 856 | |
| 857 | colons = 0; |
| 858 | for (i = 0; i < str_len; i++) |
| 859 | if (string[i] == ':') |
| 860 | colons++; |
| 861 | |
| 862 | if (colons >= 2) |
| 863 | nfs_parse_ipv6_address(string, str_len, sap, addr_len); |
| 864 | else |
| 865 | nfs_parse_ipv4_address(string, str_len, sap, addr_len); |
Chuck Lever | 9412b92 | 2007-12-10 14:59:21 -0500 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 869 | * Sanity check the NFS transport protocol. |
| 870 | * |
| 871 | */ |
| 872 | static void nfs_validate_transport_protocol(struct nfs_parsed_mount_data *mnt) |
| 873 | { |
| 874 | switch (mnt->nfs_server.protocol) { |
| 875 | case XPRT_TRANSPORT_UDP: |
| 876 | case XPRT_TRANSPORT_TCP: |
| 877 | case XPRT_TRANSPORT_RDMA: |
| 878 | break; |
| 879 | default: |
| 880 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | /* |
| 885 | * For text based NFSv2/v3 mounts, the mount protocol transport default |
| 886 | * settings should depend upon the specified NFS transport. |
| 887 | */ |
| 888 | static void nfs_set_mount_transport_protocol(struct nfs_parsed_mount_data *mnt) |
| 889 | { |
| 890 | nfs_validate_transport_protocol(mnt); |
| 891 | |
| 892 | if (mnt->mount_server.protocol == XPRT_TRANSPORT_UDP || |
| 893 | mnt->mount_server.protocol == XPRT_TRANSPORT_TCP) |
| 894 | return; |
| 895 | switch (mnt->nfs_server.protocol) { |
| 896 | case XPRT_TRANSPORT_UDP: |
| 897 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
| 898 | break; |
| 899 | case XPRT_TRANSPORT_TCP: |
| 900 | case XPRT_TRANSPORT_RDMA: |
| 901 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | /* |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 906 | * Parse the value of the 'sec=' option. |
| 907 | * |
Chuck Lever | dd07c94 | 2008-06-24 16:33:46 -0400 | [diff] [blame] | 908 | * The flavor_len setting is for v4 mounts. |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 909 | */ |
| 910 | static int nfs_parse_security_flavors(char *value, |
| 911 | struct nfs_parsed_mount_data *mnt) |
| 912 | { |
| 913 | substring_t args[MAX_OPT_ARGS]; |
| 914 | |
| 915 | dfprintk(MOUNT, "NFS: parsing sec=%s option\n", value); |
| 916 | |
| 917 | switch (match_token(value, nfs_secflavor_tokens, args)) { |
| 918 | case Opt_sec_none: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 919 | mnt->auth_flavor_len = 0; |
| 920 | mnt->auth_flavors[0] = RPC_AUTH_NULL; |
| 921 | break; |
| 922 | case Opt_sec_sys: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 923 | mnt->auth_flavor_len = 0; |
| 924 | mnt->auth_flavors[0] = RPC_AUTH_UNIX; |
| 925 | break; |
| 926 | case Opt_sec_krb5: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 927 | mnt->auth_flavor_len = 1; |
| 928 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5; |
| 929 | break; |
| 930 | case Opt_sec_krb5i: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 931 | mnt->auth_flavor_len = 1; |
| 932 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5I; |
| 933 | break; |
| 934 | case Opt_sec_krb5p: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 935 | mnt->auth_flavor_len = 1; |
| 936 | mnt->auth_flavors[0] = RPC_AUTH_GSS_KRB5P; |
| 937 | break; |
| 938 | case Opt_sec_lkey: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 939 | mnt->auth_flavor_len = 1; |
| 940 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEY; |
| 941 | break; |
| 942 | case Opt_sec_lkeyi: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 943 | mnt->auth_flavor_len = 1; |
| 944 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYI; |
| 945 | break; |
| 946 | case Opt_sec_lkeyp: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 947 | mnt->auth_flavor_len = 1; |
| 948 | mnt->auth_flavors[0] = RPC_AUTH_GSS_LKEYP; |
| 949 | break; |
| 950 | case Opt_sec_spkm: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 951 | mnt->auth_flavor_len = 1; |
| 952 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKM; |
| 953 | break; |
| 954 | case Opt_sec_spkmi: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 955 | mnt->auth_flavor_len = 1; |
| 956 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMI; |
| 957 | break; |
| 958 | case Opt_sec_spkmp: |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 959 | mnt->auth_flavor_len = 1; |
| 960 | mnt->auth_flavors[0] = RPC_AUTH_GSS_SPKMP; |
| 961 | break; |
| 962 | default: |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | return 1; |
| 967 | } |
| 968 | |
| 969 | /* |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 970 | * 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] | 971 | * a data structure. The whole mount string is processed; bad options are |
| 972 | * skipped as they are encountered. If there were no errors, return 1; |
| 973 | * otherwise return 0 (zero). |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 974 | */ |
| 975 | static int nfs_parse_mount_options(char *raw, |
| 976 | struct nfs_parsed_mount_data *mnt) |
| 977 | { |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 978 | char *p, *string, *secdata; |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 979 | int rc, sloppy = 0, invalid_option = 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 980 | |
| 981 | if (!raw) { |
| 982 | dfprintk(MOUNT, "NFS: mount options string was NULL.\n"); |
| 983 | return 1; |
| 984 | } |
| 985 | dfprintk(MOUNT, "NFS: nfs mount opts='%s'\n", raw); |
| 986 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 987 | secdata = alloc_secdata(); |
| 988 | if (!secdata) |
| 989 | goto out_nomem; |
| 990 | |
| 991 | rc = security_sb_copy_data(raw, secdata); |
| 992 | if (rc) |
| 993 | goto out_security_failure; |
| 994 | |
| 995 | rc = security_sb_parse_opts_str(secdata, &mnt->lsm_opts); |
| 996 | if (rc) |
| 997 | goto out_security_failure; |
| 998 | |
| 999 | free_secdata(secdata); |
| 1000 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1001 | while ((p = strsep(&raw, ",")) != NULL) { |
| 1002 | substring_t args[MAX_OPT_ARGS]; |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1003 | unsigned long option; |
Trond Myklebust | 1f84603 | 2009-06-17 18:13:00 -0700 | [diff] [blame] | 1004 | int int_option; |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1005 | int token; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1006 | |
| 1007 | if (!*p) |
| 1008 | continue; |
| 1009 | |
| 1010 | dfprintk(MOUNT, "NFS: parsing nfs mount option '%s'\n", p); |
| 1011 | |
| 1012 | token = match_token(p, nfs_mount_option_tokens, args); |
| 1013 | switch (token) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1014 | |
| 1015 | /* |
| 1016 | * boolean options: foo/nofoo |
| 1017 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1018 | case Opt_soft: |
| 1019 | mnt->flags |= NFS_MOUNT_SOFT; |
| 1020 | break; |
| 1021 | case Opt_hard: |
| 1022 | mnt->flags &= ~NFS_MOUNT_SOFT; |
| 1023 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1024 | case Opt_posix: |
| 1025 | mnt->flags |= NFS_MOUNT_POSIX; |
| 1026 | break; |
| 1027 | case Opt_noposix: |
| 1028 | mnt->flags &= ~NFS_MOUNT_POSIX; |
| 1029 | break; |
| 1030 | case Opt_cto: |
| 1031 | mnt->flags &= ~NFS_MOUNT_NOCTO; |
| 1032 | break; |
| 1033 | case Opt_nocto: |
| 1034 | mnt->flags |= NFS_MOUNT_NOCTO; |
| 1035 | break; |
| 1036 | case Opt_ac: |
| 1037 | mnt->flags &= ~NFS_MOUNT_NOAC; |
| 1038 | break; |
| 1039 | case Opt_noac: |
| 1040 | mnt->flags |= NFS_MOUNT_NOAC; |
| 1041 | break; |
| 1042 | case Opt_lock: |
| 1043 | mnt->flags &= ~NFS_MOUNT_NONLM; |
| 1044 | break; |
| 1045 | case Opt_nolock: |
| 1046 | mnt->flags |= NFS_MOUNT_NONLM; |
| 1047 | break; |
| 1048 | case Opt_v2: |
| 1049 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 1050 | break; |
| 1051 | case Opt_v3: |
| 1052 | mnt->flags |= NFS_MOUNT_VER3; |
| 1053 | break; |
| 1054 | case Opt_udp: |
| 1055 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1056 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1057 | break; |
| 1058 | case Opt_tcp: |
| 1059 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1060 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1061 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1062 | case Opt_rdma: |
| 1063 | mnt->flags |= NFS_MOUNT_TCP; /* for side protocols */ |
| 1064 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Tom Talpey | a67d18f | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 1065 | xprt_load_transport(p); |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1066 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1067 | case Opt_acl: |
| 1068 | mnt->flags &= ~NFS_MOUNT_NOACL; |
| 1069 | break; |
| 1070 | case Opt_noacl: |
| 1071 | mnt->flags |= NFS_MOUNT_NOACL; |
| 1072 | break; |
| 1073 | case Opt_rdirplus: |
| 1074 | mnt->flags &= ~NFS_MOUNT_NORDIRPLUS; |
| 1075 | break; |
| 1076 | case Opt_nordirplus: |
| 1077 | mnt->flags |= NFS_MOUNT_NORDIRPLUS; |
| 1078 | break; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1079 | case Opt_sharecache: |
| 1080 | mnt->flags &= ~NFS_MOUNT_UNSHARED; |
| 1081 | break; |
| 1082 | case Opt_nosharecache: |
| 1083 | mnt->flags |= NFS_MOUNT_UNSHARED; |
| 1084 | break; |
Chuck Lever | d740351 | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 1085 | case Opt_resvport: |
| 1086 | mnt->flags &= ~NFS_MOUNT_NORESVPORT; |
| 1087 | break; |
| 1088 | case Opt_noresvport: |
| 1089 | mnt->flags |= NFS_MOUNT_NORESVPORT; |
| 1090 | break; |
David Howells | b797cac | 2009-04-03 16:42:48 +0100 | [diff] [blame] | 1091 | case Opt_fscache: |
| 1092 | mnt->options |= NFS_OPTION_FSCACHE; |
| 1093 | kfree(mnt->fscache_uniq); |
| 1094 | mnt->fscache_uniq = NULL; |
| 1095 | break; |
| 1096 | case Opt_nofscache: |
| 1097 | mnt->options &= ~NFS_OPTION_FSCACHE; |
| 1098 | kfree(mnt->fscache_uniq); |
| 1099 | mnt->fscache_uniq = NULL; |
| 1100 | break; |
| 1101 | case Opt_fscache_uniq: |
| 1102 | string = match_strdup(args); |
| 1103 | if (!string) |
| 1104 | goto out_nomem; |
| 1105 | kfree(mnt->fscache_uniq); |
| 1106 | mnt->fscache_uniq = string; |
| 1107 | mnt->options |= NFS_OPTION_FSCACHE; |
| 1108 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1109 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1110 | /* |
| 1111 | * options that take numeric values |
| 1112 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1113 | case Opt_port: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1114 | string = match_strdup(args); |
| 1115 | if (string == NULL) |
| 1116 | goto out_nomem; |
| 1117 | rc = strict_strtoul(string, 10, &option); |
| 1118 | kfree(string); |
| 1119 | if (rc != 0 || option > USHORT_MAX) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1120 | goto out_invalid_value; |
| 1121 | mnt->nfs_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1122 | break; |
| 1123 | case Opt_rsize: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1124 | string = match_strdup(args); |
| 1125 | if (string == NULL) |
| 1126 | goto out_nomem; |
| 1127 | rc = strict_strtoul(string, 10, &option); |
| 1128 | kfree(string); |
| 1129 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1130 | goto out_invalid_value; |
| 1131 | mnt->rsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1132 | break; |
| 1133 | case Opt_wsize: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1134 | string = match_strdup(args); |
| 1135 | if (string == NULL) |
| 1136 | goto out_nomem; |
| 1137 | rc = strict_strtoul(string, 10, &option); |
| 1138 | kfree(string); |
| 1139 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1140 | goto out_invalid_value; |
| 1141 | mnt->wsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1142 | break; |
| 1143 | case Opt_bsize: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [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) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1150 | goto out_invalid_value; |
| 1151 | mnt->bsize = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1152 | break; |
| 1153 | case Opt_timeo: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1154 | string = match_strdup(args); |
| 1155 | if (string == NULL) |
| 1156 | goto out_nomem; |
| 1157 | rc = strict_strtoul(string, 10, &option); |
| 1158 | kfree(string); |
| 1159 | if (rc != 0 || option == 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1160 | goto out_invalid_value; |
| 1161 | mnt->timeo = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1162 | break; |
| 1163 | case Opt_retrans: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1164 | string = match_strdup(args); |
| 1165 | if (string == NULL) |
| 1166 | goto out_nomem; |
| 1167 | rc = strict_strtoul(string, 10, &option); |
| 1168 | kfree(string); |
| 1169 | if (rc != 0 || option == 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1170 | goto out_invalid_value; |
| 1171 | mnt->retrans = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1172 | break; |
| 1173 | case Opt_acregmin: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1174 | string = match_strdup(args); |
| 1175 | if (string == NULL) |
| 1176 | goto out_nomem; |
| 1177 | rc = strict_strtoul(string, 10, &option); |
| 1178 | kfree(string); |
| 1179 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1180 | goto out_invalid_value; |
| 1181 | mnt->acregmin = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1182 | break; |
| 1183 | case Opt_acregmax: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1184 | string = match_strdup(args); |
| 1185 | if (string == NULL) |
| 1186 | goto out_nomem; |
| 1187 | rc = strict_strtoul(string, 10, &option); |
| 1188 | kfree(string); |
| 1189 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1190 | goto out_invalid_value; |
| 1191 | mnt->acregmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1192 | break; |
| 1193 | case Opt_acdirmin: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1194 | string = match_strdup(args); |
| 1195 | if (string == NULL) |
| 1196 | goto out_nomem; |
| 1197 | rc = strict_strtoul(string, 10, &option); |
| 1198 | kfree(string); |
| 1199 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1200 | goto out_invalid_value; |
| 1201 | mnt->acdirmin = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1202 | break; |
| 1203 | case Opt_acdirmax: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1204 | string = match_strdup(args); |
| 1205 | if (string == NULL) |
| 1206 | goto out_nomem; |
| 1207 | rc = strict_strtoul(string, 10, &option); |
| 1208 | kfree(string); |
| 1209 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1210 | goto out_invalid_value; |
| 1211 | mnt->acdirmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1212 | break; |
| 1213 | case Opt_actimeo: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1214 | string = match_strdup(args); |
| 1215 | if (string == NULL) |
| 1216 | goto out_nomem; |
| 1217 | rc = strict_strtoul(string, 10, &option); |
| 1218 | kfree(string); |
| 1219 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1220 | goto out_invalid_value; |
| 1221 | mnt->acregmin = mnt->acregmax = |
| 1222 | mnt->acdirmin = mnt->acdirmax = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1223 | break; |
| 1224 | case Opt_namelen: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1225 | string = match_strdup(args); |
| 1226 | if (string == NULL) |
| 1227 | goto out_nomem; |
| 1228 | rc = strict_strtoul(string, 10, &option); |
| 1229 | kfree(string); |
| 1230 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1231 | goto out_invalid_value; |
| 1232 | mnt->namlen = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1233 | break; |
| 1234 | case Opt_mountport: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1235 | string = match_strdup(args); |
| 1236 | if (string == NULL) |
| 1237 | goto out_nomem; |
| 1238 | rc = strict_strtoul(string, 10, &option); |
| 1239 | kfree(string); |
| 1240 | if (rc != 0 || option > USHORT_MAX) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1241 | goto out_invalid_value; |
| 1242 | mnt->mount_server.port = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1243 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1244 | case Opt_mountvers: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1245 | string = match_strdup(args); |
| 1246 | if (string == NULL) |
| 1247 | goto out_nomem; |
| 1248 | rc = strict_strtoul(string, 10, &option); |
| 1249 | kfree(string); |
| 1250 | if (rc != 0 || |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1251 | option < NFS_MNT_VERSION || |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1252 | option > NFS_MNT3_VERSION) |
| 1253 | goto out_invalid_value; |
| 1254 | mnt->mount_server.version = option; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1255 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1256 | case Opt_nfsvers: |
Chuck Lever | a5a16ba | 2009-06-17 18:02:14 -0700 | [diff] [blame] | 1257 | string = match_strdup(args); |
| 1258 | if (string == NULL) |
| 1259 | goto out_nomem; |
| 1260 | rc = strict_strtoul(string, 10, &option); |
| 1261 | kfree(string); |
| 1262 | if (rc != 0) |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1263 | goto out_invalid_value; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1264 | switch (option) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1265 | case NFS2_VERSION: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1266 | mnt->flags &= ~NFS_MOUNT_VER3; |
| 1267 | break; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1268 | case NFS3_VERSION: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1269 | mnt->flags |= NFS_MOUNT_VER3; |
| 1270 | break; |
| 1271 | default: |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1272 | goto out_invalid_value; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1273 | } |
| 1274 | break; |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1275 | case Opt_minorversion: |
Trond Myklebust | 1f84603 | 2009-06-17 18:13:00 -0700 | [diff] [blame] | 1276 | if (match_int(args, &int_option)) |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1277 | return 0; |
Trond Myklebust | 1f84603 | 2009-06-17 18:13:00 -0700 | [diff] [blame] | 1278 | if (int_option < 0 || int_option > NFS4_MAX_MINOR_VERSION) |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1279 | return 0; |
Trond Myklebust | 1f84603 | 2009-06-17 18:13:00 -0700 | [diff] [blame] | 1280 | mnt->minorversion = int_option; |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 1281 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1282 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1283 | /* |
| 1284 | * options that take text values |
| 1285 | */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1286 | case Opt_sec: |
| 1287 | string = match_strdup(args); |
| 1288 | if (string == NULL) |
| 1289 | goto out_nomem; |
Chuck Lever | 01060c8 | 2008-06-24 16:33:38 -0400 | [diff] [blame] | 1290 | rc = nfs_parse_security_flavors(string, mnt); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1291 | kfree(string); |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1292 | if (!rc) { |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1293 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1294 | "security flavor\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1295 | return 0; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1296 | } |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1297 | break; |
| 1298 | case Opt_proto: |
| 1299 | string = match_strdup(args); |
| 1300 | if (string == NULL) |
| 1301 | goto out_nomem; |
| 1302 | token = match_token(string, |
| 1303 | nfs_xprt_protocol_tokens, args); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1304 | |
| 1305 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1306 | case Opt_xprt_udp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1307 | mnt->flags &= ~NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1308 | mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1309 | kfree(string); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1310 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1311 | case Opt_xprt_tcp: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1312 | mnt->flags |= NFS_MOUNT_TCP; |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1313 | mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1314 | kfree(string); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1315 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1316 | case Opt_xprt_rdma: |
| 1317 | /* vector side protocols to TCP */ |
| 1318 | mnt->flags |= NFS_MOUNT_TCP; |
| 1319 | mnt->nfs_server.protocol = XPRT_TRANSPORT_RDMA; |
Tom Talpey | a67d18f | 2009-03-11 14:37:56 -0400 | [diff] [blame] | 1320 | xprt_load_transport(string); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1321 | kfree(string); |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1322 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1323 | default: |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1324 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1325 | "transport protocol\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1326 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1327 | } |
| 1328 | break; |
| 1329 | case Opt_mountproto: |
| 1330 | string = match_strdup(args); |
| 1331 | if (string == NULL) |
| 1332 | goto out_nomem; |
| 1333 | token = match_token(string, |
| 1334 | nfs_xprt_protocol_tokens, args); |
Trond Myklebust | d508afb | 2009-04-06 16:41:35 -0700 | [diff] [blame] | 1335 | kfree(string); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1336 | |
| 1337 | switch (token) { |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1338 | case Opt_xprt_udp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1339 | mnt->mount_server.protocol = XPRT_TRANSPORT_UDP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1340 | break; |
Chuck Lever | fdb66ff | 2007-08-29 17:58:57 -0400 | [diff] [blame] | 1341 | case Opt_xprt_tcp: |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1342 | mnt->mount_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1343 | break; |
\"Talpey, Thomas\ | 2cf7ff7 | 2007-09-10 13:49:41 -0400 | [diff] [blame] | 1344 | case Opt_xprt_rdma: /* not used for side protocols */ |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1345 | default: |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1346 | dfprintk(MOUNT, "NFS: unrecognized " |
| 1347 | "transport protocol\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1348 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1349 | } |
| 1350 | break; |
| 1351 | case Opt_addr: |
| 1352 | string = match_strdup(args); |
| 1353 | if (string == NULL) |
| 1354 | goto out_nomem; |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 1355 | nfs_parse_ip_address(string, strlen(string), |
| 1356 | (struct sockaddr *) |
| 1357 | &mnt->nfs_server.address, |
| 1358 | &mnt->nfs_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1359 | kfree(string); |
| 1360 | break; |
| 1361 | case Opt_clientaddr: |
| 1362 | string = match_strdup(args); |
| 1363 | if (string == NULL) |
| 1364 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1365 | kfree(mnt->client_address); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1366 | mnt->client_address = string; |
| 1367 | break; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1368 | case Opt_mounthost: |
| 1369 | string = match_strdup(args); |
| 1370 | if (string == NULL) |
| 1371 | goto out_nomem; |
Chuck Lever | fc60147 | 2008-01-16 16:38:10 -0500 | [diff] [blame] | 1372 | kfree(mnt->mount_server.hostname); |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1373 | mnt->mount_server.hostname = string; |
| 1374 | break; |
Chuck Lever | 0ac8377 | 2007-09-11 18:01:04 -0400 | [diff] [blame] | 1375 | case Opt_mountaddr: |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1376 | string = match_strdup(args); |
| 1377 | if (string == NULL) |
| 1378 | goto out_nomem; |
Chuck Lever | ce3b7e1 | 2008-06-23 12:36:53 -0400 | [diff] [blame] | 1379 | nfs_parse_ip_address(string, strlen(string), |
| 1380 | (struct sockaddr *) |
| 1381 | &mnt->mount_server.address, |
| 1382 | &mnt->mount_server.addrlen); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1383 | kfree(string); |
| 1384 | break; |
Trond Myklebust | 7973c1f1 | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1385 | case Opt_lookupcache: |
| 1386 | string = match_strdup(args); |
| 1387 | if (string == NULL) |
| 1388 | goto out_nomem; |
| 1389 | token = match_token(string, |
| 1390 | nfs_lookupcache_tokens, args); |
| 1391 | kfree(string); |
| 1392 | switch (token) { |
| 1393 | case Opt_lookupcache_all: |
| 1394 | mnt->flags &= ~(NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE); |
| 1395 | break; |
| 1396 | case Opt_lookupcache_positive: |
| 1397 | mnt->flags &= ~NFS_MOUNT_LOOKUP_CACHE_NONE; |
| 1398 | mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG; |
| 1399 | break; |
| 1400 | case Opt_lookupcache_none: |
| 1401 | mnt->flags |= NFS_MOUNT_LOOKUP_CACHE_NONEG|NFS_MOUNT_LOOKUP_CACHE_NONE; |
| 1402 | break; |
| 1403 | default: |
Trond Myklebust | 7973c1f1 | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1404 | dfprintk(MOUNT, "NFS: invalid " |
| 1405 | "lookupcache argument\n"); |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1406 | return 0; |
Trond Myklebust | 7973c1f1 | 2008-07-15 17:58:14 -0400 | [diff] [blame] | 1407 | }; |
| 1408 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1409 | |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1410 | /* |
| 1411 | * Special options |
| 1412 | */ |
| 1413 | case Opt_sloppy: |
| 1414 | sloppy = 1; |
| 1415 | dfprintk(MOUNT, "NFS: relaxing parsing rules\n"); |
| 1416 | break; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1417 | case Opt_userspace: |
| 1418 | case Opt_deprecated: |
Chuck Lever | d33e4df | 2008-06-12 12:37:41 -0400 | [diff] [blame] | 1419 | dfprintk(MOUNT, "NFS: ignoring mount option " |
| 1420 | "'%s'\n", p); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1421 | break; |
| 1422 | |
| 1423 | default: |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1424 | invalid_option = 1; |
Chuck Lever | f45663c | 2008-06-24 19:28:02 -0400 | [diff] [blame] | 1425 | dfprintk(MOUNT, "NFS: unrecognized mount option " |
| 1426 | "'%s'\n", p); |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1430 | if (!sloppy && invalid_option) |
| 1431 | return 0; |
| 1432 | |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1433 | return 1; |
| 1434 | |
Chuck Lever | d23c45f | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1435 | out_invalid_value: |
| 1436 | printk(KERN_INFO "NFS: bad mount option value specified: %s \n", p); |
| 1437 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1438 | out_nomem: |
| 1439 | printk(KERN_INFO "NFS: not enough memory to parse option\n"); |
| 1440 | return 0; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1441 | out_security_failure: |
| 1442 | free_secdata(secdata); |
| 1443 | printk(KERN_INFO "NFS: security options invalid: %d\n", rc); |
| 1444 | return 0; |
Chuck Lever | bf0fd76 | 2007-07-01 12:13:44 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /* |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1448 | * Use the remote server's MOUNT service to request the NFS file handle |
| 1449 | * corresponding to the provided path. |
| 1450 | */ |
| 1451 | static int nfs_try_mount(struct nfs_parsed_mount_data *args, |
| 1452 | struct nfs_fh *root_fh) |
| 1453 | { |
Chuck Lever | 8e02f6b | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1454 | unsigned int auth_flavor_len = 0; |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1455 | struct nfs_mount_request request = { |
| 1456 | .sap = (struct sockaddr *) |
| 1457 | &args->mount_server.address, |
| 1458 | .dirpath = args->nfs_server.export_path, |
| 1459 | .protocol = args->mount_server.protocol, |
| 1460 | .fh = root_fh, |
Chuck Lever | 50a737f | 2008-12-23 15:21:37 -0500 | [diff] [blame] | 1461 | .noresvport = args->flags & NFS_MOUNT_NORESVPORT, |
Chuck Lever | 8e02f6b | 2009-06-17 18:02:13 -0700 | [diff] [blame] | 1462 | .auth_flav_len = &auth_flavor_len, |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1463 | }; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1464 | int status; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1465 | |
| 1466 | if (args->mount_server.version == 0) { |
| 1467 | if (args->flags & NFS_MOUNT_VER3) |
| 1468 | args->mount_server.version = NFS_MNT3_VERSION; |
| 1469 | else |
| 1470 | args->mount_server.version = NFS_MNT_VERSION; |
| 1471 | } |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1472 | request.version = args->mount_server.version; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1473 | |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1474 | if (args->mount_server.hostname) |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1475 | request.hostname = args->mount_server.hostname; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1476 | else |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1477 | request.hostname = args->nfs_server.hostname; |
Chuck Lever | 3383203 | 2007-12-10 14:59:13 -0500 | [diff] [blame] | 1478 | |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1479 | /* |
| 1480 | * Construct the mount server's address. |
| 1481 | */ |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1482 | if (args->mount_server.address.ss_family == AF_UNSPEC) { |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1483 | memcpy(request.sap, &args->nfs_server.address, |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1484 | args->nfs_server.addrlen); |
| 1485 | args->mount_server.addrlen = args->nfs_server.addrlen; |
| 1486 | } |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1487 | request.salen = args->mount_server.addrlen; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1488 | |
James Lentini | aad7000 | 2007-09-24 17:32:49 -0400 | [diff] [blame] | 1489 | /* |
| 1490 | * autobind will be used if mount_server.port == 0 |
| 1491 | */ |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1492 | nfs_set_port(request.sap, args->mount_server.port); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1493 | |
| 1494 | /* |
| 1495 | * Now ask the mount server to map our export path |
| 1496 | * to a file handle. |
| 1497 | */ |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1498 | status = nfs_mount(&request); |
Chuck Lever | efd8340 | 2007-09-11 18:00:58 -0400 | [diff] [blame] | 1499 | if (status == 0) |
| 1500 | return 0; |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1501 | |
Chuck Lever | 396cee97 | 2008-06-12 12:37:49 -0400 | [diff] [blame] | 1502 | dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n", |
Chuck Lever | c5d120f | 2008-12-23 15:21:35 -0500 | [diff] [blame] | 1503 | request.hostname, status); |
Chuck Lever | 0076d7b | 2007-07-01 12:13:49 -0400 | [diff] [blame] | 1504 | return status; |
| 1505 | } |
| 1506 | |
Chuck Lever | d1aa082 | 2008-06-23 12:36:45 -0400 | [diff] [blame] | 1507 | static int nfs_parse_simple_hostname(const char *dev_name, |
| 1508 | char **hostname, size_t maxnamlen, |
| 1509 | char **export_path, size_t maxpathlen) |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1510 | { |
| 1511 | size_t len; |
| 1512 | char *colon, *comma; |
| 1513 | |
| 1514 | colon = strchr(dev_name, ':'); |
| 1515 | if (colon == NULL) |
| 1516 | goto out_bad_devname; |
| 1517 | |
| 1518 | len = colon - dev_name; |
| 1519 | if (len > maxnamlen) |
| 1520 | goto out_hostname; |
| 1521 | |
| 1522 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1523 | *hostname = kstrndup(dev_name, len, GFP_KERNEL); |
| 1524 | if (!*hostname) |
| 1525 | goto out_nomem; |
| 1526 | |
| 1527 | /* kill possible hostname list: not supported */ |
| 1528 | comma = strchr(*hostname, ','); |
| 1529 | if (comma != NULL) { |
| 1530 | if (comma == *hostname) |
| 1531 | goto out_bad_devname; |
| 1532 | *comma = '\0'; |
| 1533 | } |
| 1534 | |
| 1535 | colon++; |
| 1536 | len = strlen(colon); |
| 1537 | if (len > maxpathlen) |
| 1538 | goto out_path; |
| 1539 | *export_path = kstrndup(colon, len, GFP_KERNEL); |
| 1540 | if (!*export_path) |
| 1541 | goto out_nomem; |
| 1542 | |
| 1543 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", *export_path); |
| 1544 | return 0; |
| 1545 | |
| 1546 | out_bad_devname: |
| 1547 | dfprintk(MOUNT, "NFS: device name not in host:path format\n"); |
| 1548 | return -EINVAL; |
| 1549 | |
| 1550 | out_nomem: |
| 1551 | dfprintk(MOUNT, "NFS: not enough memory to parse device name\n"); |
| 1552 | return -ENOMEM; |
| 1553 | |
| 1554 | out_hostname: |
| 1555 | dfprintk(MOUNT, "NFS: server hostname too long\n"); |
| 1556 | return -ENAMETOOLONG; |
| 1557 | |
| 1558 | out_path: |
| 1559 | dfprintk(MOUNT, "NFS: export pathname too long\n"); |
| 1560 | return -ENAMETOOLONG; |
| 1561 | } |
| 1562 | |
| 1563 | /* |
Chuck Lever | d1aa082 | 2008-06-23 12:36:45 -0400 | [diff] [blame] | 1564 | * Hostname has square brackets around it because it contains one or |
| 1565 | * more colons. We look for the first closing square bracket, and a |
| 1566 | * colon must follow it. |
| 1567 | */ |
| 1568 | static int nfs_parse_protected_hostname(const char *dev_name, |
| 1569 | char **hostname, size_t maxnamlen, |
| 1570 | char **export_path, size_t maxpathlen) |
| 1571 | { |
| 1572 | size_t len; |
| 1573 | char *start, *end; |
| 1574 | |
| 1575 | start = (char *)(dev_name + 1); |
| 1576 | |
| 1577 | end = strchr(start, ']'); |
| 1578 | if (end == NULL) |
| 1579 | goto out_bad_devname; |
| 1580 | if (*(end + 1) != ':') |
| 1581 | goto out_bad_devname; |
| 1582 | |
| 1583 | len = end - start; |
| 1584 | if (len > maxnamlen) |
| 1585 | goto out_hostname; |
| 1586 | |
| 1587 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1588 | *hostname = kstrndup(start, len, GFP_KERNEL); |
| 1589 | if (*hostname == NULL) |
| 1590 | goto out_nomem; |
| 1591 | |
| 1592 | end += 2; |
| 1593 | len = strlen(end); |
| 1594 | if (len > maxpathlen) |
| 1595 | goto out_path; |
| 1596 | *export_path = kstrndup(end, len, GFP_KERNEL); |
| 1597 | if (!*export_path) |
| 1598 | goto out_nomem; |
| 1599 | |
| 1600 | return 0; |
| 1601 | |
| 1602 | out_bad_devname: |
| 1603 | dfprintk(MOUNT, "NFS: device name not in host:path format\n"); |
| 1604 | return -EINVAL; |
| 1605 | |
| 1606 | out_nomem: |
| 1607 | dfprintk(MOUNT, "NFS: not enough memory to parse device name\n"); |
| 1608 | return -ENOMEM; |
| 1609 | |
| 1610 | out_hostname: |
| 1611 | dfprintk(MOUNT, "NFS: server hostname too long\n"); |
| 1612 | return -ENAMETOOLONG; |
| 1613 | |
| 1614 | out_path: |
| 1615 | dfprintk(MOUNT, "NFS: export pathname too long\n"); |
| 1616 | return -ENAMETOOLONG; |
| 1617 | } |
| 1618 | |
| 1619 | /* |
| 1620 | * Split "dev_name" into "hostname:export_path". |
| 1621 | * |
| 1622 | * The leftmost colon demarks the split between the server's hostname |
| 1623 | * and the export path. If the hostname starts with a left square |
| 1624 | * bracket, then it may contain colons. |
| 1625 | * |
| 1626 | * Note: caller frees hostname and export path, even on error. |
| 1627 | */ |
| 1628 | static int nfs_parse_devname(const char *dev_name, |
| 1629 | char **hostname, size_t maxnamlen, |
| 1630 | char **export_path, size_t maxpathlen) |
| 1631 | { |
| 1632 | if (*dev_name == '[') |
| 1633 | return nfs_parse_protected_hostname(dev_name, |
| 1634 | hostname, maxnamlen, |
| 1635 | export_path, maxpathlen); |
| 1636 | |
| 1637 | return nfs_parse_simple_hostname(dev_name, |
| 1638 | hostname, maxnamlen, |
| 1639 | export_path, maxpathlen); |
| 1640 | } |
| 1641 | |
| 1642 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1643 | * Validate the NFS2/NFS3 mount data |
| 1644 | * - fills in the mount root filehandle |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1645 | * |
| 1646 | * For option strings, user space handles the following behaviors: |
| 1647 | * |
| 1648 | * + DNS: mapping server host name to IP address ("addr=" option) |
| 1649 | * |
| 1650 | * + failure mode: how to behave if a mount request can't be handled |
| 1651 | * immediately ("fg/bg" option) |
| 1652 | * |
| 1653 | * + retry: how often to retry a mount request ("retry=" option) |
| 1654 | * |
| 1655 | * + breaking back: trying proto=udp after proto=tcp, v2 after v3, |
| 1656 | * mountproto=tcp after mountproto=udp, and so on |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1657 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1658 | static int nfs_validate_mount_data(void *options, |
| 1659 | struct nfs_parsed_mount_data *args, |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1660 | struct nfs_fh *mntfh, |
| 1661 | const char *dev_name) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1662 | { |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1663 | struct nfs_mount_data *data = (struct nfs_mount_data *)options; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1664 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1665 | if (data == NULL) |
| 1666 | goto out_no_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1667 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1668 | args->flags = (NFS_MOUNT_VER3 | NFS_MOUNT_TCP); |
| 1669 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 1670 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
Chuck Lever | 0e0cab7 | 2008-06-26 17:47:12 -0400 | [diff] [blame] | 1671 | args->acregmin = NFS_DEF_ACREGMIN; |
| 1672 | args->acregmax = NFS_DEF_ACREGMAX; |
| 1673 | args->acdirmin = NFS_DEF_ACDIRMIN; |
| 1674 | args->acdirmax = NFS_DEF_ACDIRMAX; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1675 | args->mount_server.port = 0; /* autobind unless user sets port */ |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 1676 | args->nfs_server.port = 0; /* autobind unless user sets port */ |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1677 | args->nfs_server.protocol = XPRT_TRANSPORT_TCP; |
Chuck Lever | dd07c94 | 2008-06-24 16:33:46 -0400 | [diff] [blame] | 1678 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1679 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1680 | switch (data->version) { |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1681 | case 1: |
| 1682 | data->namlen = 0; |
| 1683 | case 2: |
| 1684 | data->bsize = 0; |
| 1685 | case 3: |
| 1686 | if (data->flags & NFS_MOUNT_VER3) |
| 1687 | goto out_no_v3; |
| 1688 | data->root.size = NFS2_FHSIZE; |
| 1689 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 1690 | case 4: |
| 1691 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1692 | goto out_no_sec; |
| 1693 | case 5: |
| 1694 | memset(data->context, 0, sizeof(data->context)); |
| 1695 | case 6: |
Trond Myklebust | b7e2445 | 2008-06-19 15:21:11 -0400 | [diff] [blame] | 1696 | if (data->flags & NFS_MOUNT_VER3) { |
| 1697 | if (data->root.size > NFS3_FHSIZE || data->root.size == 0) |
| 1698 | goto out_invalid_fh; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1699 | mntfh->size = data->root.size; |
Trond Myklebust | b7e2445 | 2008-06-19 15:21:11 -0400 | [diff] [blame] | 1700 | } else |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1701 | mntfh->size = NFS2_FHSIZE; |
| 1702 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1703 | |
| 1704 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 1705 | if (mntfh->size < sizeof(mntfh->data)) |
| 1706 | memset(mntfh->data + mntfh->size, 0, |
| 1707 | sizeof(mntfh->data) - mntfh->size); |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1708 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1709 | /* |
| 1710 | * Translate to nfs_parsed_mount_data, which nfs_fill_super |
| 1711 | * can deal with. |
| 1712 | */ |
Trond Myklebust | ff3525a | 2008-08-15 16:59:14 -0400 | [diff] [blame] | 1713 | args->flags = data->flags & NFS_MOUNT_FLAGMASK; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1714 | args->rsize = data->rsize; |
| 1715 | args->wsize = data->wsize; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1716 | args->timeo = data->timeo; |
| 1717 | args->retrans = data->retrans; |
| 1718 | args->acregmin = data->acregmin; |
| 1719 | args->acregmax = data->acregmax; |
| 1720 | args->acdirmin = data->acdirmin; |
| 1721 | args->acdirmax = data->acdirmax; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 1722 | |
| 1723 | memcpy(&args->nfs_server.address, &data->addr, |
| 1724 | sizeof(data->addr)); |
| 1725 | args->nfs_server.addrlen = sizeof(data->addr); |
| 1726 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1727 | &args->nfs_server.address)) |
| 1728 | goto out_no_address; |
| 1729 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1730 | if (!(data->flags & NFS_MOUNT_TCP)) |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 1731 | args->nfs_server.protocol = XPRT_TRANSPORT_UDP; |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1732 | /* N.B. caller will free nfs_server.hostname in all cases */ |
| 1733 | args->nfs_server.hostname = kstrdup(data->hostname, GFP_KERNEL); |
| 1734 | args->namlen = data->namlen; |
| 1735 | args->bsize = data->bsize; |
Chuck Lever | dd07c94 | 2008-06-24 16:33:46 -0400 | [diff] [blame] | 1736 | |
| 1737 | if (data->flags & NFS_MOUNT_SECFLAVOUR) |
| 1738 | args->auth_flavors[0] = data->pseudoflavor; |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1739 | if (!args->nfs_server.hostname) |
| 1740 | goto out_nomem; |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 1741 | |
| 1742 | /* |
| 1743 | * The legacy version 6 binary mount data from userspace has a |
| 1744 | * field used only to transport selinux information into the |
| 1745 | * the kernel. To continue to support that functionality we |
| 1746 | * have a touch of selinux knowledge here in the NFS code. The |
| 1747 | * userspace code converted context=blah to just blah so we are |
| 1748 | * converting back to the full string selinux understands. |
| 1749 | */ |
| 1750 | if (data->context[0]){ |
| 1751 | #ifdef CONFIG_SECURITY_SELINUX |
| 1752 | int rc; |
| 1753 | char *opts_str = kmalloc(sizeof(data->context) + 8, GFP_KERNEL); |
| 1754 | if (!opts_str) |
| 1755 | return -ENOMEM; |
| 1756 | strcpy(opts_str, "context="); |
| 1757 | data->context[NFS_MAX_CONTEXT_LEN] = '\0'; |
| 1758 | strcat(opts_str, &data->context[0]); |
| 1759 | rc = security_sb_parse_opts_str(opts_str, &args->lsm_opts); |
| 1760 | kfree(opts_str); |
| 1761 | if (rc) |
| 1762 | return rc; |
| 1763 | #else |
| 1764 | return -EINVAL; |
| 1765 | #endif |
| 1766 | } |
| 1767 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1768 | break; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1769 | default: { |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1770 | int status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1771 | |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1772 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1773 | return -EINVAL; |
| 1774 | |
Chuck Lever | 6e88e06 | 2007-09-24 15:39:50 -0400 | [diff] [blame] | 1775 | if (!nfs_verify_server_address((struct sockaddr *) |
| 1776 | &args->nfs_server.address)) |
| 1777 | goto out_no_address; |
| 1778 | |
Chuck Lever | ed596a8 | 2008-06-26 17:47:05 -0400 | [diff] [blame] | 1779 | nfs_set_port((struct sockaddr *)&args->nfs_server.address, |
| 1780 | args->nfs_server.port); |
| 1781 | |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 1782 | nfs_set_mount_transport_protocol(args); |
| 1783 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1784 | status = nfs_parse_devname(dev_name, |
| 1785 | &args->nfs_server.hostname, |
| 1786 | PAGE_SIZE, |
| 1787 | &args->nfs_server.export_path, |
| 1788 | NFS_MAXPATHLEN); |
| 1789 | if (!status) |
| 1790 | status = nfs_try_mount(args, mntfh); |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1791 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 1792 | kfree(args->nfs_server.export_path); |
| 1793 | args->nfs_server.export_path = NULL; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1794 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1795 | if (status) |
Chuck Lever | fdc6e2c | 2007-08-29 17:58:59 -0400 | [diff] [blame] | 1796 | return status; |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1797 | |
Chuck Lever | 136d558 | 2007-07-01 12:13:54 -0400 | [diff] [blame] | 1798 | break; |
| 1799 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1800 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1801 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1802 | #ifndef CONFIG_NFS_V3 |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1803 | if (args->flags & NFS_MOUNT_VER3) |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1804 | goto out_v3_not_compiled; |
| 1805 | #endif /* !CONFIG_NFS_V3 */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1806 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1807 | return 0; |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1808 | |
| 1809 | out_no_data: |
| 1810 | dfprintk(MOUNT, "NFS: mount program didn't pass any mount data\n"); |
| 1811 | return -EINVAL; |
| 1812 | |
| 1813 | out_no_v3: |
| 1814 | dfprintk(MOUNT, "NFS: nfs_mount_data version %d does not support v3\n", |
| 1815 | data->version); |
| 1816 | return -EINVAL; |
| 1817 | |
| 1818 | out_no_sec: |
| 1819 | dfprintk(MOUNT, "NFS: nfs_mount_data version supports only AUTH_SYS\n"); |
| 1820 | return -EINVAL; |
| 1821 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1822 | #ifndef CONFIG_NFS_V3 |
| 1823 | out_v3_not_compiled: |
| 1824 | dfprintk(MOUNT, "NFS: NFSv3 is not compiled into kernel\n"); |
| 1825 | return -EPROTONOSUPPORT; |
| 1826 | #endif /* !CONFIG_NFS_V3 */ |
| 1827 | |
Cyrill Gorcunov | 63649bd | 2008-04-17 20:42:09 +0400 | [diff] [blame] | 1828 | out_nomem: |
| 1829 | dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n"); |
| 1830 | return -ENOMEM; |
| 1831 | |
Chuck Lever | 5df36e7 | 2007-07-01 12:12:56 -0400 | [diff] [blame] | 1832 | out_no_address: |
| 1833 | dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); |
| 1834 | return -EINVAL; |
| 1835 | |
| 1836 | out_invalid_fh: |
| 1837 | dfprintk(MOUNT, "NFS: invalid root filehandle\n"); |
| 1838 | return -EINVAL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1839 | } |
| 1840 | |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1841 | static int |
| 1842 | nfs_compare_remount_data(struct nfs_server *nfss, |
| 1843 | struct nfs_parsed_mount_data *data) |
| 1844 | { |
| 1845 | if (data->flags != nfss->flags || |
| 1846 | data->rsize != nfss->rsize || |
| 1847 | data->wsize != nfss->wsize || |
| 1848 | data->retrans != nfss->client->cl_timeout->to_retries || |
| 1849 | data->auth_flavors[0] != nfss->client->cl_auth->au_flavor || |
| 1850 | data->acregmin != nfss->acregmin / HZ || |
| 1851 | data->acregmax != nfss->acregmax / HZ || |
| 1852 | data->acdirmin != nfss->acdirmin / HZ || |
| 1853 | data->acdirmax != nfss->acdirmax / HZ || |
| 1854 | data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) || |
| 1855 | data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen || |
| 1856 | memcmp(&data->nfs_server.address, &nfss->nfs_client->cl_addr, |
| 1857 | data->nfs_server.addrlen) != 0) |
| 1858 | return -EINVAL; |
| 1859 | |
| 1860 | return 0; |
| 1861 | } |
| 1862 | |
| 1863 | static int |
| 1864 | nfs_remount(struct super_block *sb, int *flags, char *raw_data) |
| 1865 | { |
| 1866 | int error; |
| 1867 | struct nfs_server *nfss = sb->s_fs_info; |
| 1868 | struct nfs_parsed_mount_data *data; |
| 1869 | struct nfs_mount_data *options = (struct nfs_mount_data *)raw_data; |
| 1870 | struct nfs4_mount_data *options4 = (struct nfs4_mount_data *)raw_data; |
Trond Myklebust | cd10072 | 2008-06-17 16:12:00 -0400 | [diff] [blame] | 1871 | u32 nfsvers = nfss->nfs_client->rpc_ops->version; |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1872 | |
| 1873 | /* |
| 1874 | * Userspace mount programs that send binary options generally send |
| 1875 | * them populated with default values. We have no way to know which |
| 1876 | * ones were explicitly specified. Fall back to legacy behavior and |
| 1877 | * just return success. |
| 1878 | */ |
Marc Zyngier | 31c9446 | 2008-07-17 13:21:55 +0200 | [diff] [blame] | 1879 | if ((nfsvers == 4 && (!options4 || options4->version == 1)) || |
| 1880 | (nfsvers <= 3 && (!options || (options->version >= 1 && |
| 1881 | options->version <= 6)))) |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1882 | return 0; |
| 1883 | |
| 1884 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 1885 | if (data == NULL) |
| 1886 | return -ENOMEM; |
| 1887 | |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 1888 | lock_kernel(); |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1889 | /* fill out struct with values from existing mount */ |
| 1890 | data->flags = nfss->flags; |
| 1891 | data->rsize = nfss->rsize; |
| 1892 | data->wsize = nfss->wsize; |
| 1893 | data->retrans = nfss->client->cl_timeout->to_retries; |
| 1894 | data->auth_flavors[0] = nfss->client->cl_auth->au_flavor; |
| 1895 | data->acregmin = nfss->acregmin / HZ; |
| 1896 | data->acregmax = nfss->acregmax / HZ; |
| 1897 | data->acdirmin = nfss->acdirmin / HZ; |
| 1898 | data->acdirmax = nfss->acdirmax / HZ; |
| 1899 | data->timeo = 10U * nfss->client->cl_timeout->to_initval / HZ; |
| 1900 | data->nfs_server.addrlen = nfss->nfs_client->cl_addrlen; |
| 1901 | memcpy(&data->nfs_server.address, &nfss->nfs_client->cl_addr, |
| 1902 | data->nfs_server.addrlen); |
| 1903 | |
| 1904 | /* overwrite those values with any that were specified */ |
| 1905 | error = nfs_parse_mount_options((char *)options, data); |
| 1906 | if (error < 0) |
| 1907 | goto out; |
| 1908 | |
| 1909 | /* compare new mount options with old ones */ |
| 1910 | error = nfs_compare_remount_data(nfss, data); |
| 1911 | out: |
| 1912 | kfree(data); |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 1913 | unlock_kernel(); |
Jeff Layton | 48b605f | 2008-06-10 15:38:39 -0400 | [diff] [blame] | 1914 | return error; |
| 1915 | } |
| 1916 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1917 | /* |
| 1918 | * Initialise the common bits of the superblock |
| 1919 | */ |
| 1920 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 1921 | { |
| 1922 | struct nfs_server *server = NFS_SB(sb); |
| 1923 | |
| 1924 | sb->s_magic = NFS_SUPER_MAGIC; |
| 1925 | |
| 1926 | /* We probably want something more informative here */ |
| 1927 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 1928 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 1929 | |
| 1930 | if (sb->s_blocksize == 0) |
| 1931 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 1932 | &sb->s_blocksize_bits); |
| 1933 | |
| 1934 | if (server->flags & NFS_MOUNT_NOAC) |
| 1935 | sb->s_flags |= MS_SYNCHRONOUS; |
| 1936 | |
| 1937 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 1938 | } |
| 1939 | |
| 1940 | /* |
| 1941 | * Finish setting up an NFS2/3 superblock |
| 1942 | */ |
\"Talpey, Thomas\ | 2283f8d | 2007-09-10 13:43:56 -0400 | [diff] [blame] | 1943 | static void nfs_fill_super(struct super_block *sb, |
| 1944 | struct nfs_parsed_mount_data *data) |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1945 | { |
| 1946 | struct nfs_server *server = NFS_SB(sb); |
| 1947 | |
| 1948 | sb->s_blocksize_bits = 0; |
| 1949 | sb->s_blocksize = 0; |
| 1950 | if (data->bsize) |
| 1951 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 1952 | |
| 1953 | if (server->flags & NFS_MOUNT_VER3) { |
| 1954 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1955 | * so ourselves when necessary. |
| 1956 | */ |
| 1957 | sb->s_flags |= MS_POSIXACL; |
| 1958 | sb->s_time_gran = 1; |
| 1959 | } |
| 1960 | |
| 1961 | sb->s_op = &nfs_sops; |
| 1962 | nfs_initialise_sb(sb); |
| 1963 | } |
| 1964 | |
| 1965 | /* |
| 1966 | * Finish setting up a cloned NFS2/3 superblock |
| 1967 | */ |
| 1968 | static void nfs_clone_super(struct super_block *sb, |
| 1969 | const struct super_block *old_sb) |
| 1970 | { |
| 1971 | struct nfs_server *server = NFS_SB(sb); |
| 1972 | |
| 1973 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 1974 | sb->s_blocksize = old_sb->s_blocksize; |
| 1975 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 1976 | |
| 1977 | if (server->flags & NFS_MOUNT_VER3) { |
| 1978 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 1979 | * so ourselves when necessary. |
| 1980 | */ |
| 1981 | sb->s_flags |= MS_POSIXACL; |
| 1982 | sb->s_time_gran = 1; |
| 1983 | } |
| 1984 | |
| 1985 | sb->s_op = old_sb->s_op; |
| 1986 | nfs_initialise_sb(sb); |
| 1987 | } |
| 1988 | |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 1989 | static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b, int flags) |
| 1990 | { |
| 1991 | const struct nfs_server *a = s->s_fs_info; |
| 1992 | const struct rpc_clnt *clnt_a = a->client; |
| 1993 | const struct rpc_clnt *clnt_b = b->client; |
| 1994 | |
| 1995 | if ((s->s_flags & NFS_MS_MASK) != (flags & NFS_MS_MASK)) |
| 1996 | goto Ebusy; |
| 1997 | if (a->nfs_client != b->nfs_client) |
| 1998 | goto Ebusy; |
| 1999 | if (a->flags != b->flags) |
| 2000 | goto Ebusy; |
| 2001 | if (a->wsize != b->wsize) |
| 2002 | goto Ebusy; |
| 2003 | if (a->rsize != b->rsize) |
| 2004 | goto Ebusy; |
| 2005 | if (a->acregmin != b->acregmin) |
| 2006 | goto Ebusy; |
| 2007 | if (a->acregmax != b->acregmax) |
| 2008 | goto Ebusy; |
| 2009 | if (a->acdirmin != b->acdirmin) |
| 2010 | goto Ebusy; |
| 2011 | if (a->acdirmax != b->acdirmax) |
| 2012 | goto Ebusy; |
| 2013 | if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor) |
| 2014 | goto Ebusy; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2015 | return 1; |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2016 | Ebusy: |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2017 | return 0; |
| 2018 | } |
| 2019 | |
| 2020 | struct nfs_sb_mountdata { |
| 2021 | struct nfs_server *server; |
| 2022 | int mntflags; |
| 2023 | }; |
| 2024 | |
| 2025 | static int nfs_set_super(struct super_block *s, void *data) |
| 2026 | { |
| 2027 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 2028 | struct nfs_server *server = sb_mntdata->server; |
| 2029 | int ret; |
| 2030 | |
| 2031 | s->s_flags = sb_mntdata->mntflags; |
| 2032 | s->s_fs_info = server; |
| 2033 | ret = set_anon_super(s, server); |
| 2034 | if (ret == 0) |
| 2035 | server->s_dev = s->s_dev; |
| 2036 | return ret; |
| 2037 | } |
| 2038 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 2039 | static int nfs_compare_super_address(struct nfs_server *server1, |
| 2040 | struct nfs_server *server2) |
| 2041 | { |
| 2042 | struct sockaddr *sap1, *sap2; |
| 2043 | |
| 2044 | sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr; |
| 2045 | sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr; |
| 2046 | |
| 2047 | if (sap1->sa_family != sap2->sa_family) |
| 2048 | return 0; |
| 2049 | |
| 2050 | switch (sap1->sa_family) { |
| 2051 | case AF_INET: { |
| 2052 | struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1; |
| 2053 | struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2; |
| 2054 | if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) |
| 2055 | return 0; |
| 2056 | if (sin1->sin_port != sin2->sin_port) |
| 2057 | return 0; |
| 2058 | break; |
| 2059 | } |
| 2060 | case AF_INET6: { |
| 2061 | struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1; |
| 2062 | struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2; |
| 2063 | if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr)) |
| 2064 | return 0; |
| 2065 | if (sin1->sin6_port != sin2->sin6_port) |
| 2066 | return 0; |
| 2067 | break; |
| 2068 | } |
| 2069 | default: |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
| 2073 | return 1; |
| 2074 | } |
| 2075 | |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2076 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 2077 | { |
| 2078 | struct nfs_sb_mountdata *sb_mntdata = data; |
| 2079 | struct nfs_server *server = sb_mntdata->server, *old = NFS_SB(sb); |
| 2080 | int mntflags = sb_mntdata->mntflags; |
| 2081 | |
Chuck Lever | fd00a8f | 2007-12-10 14:57:38 -0500 | [diff] [blame] | 2082 | if (!nfs_compare_super_address(old, server)) |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2083 | return 0; |
| 2084 | /* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */ |
| 2085 | if (old->flags & NFS_MOUNT_UNSHARED) |
| 2086 | return 0; |
| 2087 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 2088 | return 0; |
| 2089 | return nfs_compare_mount_options(sb, server, mntflags); |
Trond Myklebust | 275a5d2 | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2090 | } |
| 2091 | |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2092 | static int nfs_bdi_register(struct nfs_server *server) |
| 2093 | { |
| 2094 | return bdi_register_dev(&server->backing_dev_info, server->s_dev); |
| 2095 | } |
| 2096 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2097 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 2098 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 2099 | { |
| 2100 | struct nfs_server *server = NULL; |
| 2101 | struct super_block *s; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2102 | struct nfs_parsed_mount_data *data; |
| 2103 | struct nfs_fh *mntfh; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2104 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2105 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2106 | struct nfs_sb_mountdata sb_mntdata = { |
| 2107 | .mntflags = flags, |
| 2108 | }; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2109 | int error = -ENOMEM; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2110 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2111 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2112 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); |
| 2113 | if (data == NULL || mntfh == NULL) |
| 2114 | goto out_free_fh; |
| 2115 | |
| 2116 | security_init_mnt_opts(&data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2117 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2118 | /* Validate the mount data */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2119 | error = nfs_validate_mount_data(raw_data, data, mntfh, dev_name); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2120 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2121 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2122 | |
| 2123 | /* Get a volume representation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2124 | server = nfs_create_server(data, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2125 | if (IS_ERR(server)) { |
| 2126 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2127 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2128 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2129 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2130 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2131 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 2132 | compare_super = NULL; |
| 2133 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2134 | /* 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] | 2135 | s = sget(fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2136 | if (IS_ERR(s)) { |
| 2137 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2138 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2139 | } |
| 2140 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2141 | if (s->s_fs_info != server) { |
| 2142 | nfs_free_server(server); |
| 2143 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2144 | } else { |
| 2145 | error = nfs_bdi_register(server); |
| 2146 | if (error) |
| 2147 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2148 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2149 | |
| 2150 | if (!s->s_root) { |
| 2151 | /* initial superblock/root creation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2152 | nfs_fill_super(s, data); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2153 | nfs_fscache_get_super_cookie(s, data); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2156 | mntroot = nfs_get_root(s, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2157 | if (IS_ERR(mntroot)) { |
| 2158 | error = PTR_ERR(mntroot); |
| 2159 | goto error_splat_super; |
| 2160 | } |
| 2161 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2162 | error = security_sb_set_mnt_opts(s, &data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2163 | if (error) |
| 2164 | goto error_splat_root; |
| 2165 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2166 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2167 | mnt->mnt_sb = s; |
| 2168 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2169 | error = 0; |
| 2170 | |
| 2171 | out: |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2172 | kfree(data->nfs_server.hostname); |
| 2173 | kfree(data->mount_server.hostname); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2174 | kfree(data->fscache_uniq); |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2175 | security_free_mnt_opts(&data->lsm_opts); |
| 2176 | out_free_fh: |
| 2177 | kfree(mntfh); |
| 2178 | kfree(data); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2179 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2180 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2181 | out_err_nosb: |
| 2182 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2183 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2184 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2185 | error_splat_root: |
| 2186 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2187 | error_splat_super: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2188 | deactivate_locked_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame] | 2189 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2190 | } |
| 2191 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2192 | /* |
| 2193 | * Destroy an NFS2/3 superblock |
| 2194 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2195 | static void nfs_kill_super(struct super_block *s) |
| 2196 | { |
| 2197 | struct nfs_server *server = NFS_SB(s); |
| 2198 | |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2199 | bdi_unregister(&server->backing_dev_info); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2200 | kill_anon_super(s); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2201 | nfs_fscache_release_super_cookie(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2202 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2203 | } |
| 2204 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2205 | /* |
| 2206 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 2207 | */ |
| 2208 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 2209 | const char *dev_name, void *raw_data, |
| 2210 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2211 | { |
| 2212 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2213 | struct super_block *s; |
| 2214 | struct nfs_server *server; |
| 2215 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2216 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2217 | struct nfs_sb_mountdata sb_mntdata = { |
| 2218 | .mntflags = flags, |
| 2219 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2220 | int error; |
| 2221 | |
| 2222 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 2223 | |
| 2224 | /* create a new volume representation */ |
| 2225 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2226 | if (IS_ERR(server)) { |
| 2227 | error = PTR_ERR(server); |
| 2228 | goto out_err_noserver; |
| 2229 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2230 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2231 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2232 | if (server->flags & NFS_MOUNT_UNSHARED) |
| 2233 | compare_super = NULL; |
| 2234 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2235 | /* 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] | 2236 | s = sget(&nfs_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2237 | if (IS_ERR(s)) { |
| 2238 | error = PTR_ERR(s); |
| 2239 | goto out_err_nosb; |
| 2240 | } |
| 2241 | |
| 2242 | if (s->s_fs_info != server) { |
| 2243 | nfs_free_server(server); |
| 2244 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2245 | } else { |
| 2246 | error = nfs_bdi_register(server); |
| 2247 | if (error) |
| 2248 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | if (!s->s_root) { |
| 2252 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2253 | nfs_clone_super(s, data->sb); |
| 2254 | } |
| 2255 | |
| 2256 | mntroot = nfs_get_root(s, data->fh); |
| 2257 | if (IS_ERR(mntroot)) { |
| 2258 | error = PTR_ERR(mntroot); |
| 2259 | goto error_splat_super; |
| 2260 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2261 | 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] | 2262 | dput(mntroot); |
| 2263 | error = -ESTALE; |
| 2264 | goto error_splat_super; |
| 2265 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2266 | |
| 2267 | s->s_flags |= MS_ACTIVE; |
| 2268 | mnt->mnt_sb = s; |
| 2269 | mnt->mnt_root = mntroot; |
| 2270 | |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2271 | /* clone any lsm security options from the parent to the new sb */ |
| 2272 | security_sb_clone_mnt_opts(data->sb, s); |
| 2273 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2274 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 2275 | return 0; |
| 2276 | |
| 2277 | out_err_nosb: |
| 2278 | nfs_free_server(server); |
| 2279 | out_err_noserver: |
| 2280 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 2281 | return error; |
| 2282 | |
| 2283 | error_splat_super: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2284 | deactivate_locked_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2285 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 2286 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2290 | |
| 2291 | /* |
| 2292 | * Finish setting up a cloned NFS4 superblock |
| 2293 | */ |
| 2294 | static void nfs4_clone_super(struct super_block *sb, |
| 2295 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2296 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2297 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 2298 | sb->s_blocksize = old_sb->s_blocksize; |
| 2299 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 2300 | sb->s_time_gran = 1; |
| 2301 | sb->s_op = old_sb->s_op; |
| 2302 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | /* |
| 2306 | * Set up an NFS4 superblock |
| 2307 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2308 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2309 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2310 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2311 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2312 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2313 | } |
| 2314 | |
Trond Myklebust | 01c3f05 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 2315 | static void nfs4_validate_mount_flags(struct nfs_parsed_mount_data *args) |
| 2316 | { |
| 2317 | args->flags &= ~(NFS_MOUNT_NONLM|NFS_MOUNT_NOACL|NFS_MOUNT_VER3); |
| 2318 | } |
| 2319 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2320 | /* |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2321 | * Validate NFSv4 mount options |
| 2322 | */ |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2323 | static int nfs4_validate_mount_data(void *options, |
| 2324 | struct nfs_parsed_mount_data *args, |
| 2325 | const char *dev_name) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2326 | { |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 2327 | struct sockaddr_in *ap; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2328 | struct nfs4_mount_data *data = (struct nfs4_mount_data *)options; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2329 | char *c; |
| 2330 | |
| 2331 | if (data == NULL) |
| 2332 | goto out_no_data; |
| 2333 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2334 | args->rsize = NFS_MAX_FILE_IO_SIZE; |
| 2335 | args->wsize = NFS_MAX_FILE_IO_SIZE; |
Chuck Lever | 0e0cab7 | 2008-06-26 17:47:12 -0400 | [diff] [blame] | 2336 | args->acregmin = NFS_DEF_ACREGMIN; |
| 2337 | args->acregmax = NFS_DEF_ACREGMAX; |
| 2338 | args->acdirmin = NFS_DEF_ACDIRMIN; |
| 2339 | args->acdirmax = NFS_DEF_ACDIRMAX; |
Chuck Lever | f22d6d7 | 2008-03-14 14:10:22 -0400 | [diff] [blame] | 2340 | args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */ |
Chuck Lever | 6738b25 | 2008-06-24 16:33:54 -0400 | [diff] [blame] | 2341 | args->auth_flavors[0] = RPC_AUTH_UNIX; |
| 2342 | args->auth_flavor_len = 0; |
Mike Sager | 3fd5be9 | 2009-04-01 09:21:48 -0400 | [diff] [blame] | 2343 | args->minorversion = 0; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2344 | |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2345 | switch (data->version) { |
| 2346 | case 1: |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 2347 | ap = (struct sockaddr_in *)&args->nfs_server.address; |
| 2348 | if (data->host_addrlen > sizeof(args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2349 | goto out_no_address; |
Chuck Lever | 4c56801 | 2007-12-10 14:59:28 -0500 | [diff] [blame] | 2350 | if (data->host_addrlen == 0) |
| 2351 | goto out_no_address; |
| 2352 | args->nfs_server.addrlen = data->host_addrlen; |
| 2353 | if (copy_from_user(ap, data->host_addr, data->host_addrlen)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2354 | return -EFAULT; |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2355 | if (!nfs_verify_server_address((struct sockaddr *) |
| 2356 | &args->nfs_server.address)) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2357 | goto out_no_address; |
| 2358 | |
Chuck Lever | 6738b25 | 2008-06-24 16:33:54 -0400 | [diff] [blame] | 2359 | if (data->auth_flavourlen) { |
| 2360 | if (data->auth_flavourlen > 1) |
| 2361 | goto out_inval_auth; |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 2362 | if (copy_from_user(&args->auth_flavors[0], |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2363 | data->auth_flavours, |
Trond Myklebust | 20c71f5 | 2007-09-20 20:23:51 -0400 | [diff] [blame] | 2364 | sizeof(args->auth_flavors[0]))) |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2365 | return -EFAULT; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | c = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
| 2369 | if (IS_ERR(c)) |
| 2370 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2371 | args->nfs_server.hostname = c; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2372 | |
| 2373 | c = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
| 2374 | if (IS_ERR(c)) |
| 2375 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2376 | args->nfs_server.export_path = c; |
| 2377 | dfprintk(MOUNT, "NFS: MNTPATH: '%s'\n", c); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2378 | |
| 2379 | c = strndup_user(data->client_addr.data, 16); |
| 2380 | if (IS_ERR(c)) |
| 2381 | return PTR_ERR(c); |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2382 | args->client_address = c; |
| 2383 | |
| 2384 | /* |
| 2385 | * Translate to nfs_parsed_mount_data, which nfs4_fill_super |
| 2386 | * can deal with. |
| 2387 | */ |
| 2388 | |
| 2389 | args->flags = data->flags & NFS4_MOUNT_FLAGMASK; |
| 2390 | args->rsize = data->rsize; |
| 2391 | args->wsize = data->wsize; |
| 2392 | args->timeo = data->timeo; |
| 2393 | args->retrans = data->retrans; |
| 2394 | args->acregmin = data->acregmin; |
| 2395 | args->acregmax = data->acregmax; |
| 2396 | args->acdirmin = data->acdirmin; |
| 2397 | args->acdirmax = data->acdirmax; |
| 2398 | args->nfs_server.protocol = data->proto; |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 2399 | nfs_validate_transport_protocol(args); |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2400 | |
| 2401 | break; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2402 | default: { |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 2403 | int status; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2404 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2405 | if (nfs_parse_mount_options((char *)options, args) == 0) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2406 | return -EINVAL; |
| 2407 | |
| 2408 | if (!nfs_verify_server_address((struct sockaddr *) |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2409 | &args->nfs_server.address)) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2410 | return -EINVAL; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2411 | |
Chuck Lever | ed596a8 | 2008-06-26 17:47:05 -0400 | [diff] [blame] | 2412 | nfs_set_port((struct sockaddr *)&args->nfs_server.address, |
| 2413 | args->nfs_server.port); |
| 2414 | |
Trond Myklebust | 259875e | 2008-07-02 14:43:47 -0400 | [diff] [blame] | 2415 | nfs_validate_transport_protocol(args); |
| 2416 | |
Trond Myklebust | 01c3f05 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 2417 | nfs4_validate_mount_flags(args); |
| 2418 | |
Chuck Lever | 6738b25 | 2008-06-24 16:33:54 -0400 | [diff] [blame] | 2419 | if (args->auth_flavor_len > 1) |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2420 | goto out_inval_auth; |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2421 | |
\"Talpey, Thomas\ | 91ea40b | 2007-09-10 13:44:33 -0400 | [diff] [blame] | 2422 | if (args->client_address == NULL) |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 2423 | goto out_no_client_address; |
| 2424 | |
Chuck Lever | dc04589 | 2008-06-23 12:36:37 -0400 | [diff] [blame] | 2425 | status = nfs_parse_devname(dev_name, |
| 2426 | &args->nfs_server.hostname, |
| 2427 | NFS4_MAXNAMLEN, |
| 2428 | &args->nfs_server.export_path, |
| 2429 | NFS4_MAXPATHLEN); |
| 2430 | if (status < 0) |
| 2431 | return status; |
| 2432 | |
Chuck Lever | 8007122 | 2007-07-01 12:13:59 -0400 | [diff] [blame] | 2433 | break; |
| 2434 | } |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | return 0; |
| 2438 | |
| 2439 | out_no_data: |
| 2440 | dfprintk(MOUNT, "NFS4: mount program didn't pass any mount data\n"); |
| 2441 | return -EINVAL; |
| 2442 | |
| 2443 | out_inval_auth: |
| 2444 | dfprintk(MOUNT, "NFS4: Invalid number of RPC auth flavours %d\n", |
| 2445 | data->auth_flavourlen); |
| 2446 | return -EINVAL; |
| 2447 | |
| 2448 | out_no_address: |
| 2449 | dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); |
| 2450 | return -EINVAL; |
Jeff Layton | 0a87cf1 | 2007-07-18 11:28:43 -0400 | [diff] [blame] | 2451 | |
| 2452 | out_no_client_address: |
| 2453 | dfprintk(MOUNT, "NFS4: mount program didn't pass callback address\n"); |
| 2454 | return -EINVAL; |
Chuck Lever | f0768eb | 2007-07-01 12:13:01 -0400 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | /* |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2458 | * Get the superblock for the NFS4 root partition |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2459 | */ |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2460 | static int nfs4_remote_get_sb(struct file_system_type *fs_type, |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2461 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2462 | { |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2463 | struct nfs_parsed_mount_data *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2464 | struct super_block *s; |
| 2465 | struct nfs_server *server; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2466 | struct nfs_fh *mntfh; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2467 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2468 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2469 | struct nfs_sb_mountdata sb_mntdata = { |
| 2470 | .mntflags = flags, |
| 2471 | }; |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2472 | int error = -ENOMEM; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2473 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2474 | mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL); |
| 2475 | if (data == NULL || mntfh == NULL) |
| 2476 | goto out_free_fh; |
| 2477 | |
| 2478 | security_init_mnt_opts(&data->lsm_opts); |
Eric Paris | f9c3a38 | 2008-03-05 14:20:18 -0500 | [diff] [blame] | 2479 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2480 | /* Get a volume representation */ |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2481 | server = nfs4_create_server(data, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2482 | if (IS_ERR(server)) { |
| 2483 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2484 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2485 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2486 | sb_mntdata.server = server; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2487 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2488 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2489 | compare_super = NULL; |
| 2490 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2491 | /* 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] | 2492 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2493 | if (IS_ERR(s)) { |
| 2494 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2495 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2496 | } |
| 2497 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 2498 | if (s->s_fs_info != server) { |
| 2499 | nfs_free_server(server); |
| 2500 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2501 | } else { |
| 2502 | error = nfs_bdi_register(server); |
| 2503 | if (error) |
| 2504 | goto error_splat_super; |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 2505 | } |
| 2506 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2507 | if (!s->s_root) { |
| 2508 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2509 | nfs4_fill_super(s); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2510 | nfs_fscache_get_super_cookie(s, data); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2511 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2512 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2513 | mntroot = nfs4_get_root(s, mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2514 | if (IS_ERR(mntroot)) { |
| 2515 | error = PTR_ERR(mntroot); |
| 2516 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2517 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2518 | |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2519 | error = security_sb_set_mnt_opts(s, &data->lsm_opts); |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2520 | if (error) |
| 2521 | goto error_splat_root; |
| 2522 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2523 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2524 | mnt->mnt_sb = s; |
| 2525 | mnt->mnt_root = mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2526 | error = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2527 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2528 | out: |
Trond Myklebust | 33852a1 | 2008-06-19 14:20:11 -0400 | [diff] [blame] | 2529 | security_free_mnt_opts(&data->lsm_opts); |
| 2530 | out_free_fh: |
| 2531 | kfree(mntfh); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 2532 | return error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2533 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2534 | out_free: |
| 2535 | nfs_free_server(server); |
| 2536 | goto out; |
| 2537 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2538 | error_splat_root: |
| 2539 | dput(mntroot); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2540 | error_splat_super: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2541 | deactivate_locked_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 2542 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2543 | } |
| 2544 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2545 | static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type, |
| 2546 | int flags, void *data, const char *hostname) |
| 2547 | { |
| 2548 | struct vfsmount *root_mnt; |
| 2549 | char *root_devname; |
| 2550 | size_t len; |
| 2551 | |
| 2552 | len = strlen(hostname) + 3; |
| 2553 | root_devname = kmalloc(len, GFP_KERNEL); |
| 2554 | if (root_devname == NULL) |
| 2555 | return ERR_PTR(-ENOMEM); |
| 2556 | snprintf(root_devname, len, "%s:/", hostname); |
| 2557 | root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data); |
| 2558 | kfree(root_devname); |
| 2559 | return root_mnt; |
| 2560 | } |
| 2561 | |
Trond Myklebust | b88f8a5 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2562 | static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt) |
| 2563 | { |
| 2564 | char *page = (char *) __get_free_page(GFP_KERNEL); |
| 2565 | char *devname, *tmp; |
| 2566 | |
| 2567 | if (page == NULL) |
| 2568 | return; |
| 2569 | devname = nfs_path(path->mnt->mnt_devname, |
| 2570 | path->mnt->mnt_root, path->dentry, |
| 2571 | page, PAGE_SIZE); |
| 2572 | if (devname == NULL) |
| 2573 | goto out_freepage; |
| 2574 | tmp = kstrdup(devname, GFP_KERNEL); |
| 2575 | if (tmp == NULL) |
| 2576 | goto out_freepage; |
| 2577 | kfree(mnt->mnt_devname); |
| 2578 | mnt->mnt_devname = tmp; |
| 2579 | out_freepage: |
| 2580 | free_page((unsigned long)page); |
| 2581 | } |
| 2582 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2583 | static int nfs_follow_remote_path(struct vfsmount *root_mnt, |
| 2584 | const char *export_path, struct vfsmount *mnt_target) |
| 2585 | { |
| 2586 | struct mnt_namespace *ns_private; |
| 2587 | struct nameidata nd; |
| 2588 | struct super_block *s; |
| 2589 | int ret; |
| 2590 | |
| 2591 | ns_private = create_mnt_ns(root_mnt); |
| 2592 | ret = PTR_ERR(ns_private); |
| 2593 | if (IS_ERR(ns_private)) |
| 2594 | goto out_mntput; |
| 2595 | |
| 2596 | ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, |
| 2597 | export_path, LOOKUP_FOLLOW, &nd); |
| 2598 | |
| 2599 | put_mnt_ns(ns_private); |
| 2600 | |
| 2601 | if (ret != 0) |
| 2602 | goto out_err; |
| 2603 | |
| 2604 | s = nd.path.mnt->mnt_sb; |
| 2605 | atomic_inc(&s->s_active); |
| 2606 | mnt_target->mnt_sb = s; |
| 2607 | mnt_target->mnt_root = dget(nd.path.dentry); |
| 2608 | |
Trond Myklebust | b88f8a5 | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2609 | /* Correct the device pathname */ |
| 2610 | nfs_fix_devname(&nd.path, mnt_target); |
| 2611 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2612 | path_put(&nd.path); |
| 2613 | down_write(&s->s_umount); |
| 2614 | return 0; |
| 2615 | out_mntput: |
| 2616 | mntput(root_mnt); |
| 2617 | out_err: |
| 2618 | return ret; |
| 2619 | } |
| 2620 | |
| 2621 | /* |
| 2622 | * Get the superblock for an NFS4 mountpoint |
| 2623 | */ |
| 2624 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 2625 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 2626 | { |
| 2627 | struct nfs_parsed_mount_data *data; |
| 2628 | char *export_path; |
| 2629 | struct vfsmount *root_mnt; |
| 2630 | int error = -ENOMEM; |
| 2631 | |
| 2632 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2633 | if (data == NULL) |
| 2634 | goto out_free_data; |
| 2635 | |
| 2636 | /* Validate the mount data */ |
| 2637 | error = nfs4_validate_mount_data(raw_data, data, dev_name); |
| 2638 | if (error < 0) |
| 2639 | goto out; |
| 2640 | |
| 2641 | export_path = data->nfs_server.export_path; |
| 2642 | data->nfs_server.export_path = "/"; |
| 2643 | root_mnt = nfs_do_root_mount(&nfs4_remote_fs_type, flags, data, |
| 2644 | data->nfs_server.hostname); |
| 2645 | data->nfs_server.export_path = export_path; |
| 2646 | |
| 2647 | error = PTR_ERR(root_mnt); |
| 2648 | if (IS_ERR(root_mnt)) |
| 2649 | goto out; |
| 2650 | |
| 2651 | error = nfs_follow_remote_path(root_mnt, export_path, mnt); |
| 2652 | |
| 2653 | out: |
| 2654 | kfree(data->client_address); |
| 2655 | kfree(data->nfs_server.export_path); |
| 2656 | kfree(data->nfs_server.hostname); |
| 2657 | kfree(data->fscache_uniq); |
| 2658 | out_free_data: |
| 2659 | kfree(data); |
| 2660 | dprintk("<-- nfs4_get_sb() = %d%s\n", error, |
| 2661 | error != 0 ? " [error]" : ""); |
| 2662 | return error; |
| 2663 | } |
| 2664 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2665 | static void nfs4_kill_super(struct super_block *sb) |
| 2666 | { |
| 2667 | struct nfs_server *server = NFS_SB(sb); |
| 2668 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 2669 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 515d861 | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2670 | nfs_super_return_all_delegations(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2671 | kill_anon_super(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2672 | nfs4_renewd_prepare_shutdown(server); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 2673 | nfs_fscache_release_super_cookie(sb); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2674 | nfs_free_server(server); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 2675 | dprintk("<-- %s\n", __func__); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2679 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2680 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2681 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 2682 | const char *dev_name, void *raw_data, |
| 2683 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2684 | { |
| 2685 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2686 | struct super_block *s; |
| 2687 | struct nfs_server *server; |
| 2688 | struct dentry *mntroot; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2689 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2690 | struct nfs_sb_mountdata sb_mntdata = { |
| 2691 | .mntflags = flags, |
| 2692 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2693 | int error; |
| 2694 | |
| 2695 | dprintk("--> nfs4_xdev_get_sb()\n"); |
| 2696 | |
| 2697 | /* create a new volume representation */ |
| 2698 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 2699 | if (IS_ERR(server)) { |
| 2700 | error = PTR_ERR(server); |
| 2701 | goto out_err_noserver; |
| 2702 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2703 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2704 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2705 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2706 | compare_super = NULL; |
| 2707 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2708 | /* 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] | 2709 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2710 | if (IS_ERR(s)) { |
| 2711 | error = PTR_ERR(s); |
| 2712 | goto out_err_nosb; |
| 2713 | } |
| 2714 | |
| 2715 | if (s->s_fs_info != server) { |
| 2716 | nfs_free_server(server); |
| 2717 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2718 | } else { |
| 2719 | error = nfs_bdi_register(server); |
| 2720 | if (error) |
| 2721 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | if (!s->s_root) { |
| 2725 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2726 | nfs4_clone_super(s, data->sb); |
| 2727 | } |
| 2728 | |
| 2729 | mntroot = nfs4_get_root(s, data->fh); |
| 2730 | if (IS_ERR(mntroot)) { |
| 2731 | error = PTR_ERR(mntroot); |
| 2732 | goto error_splat_super; |
| 2733 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2734 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2735 | dput(mntroot); |
| 2736 | error = -ESTALE; |
| 2737 | goto error_splat_super; |
| 2738 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2739 | |
| 2740 | s->s_flags |= MS_ACTIVE; |
| 2741 | mnt->mnt_sb = s; |
| 2742 | mnt->mnt_root = mntroot; |
| 2743 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2744 | security_sb_clone_mnt_opts(data->sb, s); |
| 2745 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2746 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); |
| 2747 | return 0; |
| 2748 | |
| 2749 | out_err_nosb: |
| 2750 | nfs_free_server(server); |
| 2751 | out_err_noserver: |
| 2752 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); |
| 2753 | return error; |
| 2754 | |
| 2755 | error_splat_super: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2756 | deactivate_locked_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2757 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
| 2758 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2759 | } |
| 2760 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2761 | static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type, |
| 2762 | int flags, const char *dev_name, void *raw_data, |
| 2763 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2764 | { |
| 2765 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2766 | struct super_block *s; |
| 2767 | struct nfs_server *server; |
| 2768 | struct dentry *mntroot; |
| 2769 | struct nfs_fh mntfh; |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2770 | int (*compare_super)(struct super_block *, void *) = nfs_compare_super; |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2771 | struct nfs_sb_mountdata sb_mntdata = { |
| 2772 | .mntflags = flags, |
| 2773 | }; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2774 | int error; |
| 2775 | |
| 2776 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2777 | |
| 2778 | /* create a new volume representation */ |
| 2779 | server = nfs4_create_referral_server(data, &mntfh); |
| 2780 | if (IS_ERR(server)) { |
| 2781 | error = PTR_ERR(server); |
| 2782 | goto out_err_noserver; |
| 2783 | } |
Trond Myklebust | e89a5a4 | 2007-08-31 10:45:17 -0400 | [diff] [blame] | 2784 | sb_mntdata.server = server; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2785 | |
Trond Myklebust | 75180df | 2007-05-16 16:53:28 -0400 | [diff] [blame] | 2786 | if (server->flags & NFS4_MOUNT_UNSHARED) |
| 2787 | compare_super = NULL; |
| 2788 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2789 | /* 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] | 2790 | s = sget(&nfs4_fs_type, compare_super, nfs_set_super, &sb_mntdata); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2791 | if (IS_ERR(s)) { |
| 2792 | error = PTR_ERR(s); |
| 2793 | goto out_err_nosb; |
| 2794 | } |
| 2795 | |
| 2796 | if (s->s_fs_info != server) { |
| 2797 | nfs_free_server(server); |
| 2798 | server = NULL; |
Miklos Szeredi | fa79975 | 2008-04-30 00:54:33 -0700 | [diff] [blame] | 2799 | } else { |
| 2800 | error = nfs_bdi_register(server); |
| 2801 | if (error) |
| 2802 | goto error_splat_super; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | if (!s->s_root) { |
| 2806 | /* initial superblock/root creation */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2807 | nfs4_fill_super(s); |
| 2808 | } |
| 2809 | |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 2810 | mntroot = nfs4_get_root(s, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2811 | if (IS_ERR(mntroot)) { |
| 2812 | error = PTR_ERR(mntroot); |
| 2813 | goto error_splat_super; |
| 2814 | } |
Trond Myklebust | e9cc6c2 | 2008-01-02 13:28:57 -0500 | [diff] [blame] | 2815 | if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) { |
| 2816 | dput(mntroot); |
| 2817 | error = -ESTALE; |
| 2818 | goto error_splat_super; |
| 2819 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2820 | |
| 2821 | s->s_flags |= MS_ACTIVE; |
| 2822 | mnt->mnt_sb = s; |
| 2823 | mnt->mnt_root = mntroot; |
| 2824 | |
Eric Paris | 46c8ac7 | 2008-05-02 13:42:42 -0700 | [diff] [blame] | 2825 | security_sb_clone_mnt_opts(data->sb, s); |
| 2826 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2827 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
| 2828 | return 0; |
| 2829 | |
| 2830 | out_err_nosb: |
| 2831 | nfs_free_server(server); |
| 2832 | out_err_noserver: |
| 2833 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
| 2834 | return error; |
| 2835 | |
| 2836 | error_splat_super: |
Al Viro | 6f5bbff | 2009-05-06 01:34:22 -0400 | [diff] [blame] | 2837 | deactivate_locked_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2838 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
| 2839 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 2840 | } |
| 2841 | |
Trond Myklebust | c02d7ad | 2009-06-22 15:09:14 -0400 | [diff] [blame] | 2842 | /* |
| 2843 | * Create an NFS4 server record on referral traversal |
| 2844 | */ |
| 2845 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, |
| 2846 | int flags, const char *dev_name, void *raw_data, |
| 2847 | struct vfsmount *mnt) |
| 2848 | { |
| 2849 | struct nfs_clone_mount *data = raw_data; |
| 2850 | char *export_path; |
| 2851 | struct vfsmount *root_mnt; |
| 2852 | int error; |
| 2853 | |
| 2854 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 2855 | |
| 2856 | export_path = data->mnt_path; |
| 2857 | data->mnt_path = "/"; |
| 2858 | |
| 2859 | root_mnt = nfs_do_root_mount(&nfs4_remote_referral_fs_type, |
| 2860 | flags, data, data->hostname); |
| 2861 | data->mnt_path = export_path; |
| 2862 | |
| 2863 | error = PTR_ERR(root_mnt); |
| 2864 | if (IS_ERR(root_mnt)) |
| 2865 | goto out; |
| 2866 | |
| 2867 | error = nfs_follow_remote_path(root_mnt, export_path, mnt); |
| 2868 | out: |
| 2869 | dprintk("<-- nfs4_referral_get_sb() = %d%s\n", error, |
| 2870 | error != 0 ? " [error]" : ""); |
| 2871 | return error; |
| 2872 | } |
| 2873 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2874 | #endif /* CONFIG_NFS_V4 */ |