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> |
| 36 | #include <linux/nfs_fs.h> |
| 37 | #include <linux/nfs_mount.h> |
| 38 | #include <linux/nfs4_mount.h> |
| 39 | #include <linux/lockd/bind.h> |
| 40 | #include <linux/smp_lock.h> |
| 41 | #include <linux/seq_file.h> |
| 42 | #include <linux/mount.h> |
| 43 | #include <linux/nfs_idmap.h> |
| 44 | #include <linux/vfs.h> |
| 45 | #include <linux/inet.h> |
| 46 | #include <linux/nfs_xdr.h> |
Adrian Bunk | b5d5dfb | 2007-02-12 00:53:40 -0800 | [diff] [blame] | 47 | #include <linux/magic.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 48 | |
| 49 | #include <asm/system.h> |
| 50 | #include <asm/uaccess.h> |
| 51 | |
| 52 | #include "nfs4_fs.h" |
| 53 | #include "callback.h" |
| 54 | #include "delegation.h" |
| 55 | #include "iostat.h" |
| 56 | #include "internal.h" |
| 57 | |
| 58 | #define NFSDBG_FACILITY NFSDBG_VFS |
| 59 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 60 | static void nfs_umount_begin(struct vfsmount *, int); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 61 | static int nfs_statfs(struct dentry *, struct kstatfs *); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 62 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
| 63 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 64 | 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] | 65 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 66 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 67 | static void nfs_kill_super(struct super_block *); |
| 68 | |
| 69 | static struct file_system_type nfs_fs_type = { |
| 70 | .owner = THIS_MODULE, |
| 71 | .name = "nfs", |
| 72 | .get_sb = nfs_get_sb, |
| 73 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 74 | .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] | 75 | }; |
| 76 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 77 | struct file_system_type nfs_xdev_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 78 | .owner = THIS_MODULE, |
| 79 | .name = "nfs", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 80 | .get_sb = nfs_xdev_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 81 | .kill_sb = nfs_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 82 | .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] | 83 | }; |
| 84 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 85 | static const struct super_operations nfs_sops = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 86 | .alloc_inode = nfs_alloc_inode, |
| 87 | .destroy_inode = nfs_destroy_inode, |
| 88 | .write_inode = nfs_write_inode, |
| 89 | .statfs = nfs_statfs, |
| 90 | .clear_inode = nfs_clear_inode, |
| 91 | .umount_begin = nfs_umount_begin, |
| 92 | .show_options = nfs_show_options, |
| 93 | .show_stats = nfs_show_stats, |
| 94 | }; |
| 95 | |
| 96 | #ifdef CONFIG_NFS_V4 |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 97 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 98 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 99 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, |
| 100 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
| 101 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, |
| 102 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 103 | static void nfs4_kill_super(struct super_block *sb); |
| 104 | |
| 105 | static struct file_system_type nfs4_fs_type = { |
| 106 | .owner = THIS_MODULE, |
| 107 | .name = "nfs4", |
| 108 | .get_sb = nfs4_get_sb, |
| 109 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 110 | .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] | 111 | }; |
| 112 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 113 | struct file_system_type nfs4_xdev_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 114 | .owner = THIS_MODULE, |
| 115 | .name = "nfs4", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 116 | .get_sb = nfs4_xdev_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 117 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 118 | .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] | 119 | }; |
| 120 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 121 | struct file_system_type nfs4_referral_fs_type = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 122 | .owner = THIS_MODULE, |
| 123 | .name = "nfs4", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 124 | .get_sb = nfs4_referral_get_sb, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 125 | .kill_sb = nfs4_kill_super, |
Mark Fasheh | 349457c | 2006-09-08 14:22:21 -0700 | [diff] [blame] | 126 | .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] | 127 | }; |
| 128 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 129 | static const struct super_operations nfs4_sops = { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 130 | .alloc_inode = nfs_alloc_inode, |
| 131 | .destroy_inode = nfs_destroy_inode, |
| 132 | .write_inode = nfs_write_inode, |
| 133 | .statfs = nfs_statfs, |
| 134 | .clear_inode = nfs4_clear_inode, |
| 135 | .umount_begin = nfs_umount_begin, |
| 136 | .show_options = nfs_show_options, |
| 137 | .show_stats = nfs_show_stats, |
| 138 | }; |
| 139 | #endif |
| 140 | |
Trond Myklebust | 979df72 | 2006-07-25 11:28:19 -0400 | [diff] [blame] | 141 | static struct shrinker *acl_shrinker; |
| 142 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 143 | /* |
| 144 | * Register the NFS filesystems |
| 145 | */ |
| 146 | int __init register_nfs_fs(void) |
| 147 | { |
| 148 | int ret; |
| 149 | |
| 150 | ret = register_filesystem(&nfs_fs_type); |
| 151 | if (ret < 0) |
| 152 | goto error_0; |
| 153 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 154 | ret = nfs_register_sysctl(); |
| 155 | if (ret < 0) |
| 156 | goto error_1; |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 157 | #ifdef CONFIG_NFS_V4 |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 158 | ret = register_filesystem(&nfs4_fs_type); |
| 159 | if (ret < 0) |
| 160 | goto error_2; |
| 161 | #endif |
Trond Myklebust | 979df72 | 2006-07-25 11:28:19 -0400 | [diff] [blame] | 162 | acl_shrinker = set_shrinker(DEFAULT_SEEKS, nfs_access_cache_shrinker); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 163 | return 0; |
| 164 | |
| 165 | #ifdef CONFIG_NFS_V4 |
| 166 | error_2: |
| 167 | nfs_unregister_sysctl(); |
Peter Zijlstra | 89a0914 | 2007-03-16 13:38:26 -0800 | [diff] [blame] | 168 | #endif |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 169 | error_1: |
| 170 | unregister_filesystem(&nfs_fs_type); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 171 | error_0: |
| 172 | return ret; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * Unregister the NFS filesystems |
| 177 | */ |
| 178 | void __exit unregister_nfs_fs(void) |
| 179 | { |
Trond Myklebust | 979df72 | 2006-07-25 11:28:19 -0400 | [diff] [blame] | 180 | if (acl_shrinker != NULL) |
| 181 | remove_shrinker(acl_shrinker); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 182 | #ifdef CONFIG_NFS_V4 |
| 183 | unregister_filesystem(&nfs4_fs_type); |
| 184 | nfs_unregister_sysctl(); |
| 185 | #endif |
| 186 | unregister_filesystem(&nfs_fs_type); |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * Deliver file system statistics to userspace |
| 191 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 192 | static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 193 | { |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 194 | struct nfs_server *server = NFS_SB(dentry->d_sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 195 | unsigned char blockbits; |
| 196 | unsigned long blockres; |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 197 | struct nfs_fh *fh = NFS_FH(dentry->d_inode); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 198 | struct nfs_fattr fattr; |
| 199 | struct nfs_fsstat res = { |
| 200 | .fattr = &fattr, |
| 201 | }; |
| 202 | int error; |
| 203 | |
| 204 | lock_kernel(); |
| 205 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 206 | error = server->nfs_client->rpc_ops->statfs(server, fh, &res); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 207 | if (error < 0) |
| 208 | goto out_err; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 209 | buf->f_type = NFS_SUPER_MAGIC; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * Current versions of glibc do not correctly handle the |
| 213 | * case where f_frsize != f_bsize. Eventually we want to |
| 214 | * report the value of wtmult in this field. |
| 215 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 216 | buf->f_frsize = dentry->d_sb->s_blocksize; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * On most *nix systems, f_blocks, f_bfree, and f_bavail |
| 220 | * are reported in units of f_frsize. Linux hasn't had |
| 221 | * an f_frsize field in its statfs struct until recently, |
| 222 | * thus historically Linux's sys_statfs reports these |
| 223 | * fields in units of f_bsize. |
| 224 | */ |
David Howells | 0c7d90c | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 225 | buf->f_bsize = dentry->d_sb->s_blocksize; |
| 226 | blockbits = dentry->d_sb->s_blocksize_bits; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 227 | blockres = (1 << blockbits) - 1; |
| 228 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; |
| 229 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; |
| 230 | buf->f_bavail = (res.abytes + blockres) >> blockbits; |
| 231 | |
| 232 | buf->f_files = res.tfiles; |
| 233 | buf->f_ffree = res.afiles; |
| 234 | |
| 235 | buf->f_namelen = server->namelen; |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 236 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 237 | unlock_kernel(); |
| 238 | return 0; |
| 239 | |
| 240 | out_err: |
| 241 | dprintk("%s: statfs error = %d\n", __FUNCTION__, -error); |
Amnon Aaronsohn | 1a0ba9a | 2007-04-09 22:05:26 -0700 | [diff] [blame] | 242 | unlock_kernel(); |
| 243 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 244 | } |
| 245 | |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 246 | /* |
| 247 | * Map the security flavour number to a name |
| 248 | */ |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 249 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) |
| 250 | { |
David Howells | 7d4e274 | 2006-08-22 20:06:07 -0400 | [diff] [blame] | 251 | static const struct { |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 252 | rpc_authflavor_t flavour; |
| 253 | const char *str; |
| 254 | } sec_flavours[] = { |
| 255 | { RPC_AUTH_NULL, "null" }, |
| 256 | { RPC_AUTH_UNIX, "sys" }, |
| 257 | { RPC_AUTH_GSS_KRB5, "krb5" }, |
| 258 | { RPC_AUTH_GSS_KRB5I, "krb5i" }, |
| 259 | { RPC_AUTH_GSS_KRB5P, "krb5p" }, |
| 260 | { RPC_AUTH_GSS_LKEY, "lkey" }, |
| 261 | { RPC_AUTH_GSS_LKEYI, "lkeyi" }, |
| 262 | { RPC_AUTH_GSS_LKEYP, "lkeyp" }, |
| 263 | { RPC_AUTH_GSS_SPKM, "spkm" }, |
| 264 | { RPC_AUTH_GSS_SPKMI, "spkmi" }, |
| 265 | { RPC_AUTH_GSS_SPKMP, "spkmp" }, |
| 266 | { -1, "unknown" } |
| 267 | }; |
| 268 | int i; |
| 269 | |
| 270 | for (i=0; sec_flavours[i].flavour != -1; i++) { |
| 271 | if (sec_flavours[i].flavour == flavour) |
| 272 | break; |
| 273 | } |
| 274 | return sec_flavours[i].str; |
| 275 | } |
| 276 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 277 | /* |
| 278 | * Describe the mount options in force on this server representation |
| 279 | */ |
| 280 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) |
| 281 | { |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 282 | static const struct proc_nfs_info { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 283 | int flag; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 284 | const char *str; |
| 285 | const char *nostr; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 286 | } nfs_info[] = { |
| 287 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
| 288 | { NFS_MOUNT_INTR, ",intr", "" }, |
| 289 | { NFS_MOUNT_NOCTO, ",nocto", "" }, |
| 290 | { NFS_MOUNT_NOAC, ",noac", "" }, |
| 291 | { NFS_MOUNT_NONLM, ",nolock", "" }, |
| 292 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
Steve Dickson | 74dd34e | 2007-04-14 17:01:15 -0400 | [diff] [blame] | 293 | { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 294 | { 0, NULL, NULL } |
| 295 | }; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 296 | const struct proc_nfs_info *nfs_infop; |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 297 | struct nfs_client *clp = nfss->nfs_client; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 298 | char buf[12]; |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 299 | const char *proto; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 300 | |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 301 | seq_printf(m, ",vers=%d", clp->rpc_ops->version); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 302 | seq_printf(m, ",rsize=%d", nfss->rsize); |
| 303 | seq_printf(m, ",wsize=%d", nfss->wsize); |
| 304 | if (nfss->acregmin != 3*HZ || showdefaults) |
| 305 | seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ); |
| 306 | if (nfss->acregmax != 60*HZ || showdefaults) |
| 307 | seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ); |
| 308 | if (nfss->acdirmin != 30*HZ || showdefaults) |
| 309 | seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ); |
| 310 | if (nfss->acdirmax != 60*HZ || showdefaults) |
| 311 | seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ); |
| 312 | for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { |
| 313 | if (nfss->flags & nfs_infop->flag) |
| 314 | seq_puts(m, nfs_infop->str); |
| 315 | else |
| 316 | seq_puts(m, nfs_infop->nostr); |
| 317 | } |
| 318 | switch (nfss->client->cl_xprt->prot) { |
| 319 | case IPPROTO_TCP: |
| 320 | proto = "tcp"; |
| 321 | break; |
| 322 | case IPPROTO_UDP: |
| 323 | proto = "udp"; |
| 324 | break; |
| 325 | default: |
| 326 | snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot); |
| 327 | proto = buf; |
| 328 | } |
| 329 | seq_printf(m, ",proto=%s", proto); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 330 | seq_printf(m, ",timeo=%lu", 10U * clp->retrans_timeo / HZ); |
| 331 | seq_printf(m, ",retrans=%u", clp->retrans_count); |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame] | 332 | seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor)); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Describe the mount options on this VFS mountpoint |
| 337 | */ |
| 338 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 339 | { |
| 340 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 341 | |
| 342 | nfs_show_mount_options(m, nfss, 0); |
| 343 | |
| 344 | seq_puts(m, ",addr="); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 345 | seq_escape(m, nfss->nfs_client->cl_hostname, " \t\n\\"); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Present statistical information for this VFS mountpoint |
| 352 | */ |
| 353 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 354 | { |
| 355 | int i, cpu; |
| 356 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 357 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 358 | struct nfs_iostats totals = { }; |
| 359 | |
| 360 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 361 | |
| 362 | /* |
| 363 | * Display all mount option settings |
| 364 | */ |
| 365 | seq_printf(m, "\n\topts:\t"); |
| 366 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 367 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 368 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 369 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 370 | nfs_show_mount_options(m, nfss, 1); |
| 371 | |
| 372 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 373 | |
| 374 | seq_printf(m, "\n\tcaps:\t"); |
| 375 | seq_printf(m, "caps=0x%x", nfss->caps); |
| 376 | seq_printf(m, ",wtmult=%d", nfss->wtmult); |
| 377 | seq_printf(m, ",dtsize=%d", nfss->dtsize); |
| 378 | seq_printf(m, ",bsize=%d", nfss->bsize); |
| 379 | seq_printf(m, ",namelen=%d", nfss->namelen); |
| 380 | |
| 381 | #ifdef CONFIG_NFS_V4 |
David Howells | 8fa5c00 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 382 | if (nfss->nfs_client->cl_nfsversion == 4) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 383 | seq_printf(m, "\n\tnfsv4:\t"); |
| 384 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 385 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 386 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 387 | } |
| 388 | #endif |
| 389 | |
| 390 | /* |
| 391 | * Display security flavor in effect for this mount |
| 392 | */ |
| 393 | seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor); |
| 394 | if (auth->au_flavor) |
| 395 | seq_printf(m, ",pseudoflavor=%d", auth->au_flavor); |
| 396 | |
| 397 | /* |
| 398 | * Display superblock I/O counters |
| 399 | */ |
| 400 | for_each_possible_cpu(cpu) { |
| 401 | struct nfs_iostats *stats; |
| 402 | |
| 403 | preempt_disable(); |
| 404 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 405 | |
| 406 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 407 | totals.events[i] += stats->events[i]; |
| 408 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 409 | totals.bytes[i] += stats->bytes[i]; |
| 410 | |
| 411 | preempt_enable(); |
| 412 | } |
| 413 | |
| 414 | seq_printf(m, "\n\tevents:\t"); |
| 415 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 416 | seq_printf(m, "%lu ", totals.events[i]); |
| 417 | seq_printf(m, "\n\tbytes:\t"); |
| 418 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 419 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 420 | seq_printf(m, "\n"); |
| 421 | |
| 422 | rpc_print_iostats(m, nfss->client); |
| 423 | |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * Begin unmount by attempting to remove all automounted mountpoints we added |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 429 | * in response to xdev traversals and referrals |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 430 | */ |
| 431 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) |
| 432 | { |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 433 | struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb); |
| 434 | struct rpc_clnt *rpc; |
| 435 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 436 | shrink_submounts(vfsmnt, &nfs_automount_list); |
Trond Myklebust | fc6ae3c | 2007-06-05 19:13:47 -0400 | [diff] [blame] | 437 | |
| 438 | if (!(flags & MNT_FORCE)) |
| 439 | return; |
| 440 | /* -EIO all pending I/O */ |
| 441 | rpc = server->client_acl; |
| 442 | if (!IS_ERR(rpc)) |
| 443 | rpc_killall_tasks(rpc); |
| 444 | rpc = server->client; |
| 445 | if (!IS_ERR(rpc)) |
| 446 | rpc_killall_tasks(rpc); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 450 | * Validate the NFS2/NFS3 mount data |
| 451 | * - fills in the mount root filehandle |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 452 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 453 | static int nfs_validate_mount_data(struct nfs_mount_data *data, |
| 454 | struct nfs_fh *mntfh) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 455 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 456 | if (data == NULL) { |
| 457 | dprintk("%s: missing data argument\n", __FUNCTION__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 458 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 459 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 460 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 461 | if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) { |
| 462 | dprintk("%s: bad mount version\n", __FUNCTION__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 463 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 464 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 465 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 466 | switch (data->version) { |
| 467 | case 1: |
| 468 | data->namlen = 0; |
| 469 | case 2: |
| 470 | data->bsize = 0; |
| 471 | case 3: |
| 472 | if (data->flags & NFS_MOUNT_VER3) { |
| 473 | dprintk("%s: mount structure version %d does not support NFSv3\n", |
| 474 | __FUNCTION__, |
| 475 | data->version); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 476 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 477 | } |
| 478 | data->root.size = NFS2_FHSIZE; |
| 479 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 480 | case 4: |
| 481 | if (data->flags & NFS_MOUNT_SECFLAVOUR) { |
| 482 | dprintk("%s: mount structure version %d does not support strong security\n", |
| 483 | __FUNCTION__, |
| 484 | data->version); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 485 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 486 | } |
| 487 | case 5: |
| 488 | memset(data->context, 0, sizeof(data->context)); |
| 489 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 490 | |
Trond Myklebust | 36b15c5 | 2006-08-22 20:06:14 -0400 | [diff] [blame] | 491 | /* Set the pseudoflavor */ |
| 492 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) |
| 493 | data->pseudoflavor = RPC_AUTH_UNIX; |
| 494 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 495 | #ifndef CONFIG_NFS_V3 |
| 496 | /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 497 | if (data->flags & NFS_MOUNT_VER3) { |
| 498 | dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 499 | return -EPROTONOSUPPORT; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 500 | } |
| 501 | #endif /* CONFIG_NFS_V3 */ |
| 502 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 503 | /* We now require that the mount process passes the remote address */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 504 | if (data->addr.sin_addr.s_addr == INADDR_ANY) { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 505 | dprintk("%s: mount program didn't pass remote address!\n", |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 506 | __FUNCTION__); |
| 507 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 508 | } |
| 509 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 510 | /* Prepare the root filehandle */ |
| 511 | if (data->flags & NFS_MOUNT_VER3) |
| 512 | mntfh->size = data->root.size; |
| 513 | else |
| 514 | mntfh->size = NFS2_FHSIZE; |
| 515 | |
| 516 | if (mntfh->size > sizeof(mntfh->data)) { |
| 517 | dprintk("%s: invalid root filehandle\n", __FUNCTION__); |
| 518 | return -EINVAL; |
| 519 | } |
| 520 | |
| 521 | memcpy(mntfh->data, data->root.data, mntfh->size); |
| 522 | if (mntfh->size < sizeof(mntfh->data)) |
| 523 | memset(mntfh->data + mntfh->size, 0, |
| 524 | sizeof(mntfh->data) - mntfh->size); |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * Initialise the common bits of the superblock |
| 531 | */ |
| 532 | static inline void nfs_initialise_sb(struct super_block *sb) |
| 533 | { |
| 534 | struct nfs_server *server = NFS_SB(sb); |
| 535 | |
| 536 | sb->s_magic = NFS_SUPER_MAGIC; |
| 537 | |
| 538 | /* We probably want something more informative here */ |
| 539 | snprintf(sb->s_id, sizeof(sb->s_id), |
| 540 | "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 541 | |
| 542 | if (sb->s_blocksize == 0) |
| 543 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 544 | &sb->s_blocksize_bits); |
| 545 | |
| 546 | if (server->flags & NFS_MOUNT_NOAC) |
| 547 | sb->s_flags |= MS_SYNCHRONOUS; |
| 548 | |
| 549 | nfs_super_set_maxbytes(sb, server->maxfilesize); |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * Finish setting up an NFS2/3 superblock |
| 554 | */ |
| 555 | static void nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data) |
| 556 | { |
| 557 | struct nfs_server *server = NFS_SB(sb); |
| 558 | |
| 559 | sb->s_blocksize_bits = 0; |
| 560 | sb->s_blocksize = 0; |
| 561 | if (data->bsize) |
| 562 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 563 | |
| 564 | if (server->flags & NFS_MOUNT_VER3) { |
| 565 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 566 | * so ourselves when necessary. |
| 567 | */ |
| 568 | sb->s_flags |= MS_POSIXACL; |
| 569 | sb->s_time_gran = 1; |
| 570 | } |
| 571 | |
| 572 | sb->s_op = &nfs_sops; |
| 573 | nfs_initialise_sb(sb); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Finish setting up a cloned NFS2/3 superblock |
| 578 | */ |
| 579 | static void nfs_clone_super(struct super_block *sb, |
| 580 | const struct super_block *old_sb) |
| 581 | { |
| 582 | struct nfs_server *server = NFS_SB(sb); |
| 583 | |
| 584 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 585 | sb->s_blocksize = old_sb->s_blocksize; |
| 586 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 587 | |
| 588 | if (server->flags & NFS_MOUNT_VER3) { |
| 589 | /* The VFS shouldn't apply the umask to mode bits. We will do |
| 590 | * so ourselves when necessary. |
| 591 | */ |
| 592 | sb->s_flags |= MS_POSIXACL; |
| 593 | sb->s_time_gran = 1; |
| 594 | } |
| 595 | |
| 596 | sb->s_op = old_sb->s_op; |
| 597 | nfs_initialise_sb(sb); |
| 598 | } |
| 599 | |
| 600 | static int nfs_set_super(struct super_block *s, void *_server) |
| 601 | { |
| 602 | struct nfs_server *server = _server; |
| 603 | int ret; |
| 604 | |
| 605 | s->s_fs_info = server; |
| 606 | ret = set_anon_super(s, server); |
| 607 | if (ret == 0) |
| 608 | server->s_dev = s->s_dev; |
| 609 | return ret; |
| 610 | } |
| 611 | |
| 612 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 613 | { |
| 614 | struct nfs_server *server = data, *old = NFS_SB(sb); |
| 615 | |
| 616 | if (old->nfs_client != server->nfs_client) |
| 617 | return 0; |
| 618 | if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0) |
| 619 | return 0; |
| 620 | return 1; |
| 621 | } |
| 622 | |
| 623 | static int nfs_get_sb(struct file_system_type *fs_type, |
| 624 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
| 625 | { |
| 626 | struct nfs_server *server = NULL; |
| 627 | struct super_block *s; |
| 628 | struct nfs_fh mntfh; |
| 629 | struct nfs_mount_data *data = raw_data; |
| 630 | struct dentry *mntroot; |
| 631 | int error; |
| 632 | |
| 633 | /* Validate the mount data */ |
| 634 | error = nfs_validate_mount_data(data, &mntfh); |
| 635 | if (error < 0) |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame^] | 636 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 637 | |
| 638 | /* Get a volume representation */ |
| 639 | server = nfs_create_server(data, &mntfh); |
| 640 | if (IS_ERR(server)) { |
| 641 | error = PTR_ERR(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame^] | 642 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* Get a superblock - note that we may end up sharing one that already exists */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 646 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 647 | if (IS_ERR(s)) { |
| 648 | error = PTR_ERR(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 649 | goto out_err_nosb; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 650 | } |
| 651 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 652 | if (s->s_fs_info != server) { |
| 653 | nfs_free_server(server); |
| 654 | server = NULL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 655 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 656 | |
| 657 | if (!s->s_root) { |
| 658 | /* initial superblock/root creation */ |
| 659 | s->s_flags = flags; |
| 660 | nfs_fill_super(s, data); |
| 661 | } |
| 662 | |
| 663 | mntroot = nfs_get_root(s, &mntfh); |
| 664 | if (IS_ERR(mntroot)) { |
| 665 | error = PTR_ERR(mntroot); |
| 666 | goto error_splat_super; |
| 667 | } |
| 668 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 669 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 670 | mnt->mnt_sb = s; |
| 671 | mnt->mnt_root = mntroot; |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame^] | 672 | error = 0; |
| 673 | |
| 674 | out: |
| 675 | return error; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 676 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 677 | out_err_nosb: |
| 678 | nfs_free_server(server); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame^] | 679 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 680 | |
| 681 | error_splat_super: |
| 682 | up_write(&s->s_umount); |
| 683 | deactivate_super(s); |
Chuck Lever | 0655960 | 2007-07-01 12:12:35 -0400 | [diff] [blame^] | 684 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 685 | } |
| 686 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 687 | /* |
| 688 | * Destroy an NFS2/3 superblock |
| 689 | */ |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 690 | static void nfs_kill_super(struct super_block *s) |
| 691 | { |
| 692 | struct nfs_server *server = NFS_SB(s); |
| 693 | |
| 694 | kill_anon_super(s); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 695 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 696 | } |
| 697 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 698 | /* |
| 699 | * Clone an NFS2/3 server record on xdev traversal (FSID-change) |
| 700 | */ |
| 701 | static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 702 | const char *dev_name, void *raw_data, |
| 703 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 704 | { |
| 705 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 706 | struct super_block *s; |
| 707 | struct nfs_server *server; |
| 708 | struct dentry *mntroot; |
| 709 | int error; |
| 710 | |
| 711 | dprintk("--> nfs_xdev_get_sb()\n"); |
| 712 | |
| 713 | /* create a new volume representation */ |
| 714 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 715 | if (IS_ERR(server)) { |
| 716 | error = PTR_ERR(server); |
| 717 | goto out_err_noserver; |
| 718 | } |
| 719 | |
| 720 | /* Get a superblock - note that we may end up sharing one that already exists */ |
| 721 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
| 722 | if (IS_ERR(s)) { |
| 723 | error = PTR_ERR(s); |
| 724 | goto out_err_nosb; |
| 725 | } |
| 726 | |
| 727 | if (s->s_fs_info != server) { |
| 728 | nfs_free_server(server); |
| 729 | server = NULL; |
| 730 | } |
| 731 | |
| 732 | if (!s->s_root) { |
| 733 | /* initial superblock/root creation */ |
| 734 | s->s_flags = flags; |
| 735 | nfs_clone_super(s, data->sb); |
| 736 | } |
| 737 | |
| 738 | mntroot = nfs_get_root(s, data->fh); |
| 739 | if (IS_ERR(mntroot)) { |
| 740 | error = PTR_ERR(mntroot); |
| 741 | goto error_splat_super; |
| 742 | } |
| 743 | |
| 744 | s->s_flags |= MS_ACTIVE; |
| 745 | mnt->mnt_sb = s; |
| 746 | mnt->mnt_root = mntroot; |
| 747 | |
| 748 | dprintk("<-- nfs_xdev_get_sb() = 0\n"); |
| 749 | return 0; |
| 750 | |
| 751 | out_err_nosb: |
| 752 | nfs_free_server(server); |
| 753 | out_err_noserver: |
| 754 | dprintk("<-- nfs_xdev_get_sb() = %d [error]\n", error); |
| 755 | return error; |
| 756 | |
| 757 | error_splat_super: |
| 758 | up_write(&s->s_umount); |
| 759 | deactivate_super(s); |
| 760 | dprintk("<-- nfs_xdev_get_sb() = %d [splat]\n", error); |
| 761 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | #ifdef CONFIG_NFS_V4 |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 765 | |
| 766 | /* |
| 767 | * Finish setting up a cloned NFS4 superblock |
| 768 | */ |
| 769 | static void nfs4_clone_super(struct super_block *sb, |
| 770 | const struct super_block *old_sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 771 | { |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 772 | sb->s_blocksize_bits = old_sb->s_blocksize_bits; |
| 773 | sb->s_blocksize = old_sb->s_blocksize; |
| 774 | sb->s_maxbytes = old_sb->s_maxbytes; |
| 775 | sb->s_time_gran = 1; |
| 776 | sb->s_op = old_sb->s_op; |
| 777 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /* |
| 781 | * Set up an NFS4 superblock |
| 782 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 783 | static void nfs4_fill_super(struct super_block *sb) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 784 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 785 | sb->s_time_gran = 1; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 786 | sb->s_op = &nfs4_sops; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 787 | nfs_initialise_sb(sb); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 788 | } |
| 789 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 790 | /* |
| 791 | * Get the superblock for an NFS4 mountpoint |
| 792 | */ |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 793 | static int nfs4_get_sb(struct file_system_type *fs_type, |
| 794 | int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 795 | { |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 796 | struct nfs4_mount_data *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 797 | struct super_block *s; |
| 798 | struct nfs_server *server; |
| 799 | struct sockaddr_in addr; |
| 800 | rpc_authflavor_t authflavour; |
| 801 | struct nfs_fh mntfh; |
| 802 | struct dentry *mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 803 | char *p, *mntpath = NULL, *hostname = NULL, *ip_addr = NULL; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 804 | int error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 805 | |
| 806 | if (data == NULL) { |
| 807 | dprintk("%s: missing data argument\n", __FUNCTION__); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 808 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 809 | } |
| 810 | if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) { |
| 811 | dprintk("%s: bad mount version\n", __FUNCTION__); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 812 | return -EINVAL; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 813 | } |
| 814 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 815 | /* We now require that the mount process passes the remote address */ |
| 816 | if (data->host_addrlen != sizeof(addr)) |
| 817 | return -EINVAL; |
| 818 | |
| 819 | if (copy_from_user(&addr, data->host_addr, sizeof(addr))) |
| 820 | return -EFAULT; |
| 821 | |
| 822 | if (addr.sin_family != AF_INET || |
| 823 | addr.sin_addr.s_addr == INADDR_ANY |
| 824 | ) { |
| 825 | dprintk("%s: mount program didn't pass remote IP address!\n", |
| 826 | __FUNCTION__); |
| 827 | return -EINVAL; |
| 828 | } |
Trond Myklebust | 51b6ded | 2006-09-15 16:31:56 -0400 | [diff] [blame] | 829 | /* RFC3530: The default port for NFS is 2049 */ |
| 830 | if (addr.sin_port == 0) |
Trond Myklebust | 575b5c7 | 2006-10-19 23:28:37 -0700 | [diff] [blame] | 831 | addr.sin_port = htons(NFS_PORT); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 832 | |
| 833 | /* Grab the authentication type */ |
| 834 | authflavour = RPC_AUTH_UNIX; |
| 835 | if (data->auth_flavourlen != 0) { |
| 836 | if (data->auth_flavourlen != 1) { |
| 837 | dprintk("%s: Invalid number of RPC auth flavours %d.\n", |
| 838 | __FUNCTION__, data->auth_flavourlen); |
| 839 | error = -EINVAL; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 840 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | if (copy_from_user(&authflavour, data->auth_flavours, |
| 844 | sizeof(authflavour))) { |
| 845 | error = -EFAULT; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 846 | goto out; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 847 | } |
| 848 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 849 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 850 | p = strndup_user(data->hostname.data, NFS4_MAXNAMLEN); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 851 | if (IS_ERR(p)) |
| 852 | goto out_err; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 853 | hostname = p; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 854 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 855 | p = strndup_user(data->mnt_path.data, NFS4_MAXPATHLEN); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 856 | if (IS_ERR(p)) |
| 857 | goto out_err; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 858 | mntpath = p; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 859 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 860 | dprintk("MNTPATH: %s\n", mntpath); |
| 861 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 862 | p = strndup_user(data->client_addr.data, 16); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 863 | if (IS_ERR(p)) |
| 864 | goto out_err; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 865 | ip_addr = p; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 866 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 867 | /* Get a volume representation */ |
| 868 | server = nfs4_create_server(data, hostname, &addr, mntpath, ip_addr, |
| 869 | authflavour, &mntfh); |
| 870 | if (IS_ERR(server)) { |
| 871 | error = PTR_ERR(server); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 872 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 873 | } |
| 874 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 875 | /* Get a superblock - note that we may end up sharing one that already exists */ |
| 876 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 877 | if (IS_ERR(s)) { |
| 878 | error = PTR_ERR(s); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 879 | goto out_free; |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Trond Myklebust | 5dd3177 | 2006-08-24 01:03:05 -0400 | [diff] [blame] | 882 | if (s->s_fs_info != server) { |
| 883 | nfs_free_server(server); |
| 884 | server = NULL; |
| 885 | } |
| 886 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 887 | if (!s->s_root) { |
| 888 | /* initial superblock/root creation */ |
| 889 | s->s_flags = flags; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 890 | nfs4_fill_super(s); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 891 | } |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 892 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 893 | mntroot = nfs4_get_root(s, &mntfh); |
| 894 | if (IS_ERR(mntroot)) { |
| 895 | error = PTR_ERR(mntroot); |
| 896 | goto error_splat_super; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 897 | } |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 898 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 899 | s->s_flags |= MS_ACTIVE; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 900 | mnt->mnt_sb = s; |
| 901 | mnt->mnt_root = mntroot; |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 902 | error = 0; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 903 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 904 | out: |
| 905 | kfree(ip_addr); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 906 | kfree(mntpath); |
| 907 | kfree(hostname); |
Trond Myklebust | 816724e | 2006-06-24 08:41:41 -0400 | [diff] [blame] | 908 | return error; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 909 | |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 910 | out_err: |
| 911 | error = PTR_ERR(p); |
| 912 | goto out; |
| 913 | |
| 914 | out_free: |
| 915 | nfs_free_server(server); |
| 916 | goto out; |
| 917 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 918 | error_splat_super: |
| 919 | up_write(&s->s_umount); |
| 920 | deactivate_super(s); |
Chuck Lever | 29eb981 | 2007-07-01 12:12:30 -0400 | [diff] [blame] | 921 | goto out; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | static void nfs4_kill_super(struct super_block *sb) |
| 925 | { |
| 926 | struct nfs_server *server = NFS_SB(sb); |
| 927 | |
| 928 | nfs_return_all_delegations(sb); |
| 929 | kill_anon_super(sb); |
| 930 | |
| 931 | nfs4_renewd_prepare_shutdown(server); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 932 | nfs_free_server(server); |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 936 | * Clone an NFS4 server record on xdev traversal (FSID-change) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 937 | */ |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 938 | static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags, |
| 939 | const char *dev_name, void *raw_data, |
| 940 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 941 | { |
| 942 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 943 | struct super_block *s; |
| 944 | struct nfs_server *server; |
| 945 | struct dentry *mntroot; |
| 946 | int error; |
| 947 | |
| 948 | dprintk("--> nfs4_xdev_get_sb()\n"); |
| 949 | |
| 950 | /* create a new volume representation */ |
| 951 | server = nfs_clone_server(NFS_SB(data->sb), data->fh, data->fattr); |
| 952 | if (IS_ERR(server)) { |
| 953 | error = PTR_ERR(server); |
| 954 | goto out_err_noserver; |
| 955 | } |
| 956 | |
| 957 | /* Get a superblock - note that we may end up sharing one that already exists */ |
| 958 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
| 959 | if (IS_ERR(s)) { |
| 960 | error = PTR_ERR(s); |
| 961 | goto out_err_nosb; |
| 962 | } |
| 963 | |
| 964 | if (s->s_fs_info != server) { |
| 965 | nfs_free_server(server); |
| 966 | server = NULL; |
| 967 | } |
| 968 | |
| 969 | if (!s->s_root) { |
| 970 | /* initial superblock/root creation */ |
| 971 | s->s_flags = flags; |
| 972 | nfs4_clone_super(s, data->sb); |
| 973 | } |
| 974 | |
| 975 | mntroot = nfs4_get_root(s, data->fh); |
| 976 | if (IS_ERR(mntroot)) { |
| 977 | error = PTR_ERR(mntroot); |
| 978 | goto error_splat_super; |
| 979 | } |
| 980 | |
| 981 | s->s_flags |= MS_ACTIVE; |
| 982 | mnt->mnt_sb = s; |
| 983 | mnt->mnt_root = mntroot; |
| 984 | |
| 985 | dprintk("<-- nfs4_xdev_get_sb() = 0\n"); |
| 986 | return 0; |
| 987 | |
| 988 | out_err_nosb: |
| 989 | nfs_free_server(server); |
| 990 | out_err_noserver: |
| 991 | dprintk("<-- nfs4_xdev_get_sb() = %d [error]\n", error); |
| 992 | return error; |
| 993 | |
| 994 | error_splat_super: |
| 995 | up_write(&s->s_umount); |
| 996 | deactivate_super(s); |
| 997 | dprintk("<-- nfs4_xdev_get_sb() = %d [splat]\n", error); |
| 998 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 999 | } |
| 1000 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1001 | /* |
| 1002 | * Create an NFS4 server record on referral traversal |
| 1003 | */ |
| 1004 | static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags, |
| 1005 | const char *dev_name, void *raw_data, |
| 1006 | struct vfsmount *mnt) |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1007 | { |
| 1008 | struct nfs_clone_mount *data = raw_data; |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1009 | struct super_block *s; |
| 1010 | struct nfs_server *server; |
| 1011 | struct dentry *mntroot; |
| 1012 | struct nfs_fh mntfh; |
| 1013 | int error; |
| 1014 | |
| 1015 | dprintk("--> nfs4_referral_get_sb()\n"); |
| 1016 | |
| 1017 | /* create a new volume representation */ |
| 1018 | server = nfs4_create_referral_server(data, &mntfh); |
| 1019 | if (IS_ERR(server)) { |
| 1020 | error = PTR_ERR(server); |
| 1021 | goto out_err_noserver; |
| 1022 | } |
| 1023 | |
| 1024 | /* Get a superblock - note that we may end up sharing one that already exists */ |
| 1025 | s = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
| 1026 | if (IS_ERR(s)) { |
| 1027 | error = PTR_ERR(s); |
| 1028 | goto out_err_nosb; |
| 1029 | } |
| 1030 | |
| 1031 | if (s->s_fs_info != server) { |
| 1032 | nfs_free_server(server); |
| 1033 | server = NULL; |
| 1034 | } |
| 1035 | |
| 1036 | if (!s->s_root) { |
| 1037 | /* initial superblock/root creation */ |
| 1038 | s->s_flags = flags; |
| 1039 | nfs4_fill_super(s); |
| 1040 | } |
| 1041 | |
Trond Myklebust | f2d0d85 | 2007-02-02 14:46:09 -0800 | [diff] [blame] | 1042 | mntroot = nfs4_get_root(s, &mntfh); |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1043 | if (IS_ERR(mntroot)) { |
| 1044 | error = PTR_ERR(mntroot); |
| 1045 | goto error_splat_super; |
| 1046 | } |
| 1047 | |
| 1048 | s->s_flags |= MS_ACTIVE; |
| 1049 | mnt->mnt_sb = s; |
| 1050 | mnt->mnt_root = mntroot; |
| 1051 | |
| 1052 | dprintk("<-- nfs4_referral_get_sb() = 0\n"); |
| 1053 | return 0; |
| 1054 | |
| 1055 | out_err_nosb: |
| 1056 | nfs_free_server(server); |
| 1057 | out_err_noserver: |
| 1058 | dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error); |
| 1059 | return error; |
| 1060 | |
| 1061 | error_splat_super: |
| 1062 | up_write(&s->s_umount); |
| 1063 | deactivate_super(s); |
| 1064 | dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error); |
| 1065 | return error; |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 1068 | #endif /* CONFIG_NFS_V4 */ |