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