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 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/config.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | |
| 22 | #include <linux/time.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/mm.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/stat.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/unistd.h> |
| 29 | #include <linux/sunrpc/clnt.h> |
| 30 | #include <linux/sunrpc/stats.h> |
| 31 | #include <linux/sunrpc/metrics.h> |
| 32 | #include <linux/nfs_fs.h> |
| 33 | #include <linux/nfs_mount.h> |
| 34 | #include <linux/nfs4_mount.h> |
| 35 | #include <linux/lockd/bind.h> |
| 36 | #include <linux/smp_lock.h> |
| 37 | #include <linux/seq_file.h> |
| 38 | #include <linux/mount.h> |
| 39 | #include <linux/nfs_idmap.h> |
| 40 | #include <linux/vfs.h> |
| 41 | #include <linux/inet.h> |
| 42 | #include <linux/nfs_xdr.h> |
| 43 | |
| 44 | #include <asm/system.h> |
| 45 | #include <asm/uaccess.h> |
| 46 | |
| 47 | #include "nfs4_fs.h" |
| 48 | #include "callback.h" |
| 49 | #include "delegation.h" |
| 50 | #include "iostat.h" |
| 51 | #include "internal.h" |
| 52 | |
| 53 | #define NFSDBG_FACILITY NFSDBG_VFS |
| 54 | |
| 55 | /* Maximum number of readahead requests |
| 56 | * FIXME: this should really be a sysctl so that users may tune it to suit |
| 57 | * their needs. People that do NFS over a slow network, might for |
| 58 | * instance want to reduce it to something closer to 1 for improved |
| 59 | * interactive response. |
| 60 | */ |
| 61 | #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) |
| 62 | |
| 63 | /* |
| 64 | * RPC cruft for NFS |
| 65 | */ |
| 66 | static struct rpc_version * nfs_version[] = { |
| 67 | NULL, |
| 68 | NULL, |
| 69 | &nfs_version2, |
| 70 | #if defined(CONFIG_NFS_V3) |
| 71 | &nfs_version3, |
| 72 | #elif defined(CONFIG_NFS_V4) |
| 73 | NULL, |
| 74 | #endif |
| 75 | #if defined(CONFIG_NFS_V4) |
| 76 | &nfs_version4, |
| 77 | #endif |
| 78 | }; |
| 79 | |
| 80 | static struct rpc_program nfs_program = { |
| 81 | .name = "nfs", |
| 82 | .number = NFS_PROGRAM, |
| 83 | .nrvers = ARRAY_SIZE(nfs_version), |
| 84 | .version = nfs_version, |
| 85 | .stats = &nfs_rpcstat, |
| 86 | .pipe_dir_name = "/nfs", |
| 87 | }; |
| 88 | |
| 89 | struct rpc_stat nfs_rpcstat = { |
| 90 | .program = &nfs_program |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | #ifdef CONFIG_NFS_V3_ACL |
| 95 | static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; |
| 96 | static struct rpc_version * nfsacl_version[] = { |
| 97 | [3] = &nfsacl_version3, |
| 98 | }; |
| 99 | |
| 100 | struct rpc_program nfsacl_program = { |
| 101 | .name = "nfsacl", |
| 102 | .number = NFS_ACL_PROGRAM, |
| 103 | .nrvers = ARRAY_SIZE(nfsacl_version), |
| 104 | .version = nfsacl_version, |
| 105 | .stats = &nfsacl_rpcstat, |
| 106 | }; |
| 107 | #endif /* CONFIG_NFS_V3_ACL */ |
| 108 | |
| 109 | static void nfs_umount_begin(struct vfsmount *, int); |
| 110 | static int nfs_statfs(struct super_block *, struct kstatfs *); |
| 111 | static int nfs_show_options(struct seq_file *, struct vfsmount *); |
| 112 | static int nfs_show_stats(struct seq_file *, struct vfsmount *); |
| 113 | static struct super_block *nfs_get_sb(struct file_system_type *, int, const char *, void *); |
| 114 | static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type, |
| 115 | int flags, const char *dev_name, void *raw_data); |
| 116 | static void nfs_kill_super(struct super_block *); |
| 117 | |
| 118 | static struct file_system_type nfs_fs_type = { |
| 119 | .owner = THIS_MODULE, |
| 120 | .name = "nfs", |
| 121 | .get_sb = nfs_get_sb, |
| 122 | .kill_sb = nfs_kill_super, |
| 123 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
| 124 | }; |
| 125 | |
| 126 | struct file_system_type clone_nfs_fs_type = { |
| 127 | .owner = THIS_MODULE, |
| 128 | .name = "nfs", |
| 129 | .get_sb = nfs_clone_nfs_sb, |
| 130 | .kill_sb = nfs_kill_super, |
| 131 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
| 132 | }; |
| 133 | |
| 134 | static struct super_operations nfs_sops = { |
| 135 | .alloc_inode = nfs_alloc_inode, |
| 136 | .destroy_inode = nfs_destroy_inode, |
| 137 | .write_inode = nfs_write_inode, |
| 138 | .statfs = nfs_statfs, |
| 139 | .clear_inode = nfs_clear_inode, |
| 140 | .umount_begin = nfs_umount_begin, |
| 141 | .show_options = nfs_show_options, |
| 142 | .show_stats = nfs_show_stats, |
| 143 | }; |
| 144 | |
| 145 | #ifdef CONFIG_NFS_V4 |
| 146 | static struct super_block *nfs4_get_sb(struct file_system_type *fs_type, |
| 147 | int flags, const char *dev_name, void *raw_data); |
| 148 | static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type, |
| 149 | int flags, const char *dev_name, void *raw_data); |
| 150 | static struct super_block *nfs_referral_nfs4_sb(struct file_system_type *fs_type, |
| 151 | int flags, const char *dev_name, void *raw_data); |
| 152 | static void nfs4_kill_super(struct super_block *sb); |
| 153 | |
| 154 | static struct file_system_type nfs4_fs_type = { |
| 155 | .owner = THIS_MODULE, |
| 156 | .name = "nfs4", |
| 157 | .get_sb = nfs4_get_sb, |
| 158 | .kill_sb = nfs4_kill_super, |
| 159 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
| 160 | }; |
| 161 | |
| 162 | struct file_system_type clone_nfs4_fs_type = { |
| 163 | .owner = THIS_MODULE, |
| 164 | .name = "nfs4", |
| 165 | .get_sb = nfs_clone_nfs4_sb, |
| 166 | .kill_sb = nfs4_kill_super, |
| 167 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
| 168 | }; |
| 169 | |
| 170 | struct file_system_type nfs_referral_nfs4_fs_type = { |
| 171 | .owner = THIS_MODULE, |
| 172 | .name = "nfs4", |
| 173 | .get_sb = nfs_referral_nfs4_sb, |
| 174 | .kill_sb = nfs4_kill_super, |
| 175 | .fs_flags = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA, |
| 176 | }; |
| 177 | |
| 178 | static struct super_operations nfs4_sops = { |
| 179 | .alloc_inode = nfs_alloc_inode, |
| 180 | .destroy_inode = nfs_destroy_inode, |
| 181 | .write_inode = nfs_write_inode, |
| 182 | .statfs = nfs_statfs, |
| 183 | .clear_inode = nfs4_clear_inode, |
| 184 | .umount_begin = nfs_umount_begin, |
| 185 | .show_options = nfs_show_options, |
| 186 | .show_stats = nfs_show_stats, |
| 187 | }; |
| 188 | #endif |
| 189 | |
| 190 | static const int nfs_set_port_min = 0; |
| 191 | static const int nfs_set_port_max = 65535; |
| 192 | |
| 193 | static int param_set_port(const char *val, struct kernel_param *kp) |
| 194 | { |
| 195 | char *endp; |
| 196 | int num = simple_strtol(val, &endp, 0); |
| 197 | if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max) |
| 198 | return -EINVAL; |
| 199 | *((int *)kp->arg) = num; |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | module_param_call(callback_tcpport, param_set_port, param_get_int, |
| 204 | &nfs_callback_set_tcpport, 0644); |
| 205 | |
| 206 | static int param_set_idmap_timeout(const char *val, struct kernel_param *kp) |
| 207 | { |
| 208 | char *endp; |
| 209 | int num = simple_strtol(val, &endp, 0); |
| 210 | int jif = num * HZ; |
| 211 | if (endp == val || *endp || num < 0 || jif < num) |
| 212 | return -EINVAL; |
| 213 | *((int *)kp->arg) = jif; |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int, |
| 218 | &nfs_idmap_cache_timeout, 0644); |
| 219 | |
| 220 | /* |
| 221 | * Register the NFS filesystems |
| 222 | */ |
| 223 | int __init register_nfs_fs(void) |
| 224 | { |
| 225 | int ret; |
| 226 | |
| 227 | ret = register_filesystem(&nfs_fs_type); |
| 228 | if (ret < 0) |
| 229 | goto error_0; |
| 230 | |
| 231 | #ifdef CONFIG_NFS_V4 |
| 232 | ret = nfs_register_sysctl(); |
| 233 | if (ret < 0) |
| 234 | goto error_1; |
| 235 | ret = register_filesystem(&nfs4_fs_type); |
| 236 | if (ret < 0) |
| 237 | goto error_2; |
| 238 | #endif |
| 239 | return 0; |
| 240 | |
| 241 | #ifdef CONFIG_NFS_V4 |
| 242 | error_2: |
| 243 | nfs_unregister_sysctl(); |
| 244 | error_1: |
| 245 | unregister_filesystem(&nfs_fs_type); |
| 246 | #endif |
| 247 | error_0: |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * Unregister the NFS filesystems |
| 253 | */ |
| 254 | void __exit unregister_nfs_fs(void) |
| 255 | { |
| 256 | #ifdef CONFIG_NFS_V4 |
| 257 | unregister_filesystem(&nfs4_fs_type); |
| 258 | nfs_unregister_sysctl(); |
| 259 | #endif |
| 260 | unregister_filesystem(&nfs_fs_type); |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * Deliver file system statistics to userspace |
| 265 | */ |
| 266 | static int nfs_statfs(struct super_block *sb, struct kstatfs *buf) |
| 267 | { |
| 268 | struct nfs_server *server = NFS_SB(sb); |
| 269 | unsigned char blockbits; |
| 270 | unsigned long blockres; |
| 271 | struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode); |
| 272 | struct nfs_fattr fattr; |
| 273 | struct nfs_fsstat res = { |
| 274 | .fattr = &fattr, |
| 275 | }; |
| 276 | int error; |
| 277 | |
| 278 | lock_kernel(); |
| 279 | |
| 280 | error = server->rpc_ops->statfs(server, rootfh, &res); |
| 281 | buf->f_type = NFS_SUPER_MAGIC; |
| 282 | if (error < 0) |
| 283 | goto out_err; |
| 284 | |
| 285 | /* |
| 286 | * Current versions of glibc do not correctly handle the |
| 287 | * case where f_frsize != f_bsize. Eventually we want to |
| 288 | * report the value of wtmult in this field. |
| 289 | */ |
| 290 | buf->f_frsize = sb->s_blocksize; |
| 291 | |
| 292 | /* |
| 293 | * On most *nix systems, f_blocks, f_bfree, and f_bavail |
| 294 | * are reported in units of f_frsize. Linux hasn't had |
| 295 | * an f_frsize field in its statfs struct until recently, |
| 296 | * thus historically Linux's sys_statfs reports these |
| 297 | * fields in units of f_bsize. |
| 298 | */ |
| 299 | buf->f_bsize = sb->s_blocksize; |
| 300 | blockbits = sb->s_blocksize_bits; |
| 301 | blockres = (1 << blockbits) - 1; |
| 302 | buf->f_blocks = (res.tbytes + blockres) >> blockbits; |
| 303 | buf->f_bfree = (res.fbytes + blockres) >> blockbits; |
| 304 | buf->f_bavail = (res.abytes + blockres) >> blockbits; |
| 305 | |
| 306 | buf->f_files = res.tfiles; |
| 307 | buf->f_ffree = res.afiles; |
| 308 | |
| 309 | buf->f_namelen = server->namelen; |
| 310 | out: |
| 311 | unlock_kernel(); |
| 312 | return 0; |
| 313 | |
| 314 | out_err: |
| 315 | dprintk("%s: statfs error = %d\n", __FUNCTION__, -error); |
| 316 | buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; |
| 317 | goto out; |
| 318 | |
| 319 | } |
| 320 | |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame^] | 321 | static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour) |
| 322 | { |
| 323 | static struct { |
| 324 | rpc_authflavor_t flavour; |
| 325 | const char *str; |
| 326 | } sec_flavours[] = { |
| 327 | { RPC_AUTH_NULL, "null" }, |
| 328 | { RPC_AUTH_UNIX, "sys" }, |
| 329 | { RPC_AUTH_GSS_KRB5, "krb5" }, |
| 330 | { RPC_AUTH_GSS_KRB5I, "krb5i" }, |
| 331 | { RPC_AUTH_GSS_KRB5P, "krb5p" }, |
| 332 | { RPC_AUTH_GSS_LKEY, "lkey" }, |
| 333 | { RPC_AUTH_GSS_LKEYI, "lkeyi" }, |
| 334 | { RPC_AUTH_GSS_LKEYP, "lkeyp" }, |
| 335 | { RPC_AUTH_GSS_SPKM, "spkm" }, |
| 336 | { RPC_AUTH_GSS_SPKMI, "spkmi" }, |
| 337 | { RPC_AUTH_GSS_SPKMP, "spkmp" }, |
| 338 | { -1, "unknown" } |
| 339 | }; |
| 340 | int i; |
| 341 | |
| 342 | for (i=0; sec_flavours[i].flavour != -1; i++) { |
| 343 | if (sec_flavours[i].flavour == flavour) |
| 344 | break; |
| 345 | } |
| 346 | return sec_flavours[i].str; |
| 347 | } |
| 348 | |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 349 | /* |
| 350 | * Describe the mount options in force on this server representation |
| 351 | */ |
| 352 | static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) |
| 353 | { |
| 354 | static struct proc_nfs_info { |
| 355 | int flag; |
| 356 | char *str; |
| 357 | char *nostr; |
| 358 | } nfs_info[] = { |
| 359 | { NFS_MOUNT_SOFT, ",soft", ",hard" }, |
| 360 | { NFS_MOUNT_INTR, ",intr", "" }, |
| 361 | { NFS_MOUNT_NOCTO, ",nocto", "" }, |
| 362 | { NFS_MOUNT_NOAC, ",noac", "" }, |
| 363 | { NFS_MOUNT_NONLM, ",nolock", "" }, |
| 364 | { NFS_MOUNT_NOACL, ",noacl", "" }, |
| 365 | { 0, NULL, NULL } |
| 366 | }; |
| 367 | struct proc_nfs_info *nfs_infop; |
| 368 | char buf[12]; |
| 369 | char *proto; |
| 370 | |
| 371 | seq_printf(m, ",vers=%d", nfss->rpc_ops->version); |
| 372 | seq_printf(m, ",rsize=%d", nfss->rsize); |
| 373 | seq_printf(m, ",wsize=%d", nfss->wsize); |
| 374 | if (nfss->acregmin != 3*HZ || showdefaults) |
| 375 | seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ); |
| 376 | if (nfss->acregmax != 60*HZ || showdefaults) |
| 377 | seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ); |
| 378 | if (nfss->acdirmin != 30*HZ || showdefaults) |
| 379 | seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ); |
| 380 | if (nfss->acdirmax != 60*HZ || showdefaults) |
| 381 | seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ); |
| 382 | for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { |
| 383 | if (nfss->flags & nfs_infop->flag) |
| 384 | seq_puts(m, nfs_infop->str); |
| 385 | else |
| 386 | seq_puts(m, nfs_infop->nostr); |
| 387 | } |
| 388 | switch (nfss->client->cl_xprt->prot) { |
| 389 | case IPPROTO_TCP: |
| 390 | proto = "tcp"; |
| 391 | break; |
| 392 | case IPPROTO_UDP: |
| 393 | proto = "udp"; |
| 394 | break; |
| 395 | default: |
| 396 | snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot); |
| 397 | proto = buf; |
| 398 | } |
| 399 | seq_printf(m, ",proto=%s", proto); |
| 400 | seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ); |
| 401 | seq_printf(m, ",retrans=%u", nfss->retrans_count); |
Trond Myklebust | 81039f1 | 2006-06-09 09:34:34 -0400 | [diff] [blame^] | 402 | 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] | 403 | } |
| 404 | |
| 405 | /* |
| 406 | * Describe the mount options on this VFS mountpoint |
| 407 | */ |
| 408 | static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 409 | { |
| 410 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 411 | |
| 412 | nfs_show_mount_options(m, nfss, 0); |
| 413 | |
| 414 | seq_puts(m, ",addr="); |
| 415 | seq_escape(m, nfss->hostname, " \t\n\\"); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | /* |
| 421 | * Present statistical information for this VFS mountpoint |
| 422 | */ |
| 423 | static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt) |
| 424 | { |
| 425 | int i, cpu; |
| 426 | struct nfs_server *nfss = NFS_SB(mnt->mnt_sb); |
| 427 | struct rpc_auth *auth = nfss->client->cl_auth; |
| 428 | struct nfs_iostats totals = { }; |
| 429 | |
| 430 | seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS); |
| 431 | |
| 432 | /* |
| 433 | * Display all mount option settings |
| 434 | */ |
| 435 | seq_printf(m, "\n\topts:\t"); |
| 436 | seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw"); |
| 437 | seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : ""); |
| 438 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : ""); |
| 439 | seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : ""); |
| 440 | nfs_show_mount_options(m, nfss, 1); |
| 441 | |
| 442 | seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); |
| 443 | |
| 444 | seq_printf(m, "\n\tcaps:\t"); |
| 445 | seq_printf(m, "caps=0x%x", nfss->caps); |
| 446 | seq_printf(m, ",wtmult=%d", nfss->wtmult); |
| 447 | seq_printf(m, ",dtsize=%d", nfss->dtsize); |
| 448 | seq_printf(m, ",bsize=%d", nfss->bsize); |
| 449 | seq_printf(m, ",namelen=%d", nfss->namelen); |
| 450 | |
| 451 | #ifdef CONFIG_NFS_V4 |
| 452 | if (nfss->rpc_ops->version == 4) { |
| 453 | seq_printf(m, "\n\tnfsv4:\t"); |
| 454 | seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]); |
| 455 | seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]); |
| 456 | seq_printf(m, ",acl=0x%x", nfss->acl_bitmask); |
| 457 | } |
| 458 | #endif |
| 459 | |
| 460 | /* |
| 461 | * Display security flavor in effect for this mount |
| 462 | */ |
| 463 | seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor); |
| 464 | if (auth->au_flavor) |
| 465 | seq_printf(m, ",pseudoflavor=%d", auth->au_flavor); |
| 466 | |
| 467 | /* |
| 468 | * Display superblock I/O counters |
| 469 | */ |
| 470 | for_each_possible_cpu(cpu) { |
| 471 | struct nfs_iostats *stats; |
| 472 | |
| 473 | preempt_disable(); |
| 474 | stats = per_cpu_ptr(nfss->io_stats, cpu); |
| 475 | |
| 476 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 477 | totals.events[i] += stats->events[i]; |
| 478 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 479 | totals.bytes[i] += stats->bytes[i]; |
| 480 | |
| 481 | preempt_enable(); |
| 482 | } |
| 483 | |
| 484 | seq_printf(m, "\n\tevents:\t"); |
| 485 | for (i = 0; i < __NFSIOS_COUNTSMAX; i++) |
| 486 | seq_printf(m, "%lu ", totals.events[i]); |
| 487 | seq_printf(m, "\n\tbytes:\t"); |
| 488 | for (i = 0; i < __NFSIOS_BYTESMAX; i++) |
| 489 | seq_printf(m, "%Lu ", totals.bytes[i]); |
| 490 | seq_printf(m, "\n"); |
| 491 | |
| 492 | rpc_print_iostats(m, nfss->client); |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * Begin unmount by attempting to remove all automounted mountpoints we added |
| 499 | * in response to traversals |
| 500 | */ |
| 501 | static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags) |
| 502 | { |
| 503 | struct nfs_server *server; |
| 504 | struct rpc_clnt *rpc; |
| 505 | |
| 506 | shrink_submounts(vfsmnt, &nfs_automount_list); |
| 507 | if (!(flags & MNT_FORCE)) |
| 508 | return; |
| 509 | /* -EIO all pending I/O */ |
| 510 | server = NFS_SB(vfsmnt->mnt_sb); |
| 511 | rpc = server->client; |
| 512 | if (!IS_ERR(rpc)) |
| 513 | rpc_killall_tasks(rpc); |
| 514 | rpc = server->client_acl; |
| 515 | if (!IS_ERR(rpc)) |
| 516 | rpc_killall_tasks(rpc); |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * Obtain the root inode of the file system. |
| 521 | */ |
| 522 | static struct inode * |
| 523 | nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo) |
| 524 | { |
| 525 | struct nfs_server *server = NFS_SB(sb); |
| 526 | int error; |
| 527 | |
| 528 | error = server->rpc_ops->getroot(server, rootfh, fsinfo); |
| 529 | if (error < 0) { |
| 530 | dprintk("nfs_get_root: getattr error = %d\n", -error); |
| 531 | return ERR_PTR(error); |
| 532 | } |
| 533 | |
| 534 | server->fsid = fsinfo->fattr->fsid; |
| 535 | return nfs_fhget(sb, rootfh, fsinfo->fattr); |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * Do NFS version-independent mount processing, and sanity checking |
| 540 | */ |
| 541 | static int |
| 542 | nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor) |
| 543 | { |
| 544 | struct nfs_server *server; |
| 545 | struct inode *root_inode; |
| 546 | struct nfs_fattr fattr; |
| 547 | struct nfs_fsinfo fsinfo = { |
| 548 | .fattr = &fattr, |
| 549 | }; |
| 550 | struct nfs_pathconf pathinfo = { |
| 551 | .fattr = &fattr, |
| 552 | }; |
| 553 | int no_root_error = 0; |
| 554 | unsigned long max_rpc_payload; |
| 555 | |
| 556 | /* We probably want something more informative here */ |
| 557 | snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); |
| 558 | |
| 559 | server = NFS_SB(sb); |
| 560 | |
| 561 | sb->s_magic = NFS_SUPER_MAGIC; |
| 562 | |
| 563 | server->io_stats = nfs_alloc_iostats(); |
| 564 | if (server->io_stats == NULL) |
| 565 | return -ENOMEM; |
| 566 | |
| 567 | root_inode = nfs_get_root(sb, &server->fh, &fsinfo); |
| 568 | /* Did getting the root inode fail? */ |
| 569 | if (IS_ERR(root_inode)) { |
| 570 | no_root_error = PTR_ERR(root_inode); |
| 571 | goto out_no_root; |
| 572 | } |
| 573 | sb->s_root = d_alloc_root(root_inode); |
| 574 | if (!sb->s_root) { |
| 575 | no_root_error = -ENOMEM; |
| 576 | goto out_no_root; |
| 577 | } |
| 578 | sb->s_root->d_op = server->rpc_ops->dentry_ops; |
| 579 | |
| 580 | /* mount time stamp, in seconds */ |
| 581 | server->mount_time = jiffies; |
| 582 | |
| 583 | /* Get some general file system info */ |
| 584 | if (server->namelen == 0 && |
| 585 | server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0) |
| 586 | server->namelen = pathinfo.max_namelen; |
| 587 | /* Work out a lot of parameters */ |
| 588 | if (server->rsize == 0) |
| 589 | server->rsize = nfs_block_size(fsinfo.rtpref, NULL); |
| 590 | if (server->wsize == 0) |
| 591 | server->wsize = nfs_block_size(fsinfo.wtpref, NULL); |
| 592 | |
| 593 | if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax) |
| 594 | server->rsize = nfs_block_size(fsinfo.rtmax, NULL); |
| 595 | if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax) |
| 596 | server->wsize = nfs_block_size(fsinfo.wtmax, NULL); |
| 597 | |
| 598 | max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL); |
| 599 | if (server->rsize > max_rpc_payload) |
| 600 | server->rsize = max_rpc_payload; |
| 601 | if (server->rsize > NFS_MAX_FILE_IO_SIZE) |
| 602 | server->rsize = NFS_MAX_FILE_IO_SIZE; |
| 603 | server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
| 604 | |
| 605 | if (server->wsize > max_rpc_payload) |
| 606 | server->wsize = max_rpc_payload; |
| 607 | if (server->wsize > NFS_MAX_FILE_IO_SIZE) |
| 608 | server->wsize = NFS_MAX_FILE_IO_SIZE; |
| 609 | server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
| 610 | |
| 611 | if (sb->s_blocksize == 0) |
| 612 | sb->s_blocksize = nfs_block_bits(server->wsize, |
| 613 | &sb->s_blocksize_bits); |
| 614 | server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL); |
| 615 | |
| 616 | server->dtsize = nfs_block_size(fsinfo.dtpref, NULL); |
| 617 | if (server->dtsize > PAGE_CACHE_SIZE) |
| 618 | server->dtsize = PAGE_CACHE_SIZE; |
| 619 | if (server->dtsize > server->rsize) |
| 620 | server->dtsize = server->rsize; |
| 621 | |
| 622 | if (server->flags & NFS_MOUNT_NOAC) { |
| 623 | server->acregmin = server->acregmax = 0; |
| 624 | server->acdirmin = server->acdirmax = 0; |
| 625 | sb->s_flags |= MS_SYNCHRONOUS; |
| 626 | } |
| 627 | server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD; |
| 628 | |
| 629 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); |
| 630 | |
| 631 | server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0; |
| 632 | server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0; |
| 633 | |
| 634 | /* We're airborne Set socket buffersize */ |
| 635 | rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100); |
| 636 | return 0; |
| 637 | /* Yargs. It didn't work out. */ |
| 638 | out_no_root: |
| 639 | dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error); |
| 640 | if (!IS_ERR(root_inode)) |
| 641 | iput(root_inode); |
| 642 | return no_root_error; |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * Initialise the timeout values for a connection |
| 647 | */ |
| 648 | static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans) |
| 649 | { |
| 650 | to->to_initval = timeo * HZ / 10; |
| 651 | to->to_retries = retrans; |
| 652 | if (!to->to_retries) |
| 653 | to->to_retries = 2; |
| 654 | |
| 655 | switch (proto) { |
| 656 | case IPPROTO_TCP: |
| 657 | if (!to->to_initval) |
| 658 | to->to_initval = 60 * HZ; |
| 659 | if (to->to_initval > NFS_MAX_TCP_TIMEOUT) |
| 660 | to->to_initval = NFS_MAX_TCP_TIMEOUT; |
| 661 | to->to_increment = to->to_initval; |
| 662 | to->to_maxval = to->to_initval + (to->to_increment * to->to_retries); |
| 663 | to->to_exponential = 0; |
| 664 | break; |
| 665 | case IPPROTO_UDP: |
| 666 | default: |
| 667 | if (!to->to_initval) |
| 668 | to->to_initval = 11 * HZ / 10; |
| 669 | if (to->to_initval > NFS_MAX_UDP_TIMEOUT) |
| 670 | to->to_initval = NFS_MAX_UDP_TIMEOUT; |
| 671 | to->to_maxval = NFS_MAX_UDP_TIMEOUT; |
| 672 | to->to_exponential = 1; |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Create an RPC client handle. |
| 679 | */ |
| 680 | static struct rpc_clnt * |
| 681 | nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data) |
| 682 | { |
| 683 | struct rpc_timeout timeparms; |
| 684 | struct rpc_xprt *xprt = NULL; |
| 685 | struct rpc_clnt *clnt = NULL; |
| 686 | int proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP; |
| 687 | |
| 688 | nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans); |
| 689 | |
| 690 | server->retrans_timeo = timeparms.to_initval; |
| 691 | server->retrans_count = timeparms.to_retries; |
| 692 | |
| 693 | /* create transport and client */ |
| 694 | xprt = xprt_create_proto(proto, &server->addr, &timeparms); |
| 695 | if (IS_ERR(xprt)) { |
| 696 | dprintk("%s: cannot create RPC transport. Error = %ld\n", |
| 697 | __FUNCTION__, PTR_ERR(xprt)); |
| 698 | return (struct rpc_clnt *)xprt; |
| 699 | } |
| 700 | clnt = rpc_create_client(xprt, server->hostname, &nfs_program, |
| 701 | server->rpc_ops->version, data->pseudoflavor); |
| 702 | if (IS_ERR(clnt)) { |
| 703 | dprintk("%s: cannot create RPC client. Error = %ld\n", |
| 704 | __FUNCTION__, PTR_ERR(xprt)); |
| 705 | goto out_fail; |
| 706 | } |
| 707 | |
| 708 | clnt->cl_intr = 1; |
| 709 | clnt->cl_softrtry = 1; |
| 710 | |
| 711 | return clnt; |
| 712 | |
| 713 | out_fail: |
| 714 | return clnt; |
| 715 | } |
| 716 | |
| 717 | /* |
| 718 | * Clone a server record |
| 719 | */ |
| 720 | static struct nfs_server *nfs_clone_server(struct super_block *sb, struct nfs_clone_mount *data) |
| 721 | { |
| 722 | struct nfs_server *server = NFS_SB(sb); |
| 723 | struct nfs_server *parent = NFS_SB(data->sb); |
| 724 | struct inode *root_inode; |
| 725 | struct nfs_fsinfo fsinfo; |
| 726 | void *err = ERR_PTR(-ENOMEM); |
| 727 | |
| 728 | sb->s_op = data->sb->s_op; |
| 729 | sb->s_blocksize = data->sb->s_blocksize; |
| 730 | sb->s_blocksize_bits = data->sb->s_blocksize_bits; |
| 731 | sb->s_maxbytes = data->sb->s_maxbytes; |
| 732 | |
| 733 | server->client_sys = server->client_acl = ERR_PTR(-EINVAL); |
| 734 | server->io_stats = nfs_alloc_iostats(); |
| 735 | if (server->io_stats == NULL) |
| 736 | goto out; |
| 737 | |
| 738 | server->client = rpc_clone_client(parent->client); |
| 739 | if (IS_ERR((err = server->client))) |
| 740 | goto out; |
| 741 | |
| 742 | if (!IS_ERR(parent->client_sys)) { |
| 743 | server->client_sys = rpc_clone_client(parent->client_sys); |
| 744 | if (IS_ERR((err = server->client_sys))) |
| 745 | goto out; |
| 746 | } |
| 747 | if (!IS_ERR(parent->client_acl)) { |
| 748 | server->client_acl = rpc_clone_client(parent->client_acl); |
| 749 | if (IS_ERR((err = server->client_acl))) |
| 750 | goto out; |
| 751 | } |
| 752 | root_inode = nfs_fhget(sb, data->fh, data->fattr); |
| 753 | if (!root_inode) |
| 754 | goto out; |
| 755 | sb->s_root = d_alloc_root(root_inode); |
| 756 | if (!sb->s_root) |
| 757 | goto out_put_root; |
| 758 | fsinfo.fattr = data->fattr; |
| 759 | if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0) |
| 760 | nfs_super_set_maxbytes(sb, fsinfo.maxfilesize); |
| 761 | sb->s_root->d_op = server->rpc_ops->dentry_ops; |
| 762 | sb->s_flags |= MS_ACTIVE; |
| 763 | return server; |
| 764 | out_put_root: |
| 765 | iput(root_inode); |
| 766 | out: |
| 767 | return err; |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | * Copy an existing superblock and attach revised data |
| 772 | */ |
| 773 | static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data, |
| 774 | struct super_block *(*fill_sb)(struct nfs_server *, struct nfs_clone_mount *), |
| 775 | struct nfs_server *(*fill_server)(struct super_block *, struct nfs_clone_mount *)) |
| 776 | { |
| 777 | struct nfs_server *server; |
| 778 | struct nfs_server *parent = NFS_SB(data->sb); |
| 779 | struct super_block *sb = ERR_PTR(-EINVAL); |
| 780 | void *err = ERR_PTR(-ENOMEM); |
| 781 | char *hostname; |
| 782 | int len; |
| 783 | |
| 784 | server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 785 | if (server == NULL) |
| 786 | goto out_err; |
| 787 | memcpy(server, parent, sizeof(*server)); |
| 788 | hostname = (data->hostname != NULL) ? data->hostname : parent->hostname; |
| 789 | len = strlen(hostname) + 1; |
| 790 | server->hostname = kmalloc(len, GFP_KERNEL); |
| 791 | if (server->hostname == NULL) |
| 792 | goto free_server; |
| 793 | memcpy(server->hostname, hostname, len); |
| 794 | if (rpciod_up() != 0) |
| 795 | goto free_hostname; |
| 796 | |
| 797 | sb = fill_sb(server, data); |
| 798 | if (IS_ERR((err = sb)) || sb->s_root) |
| 799 | goto kill_rpciod; |
| 800 | |
| 801 | server = fill_server(sb, data); |
| 802 | if (IS_ERR((err = server))) |
| 803 | goto out_deactivate; |
| 804 | return sb; |
| 805 | out_deactivate: |
| 806 | up_write(&sb->s_umount); |
| 807 | deactivate_super(sb); |
| 808 | return (struct super_block *)err; |
| 809 | kill_rpciod: |
| 810 | rpciod_down(); |
| 811 | free_hostname: |
| 812 | kfree(server->hostname); |
| 813 | free_server: |
| 814 | kfree(server); |
| 815 | out_err: |
| 816 | return (struct super_block *)err; |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * Set up an NFS2/3 superblock |
| 821 | * |
| 822 | * The way this works is that the mount process passes a structure |
| 823 | * in the data argument which contains the server's IP address |
| 824 | * and the root file handle obtained from the server's mount |
| 825 | * daemon. We stash these away in the private superblock fields. |
| 826 | */ |
| 827 | static int |
| 828 | nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent) |
| 829 | { |
| 830 | struct nfs_server *server; |
| 831 | rpc_authflavor_t authflavor; |
| 832 | |
| 833 | server = NFS_SB(sb); |
| 834 | sb->s_blocksize_bits = 0; |
| 835 | sb->s_blocksize = 0; |
| 836 | if (data->bsize) |
| 837 | sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits); |
| 838 | if (data->rsize) |
| 839 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 840 | if (data->wsize) |
| 841 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 842 | server->flags = data->flags & NFS_MOUNT_FLAGMASK; |
| 843 | |
| 844 | server->acregmin = data->acregmin*HZ; |
| 845 | server->acregmax = data->acregmax*HZ; |
| 846 | server->acdirmin = data->acdirmin*HZ; |
| 847 | server->acdirmax = data->acdirmax*HZ; |
| 848 | |
| 849 | /* Start lockd here, before we might error out */ |
| 850 | if (!(server->flags & NFS_MOUNT_NONLM)) |
| 851 | lockd_up(); |
| 852 | |
| 853 | server->namelen = data->namlen; |
| 854 | server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL); |
| 855 | if (!server->hostname) |
| 856 | return -ENOMEM; |
| 857 | strcpy(server->hostname, data->hostname); |
| 858 | |
| 859 | /* Check NFS protocol revision and initialize RPC op vector |
| 860 | * and file handle pool. */ |
| 861 | #ifdef CONFIG_NFS_V3 |
| 862 | if (server->flags & NFS_MOUNT_VER3) { |
| 863 | server->rpc_ops = &nfs_v3_clientops; |
| 864 | server->caps |= NFS_CAP_READDIRPLUS; |
| 865 | } else { |
| 866 | server->rpc_ops = &nfs_v2_clientops; |
| 867 | } |
| 868 | #else |
| 869 | server->rpc_ops = &nfs_v2_clientops; |
| 870 | #endif |
| 871 | |
| 872 | /* Fill in pseudoflavor for mount version < 5 */ |
| 873 | if (!(data->flags & NFS_MOUNT_SECFLAVOUR)) |
| 874 | data->pseudoflavor = RPC_AUTH_UNIX; |
| 875 | authflavor = data->pseudoflavor; /* save for sb_init() */ |
| 876 | /* XXX maybe we want to add a server->pseudoflavor field */ |
| 877 | |
| 878 | /* Create RPC client handles */ |
| 879 | server->client = nfs_create_client(server, data); |
| 880 | if (IS_ERR(server->client)) |
| 881 | return PTR_ERR(server->client); |
| 882 | /* RFC 2623, sec 2.3.2 */ |
| 883 | if (authflavor != RPC_AUTH_UNIX) { |
| 884 | struct rpc_auth *auth; |
| 885 | |
| 886 | server->client_sys = rpc_clone_client(server->client); |
| 887 | if (IS_ERR(server->client_sys)) |
| 888 | return PTR_ERR(server->client_sys); |
| 889 | auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys); |
| 890 | if (IS_ERR(auth)) |
| 891 | return PTR_ERR(auth); |
| 892 | } else { |
| 893 | atomic_inc(&server->client->cl_count); |
| 894 | server->client_sys = server->client; |
| 895 | } |
| 896 | if (server->flags & NFS_MOUNT_VER3) { |
| 897 | #ifdef CONFIG_NFS_V3_ACL |
| 898 | if (!(server->flags & NFS_MOUNT_NOACL)) { |
| 899 | server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3); |
| 900 | /* No errors! Assume that Sun nfsacls are supported */ |
| 901 | if (!IS_ERR(server->client_acl)) |
| 902 | server->caps |= NFS_CAP_ACLS; |
| 903 | } |
| 904 | #else |
| 905 | server->flags &= ~NFS_MOUNT_NOACL; |
| 906 | #endif /* CONFIG_NFS_V3_ACL */ |
| 907 | /* |
| 908 | * The VFS shouldn't apply the umask to mode bits. We will |
| 909 | * do so ourselves when necessary. |
| 910 | */ |
| 911 | sb->s_flags |= MS_POSIXACL; |
| 912 | if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN) |
| 913 | server->namelen = NFS3_MAXNAMLEN; |
| 914 | sb->s_time_gran = 1; |
| 915 | } else { |
| 916 | if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN) |
| 917 | server->namelen = NFS2_MAXNAMLEN; |
| 918 | } |
| 919 | |
| 920 | sb->s_op = &nfs_sops; |
| 921 | return nfs_sb_init(sb, authflavor); |
| 922 | } |
| 923 | |
| 924 | static int nfs_set_super(struct super_block *s, void *data) |
| 925 | { |
| 926 | s->s_fs_info = data; |
| 927 | return set_anon_super(s, data); |
| 928 | } |
| 929 | |
| 930 | static int nfs_compare_super(struct super_block *sb, void *data) |
| 931 | { |
| 932 | struct nfs_server *server = data; |
| 933 | struct nfs_server *old = NFS_SB(sb); |
| 934 | |
| 935 | if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr) |
| 936 | return 0; |
| 937 | if (old->addr.sin_port != server->addr.sin_port) |
| 938 | return 0; |
| 939 | return !nfs_compare_fh(&old->fh, &server->fh); |
| 940 | } |
| 941 | |
| 942 | static struct super_block *nfs_get_sb(struct file_system_type *fs_type, |
| 943 | int flags, const char *dev_name, void *raw_data) |
| 944 | { |
| 945 | int error; |
| 946 | struct nfs_server *server = NULL; |
| 947 | struct super_block *s; |
| 948 | struct nfs_fh *root; |
| 949 | struct nfs_mount_data *data = raw_data; |
| 950 | |
| 951 | s = ERR_PTR(-EINVAL); |
| 952 | if (data == NULL) { |
| 953 | dprintk("%s: missing data argument\n", __FUNCTION__); |
| 954 | goto out_err; |
| 955 | } |
| 956 | if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) { |
| 957 | dprintk("%s: bad mount version\n", __FUNCTION__); |
| 958 | goto out_err; |
| 959 | } |
| 960 | switch (data->version) { |
| 961 | case 1: |
| 962 | data->namlen = 0; |
| 963 | case 2: |
| 964 | data->bsize = 0; |
| 965 | case 3: |
| 966 | if (data->flags & NFS_MOUNT_VER3) { |
| 967 | dprintk("%s: mount structure version %d does not support NFSv3\n", |
| 968 | __FUNCTION__, |
| 969 | data->version); |
| 970 | goto out_err; |
| 971 | } |
| 972 | data->root.size = NFS2_FHSIZE; |
| 973 | memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE); |
| 974 | case 4: |
| 975 | if (data->flags & NFS_MOUNT_SECFLAVOUR) { |
| 976 | dprintk("%s: mount structure version %d does not support strong security\n", |
| 977 | __FUNCTION__, |
| 978 | data->version); |
| 979 | goto out_err; |
| 980 | } |
| 981 | case 5: |
| 982 | memset(data->context, 0, sizeof(data->context)); |
| 983 | } |
| 984 | #ifndef CONFIG_NFS_V3 |
| 985 | /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */ |
| 986 | s = ERR_PTR(-EPROTONOSUPPORT); |
| 987 | if (data->flags & NFS_MOUNT_VER3) { |
| 988 | dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__); |
| 989 | goto out_err; |
| 990 | } |
| 991 | #endif /* CONFIG_NFS_V3 */ |
| 992 | |
| 993 | s = ERR_PTR(-ENOMEM); |
| 994 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 995 | if (!server) |
| 996 | goto out_err; |
| 997 | /* Zero out the NFS state stuff */ |
| 998 | init_nfsv4_state(server); |
| 999 | server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL); |
| 1000 | |
| 1001 | root = &server->fh; |
| 1002 | if (data->flags & NFS_MOUNT_VER3) |
| 1003 | root->size = data->root.size; |
| 1004 | else |
| 1005 | root->size = NFS2_FHSIZE; |
| 1006 | s = ERR_PTR(-EINVAL); |
| 1007 | if (root->size > sizeof(root->data)) { |
| 1008 | dprintk("%s: invalid root filehandle\n", __FUNCTION__); |
| 1009 | goto out_err; |
| 1010 | } |
| 1011 | memcpy(root->data, data->root.data, root->size); |
| 1012 | |
| 1013 | /* We now require that the mount process passes the remote address */ |
| 1014 | memcpy(&server->addr, &data->addr, sizeof(server->addr)); |
| 1015 | if (server->addr.sin_addr.s_addr == INADDR_ANY) { |
| 1016 | dprintk("%s: mount program didn't pass remote address!\n", |
| 1017 | __FUNCTION__); |
| 1018 | goto out_err; |
| 1019 | } |
| 1020 | |
| 1021 | /* Fire up rpciod if not yet running */ |
| 1022 | s = ERR_PTR(rpciod_up()); |
| 1023 | if (IS_ERR(s)) { |
| 1024 | dprintk("%s: couldn't start rpciod! Error = %ld\n", |
| 1025 | __FUNCTION__, PTR_ERR(s)); |
| 1026 | goto out_err; |
| 1027 | } |
| 1028 | |
| 1029 | s = sget(fs_type, nfs_compare_super, nfs_set_super, server); |
| 1030 | if (IS_ERR(s) || s->s_root) |
| 1031 | goto out_rpciod_down; |
| 1032 | |
| 1033 | s->s_flags = flags; |
| 1034 | |
| 1035 | error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
| 1036 | if (error) { |
| 1037 | up_write(&s->s_umount); |
| 1038 | deactivate_super(s); |
| 1039 | return ERR_PTR(error); |
| 1040 | } |
| 1041 | s->s_flags |= MS_ACTIVE; |
| 1042 | return s; |
| 1043 | out_rpciod_down: |
| 1044 | rpciod_down(); |
| 1045 | out_err: |
| 1046 | kfree(server); |
| 1047 | return s; |
| 1048 | } |
| 1049 | |
| 1050 | static void nfs_kill_super(struct super_block *s) |
| 1051 | { |
| 1052 | struct nfs_server *server = NFS_SB(s); |
| 1053 | |
| 1054 | kill_anon_super(s); |
| 1055 | |
| 1056 | if (!IS_ERR(server->client)) |
| 1057 | rpc_shutdown_client(server->client); |
| 1058 | if (!IS_ERR(server->client_sys)) |
| 1059 | rpc_shutdown_client(server->client_sys); |
| 1060 | if (!IS_ERR(server->client_acl)) |
| 1061 | rpc_shutdown_client(server->client_acl); |
| 1062 | |
| 1063 | if (!(server->flags & NFS_MOUNT_NONLM)) |
| 1064 | lockd_down(); /* release rpc.lockd */ |
| 1065 | |
| 1066 | rpciod_down(); /* release rpciod */ |
| 1067 | |
| 1068 | nfs_free_iostats(server->io_stats); |
| 1069 | kfree(server->hostname); |
| 1070 | kfree(server); |
| 1071 | nfs_release_automount_timer(); |
| 1072 | } |
| 1073 | |
| 1074 | static struct super_block *nfs_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data) |
| 1075 | { |
| 1076 | struct super_block *sb; |
| 1077 | |
| 1078 | server->fsid = data->fattr->fsid; |
| 1079 | nfs_copy_fh(&server->fh, data->fh); |
| 1080 | sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server); |
| 1081 | if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM)) |
| 1082 | lockd_up(); |
| 1083 | return sb; |
| 1084 | } |
| 1085 | |
| 1086 | static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type, |
| 1087 | int flags, const char *dev_name, void *raw_data) |
| 1088 | { |
| 1089 | struct nfs_clone_mount *data = raw_data; |
| 1090 | return nfs_clone_generic_sb(data, nfs_clone_sb, nfs_clone_server); |
| 1091 | } |
| 1092 | |
| 1093 | #ifdef CONFIG_NFS_V4 |
| 1094 | static struct rpc_clnt *nfs4_create_client(struct nfs_server *server, |
| 1095 | struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor) |
| 1096 | { |
| 1097 | struct nfs4_client *clp; |
| 1098 | struct rpc_xprt *xprt = NULL; |
| 1099 | struct rpc_clnt *clnt = NULL; |
| 1100 | int err = -EIO; |
| 1101 | |
| 1102 | clp = nfs4_get_client(&server->addr.sin_addr); |
| 1103 | if (!clp) { |
| 1104 | dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__); |
| 1105 | return ERR_PTR(err); |
| 1106 | } |
| 1107 | |
| 1108 | /* Now create transport and client */ |
| 1109 | down_write(&clp->cl_sem); |
| 1110 | if (IS_ERR(clp->cl_rpcclient)) { |
| 1111 | xprt = xprt_create_proto(proto, &server->addr, timeparms); |
| 1112 | if (IS_ERR(xprt)) { |
| 1113 | up_write(&clp->cl_sem); |
| 1114 | err = PTR_ERR(xprt); |
| 1115 | dprintk("%s: cannot create RPC transport. Error = %d\n", |
| 1116 | __FUNCTION__, err); |
| 1117 | goto out_fail; |
| 1118 | } |
| 1119 | /* Bind to a reserved port! */ |
| 1120 | xprt->resvport = 1; |
| 1121 | clnt = rpc_create_client(xprt, server->hostname, &nfs_program, |
| 1122 | server->rpc_ops->version, flavor); |
| 1123 | if (IS_ERR(clnt)) { |
| 1124 | up_write(&clp->cl_sem); |
| 1125 | err = PTR_ERR(clnt); |
| 1126 | dprintk("%s: cannot create RPC client. Error = %d\n", |
| 1127 | __FUNCTION__, err); |
| 1128 | goto out_fail; |
| 1129 | } |
| 1130 | clnt->cl_intr = 1; |
| 1131 | clnt->cl_softrtry = 1; |
| 1132 | clp->cl_rpcclient = clnt; |
| 1133 | memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr)); |
| 1134 | nfs_idmap_new(clp); |
| 1135 | } |
| 1136 | list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); |
| 1137 | clnt = rpc_clone_client(clp->cl_rpcclient); |
| 1138 | if (!IS_ERR(clnt)) |
| 1139 | server->nfs4_state = clp; |
| 1140 | up_write(&clp->cl_sem); |
| 1141 | clp = NULL; |
| 1142 | |
| 1143 | if (IS_ERR(clnt)) { |
| 1144 | dprintk("%s: cannot create RPC client. Error = %d\n", |
| 1145 | __FUNCTION__, err); |
| 1146 | return clnt; |
| 1147 | } |
| 1148 | |
| 1149 | if (server->nfs4_state->cl_idmap == NULL) { |
| 1150 | dprintk("%s: failed to create idmapper.\n", __FUNCTION__); |
| 1151 | return ERR_PTR(-ENOMEM); |
| 1152 | } |
| 1153 | |
| 1154 | if (clnt->cl_auth->au_flavor != flavor) { |
| 1155 | struct rpc_auth *auth; |
| 1156 | |
| 1157 | auth = rpcauth_create(flavor, clnt); |
| 1158 | if (IS_ERR(auth)) { |
| 1159 | dprintk("%s: couldn't create credcache!\n", __FUNCTION__); |
| 1160 | return (struct rpc_clnt *)auth; |
| 1161 | } |
| 1162 | } |
| 1163 | return clnt; |
| 1164 | |
| 1165 | out_fail: |
| 1166 | if (clp) |
| 1167 | nfs4_put_client(clp); |
| 1168 | return ERR_PTR(err); |
| 1169 | } |
| 1170 | |
| 1171 | /* |
| 1172 | * Set up an NFS4 superblock |
| 1173 | */ |
| 1174 | static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent) |
| 1175 | { |
| 1176 | struct nfs_server *server; |
| 1177 | struct rpc_timeout timeparms; |
| 1178 | rpc_authflavor_t authflavour; |
| 1179 | int err = -EIO; |
| 1180 | |
| 1181 | sb->s_blocksize_bits = 0; |
| 1182 | sb->s_blocksize = 0; |
| 1183 | server = NFS_SB(sb); |
| 1184 | if (data->rsize != 0) |
| 1185 | server->rsize = nfs_block_size(data->rsize, NULL); |
| 1186 | if (data->wsize != 0) |
| 1187 | server->wsize = nfs_block_size(data->wsize, NULL); |
| 1188 | server->flags = data->flags & NFS_MOUNT_FLAGMASK; |
| 1189 | server->caps = NFS_CAP_ATOMIC_OPEN; |
| 1190 | |
| 1191 | server->acregmin = data->acregmin*HZ; |
| 1192 | server->acregmax = data->acregmax*HZ; |
| 1193 | server->acdirmin = data->acdirmin*HZ; |
| 1194 | server->acdirmax = data->acdirmax*HZ; |
| 1195 | |
| 1196 | server->rpc_ops = &nfs_v4_clientops; |
| 1197 | |
| 1198 | nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans); |
| 1199 | |
| 1200 | server->retrans_timeo = timeparms.to_initval; |
| 1201 | server->retrans_count = timeparms.to_retries; |
| 1202 | |
| 1203 | /* Now create transport and client */ |
| 1204 | authflavour = RPC_AUTH_UNIX; |
| 1205 | if (data->auth_flavourlen != 0) { |
| 1206 | if (data->auth_flavourlen != 1) { |
| 1207 | dprintk("%s: Invalid number of RPC auth flavours %d.\n", |
| 1208 | __FUNCTION__, data->auth_flavourlen); |
| 1209 | err = -EINVAL; |
| 1210 | goto out_fail; |
| 1211 | } |
| 1212 | if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) { |
| 1213 | err = -EFAULT; |
| 1214 | goto out_fail; |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour); |
| 1219 | if (IS_ERR(server->client)) { |
| 1220 | err = PTR_ERR(server->client); |
| 1221 | dprintk("%s: cannot create RPC client. Error = %d\n", |
| 1222 | __FUNCTION__, err); |
| 1223 | goto out_fail; |
| 1224 | } |
| 1225 | |
| 1226 | sb->s_time_gran = 1; |
| 1227 | |
| 1228 | sb->s_op = &nfs4_sops; |
| 1229 | err = nfs_sb_init(sb, authflavour); |
| 1230 | |
| 1231 | out_fail: |
| 1232 | return err; |
| 1233 | } |
| 1234 | |
| 1235 | static int nfs4_compare_super(struct super_block *sb, void *data) |
| 1236 | { |
| 1237 | struct nfs_server *server = data; |
| 1238 | struct nfs_server *old = NFS_SB(sb); |
| 1239 | |
| 1240 | if (strcmp(server->hostname, old->hostname) != 0) |
| 1241 | return 0; |
| 1242 | if (strcmp(server->mnt_path, old->mnt_path) != 0) |
| 1243 | return 0; |
| 1244 | return 1; |
| 1245 | } |
| 1246 | |
| 1247 | static void * |
| 1248 | nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen) |
| 1249 | { |
| 1250 | void *p = NULL; |
| 1251 | |
| 1252 | if (!src->len) |
| 1253 | return ERR_PTR(-EINVAL); |
| 1254 | if (src->len < maxlen) |
| 1255 | maxlen = src->len; |
| 1256 | if (dst == NULL) { |
| 1257 | p = dst = kmalloc(maxlen + 1, GFP_KERNEL); |
| 1258 | if (p == NULL) |
| 1259 | return ERR_PTR(-ENOMEM); |
| 1260 | } |
| 1261 | if (copy_from_user(dst, src->data, maxlen)) { |
| 1262 | kfree(p); |
| 1263 | return ERR_PTR(-EFAULT); |
| 1264 | } |
| 1265 | dst[maxlen] = '\0'; |
| 1266 | return dst; |
| 1267 | } |
| 1268 | |
| 1269 | static struct super_block *nfs4_get_sb(struct file_system_type *fs_type, |
| 1270 | int flags, const char *dev_name, void *raw_data) |
| 1271 | { |
| 1272 | int error; |
| 1273 | struct nfs_server *server; |
| 1274 | struct super_block *s; |
| 1275 | struct nfs4_mount_data *data = raw_data; |
| 1276 | void *p; |
| 1277 | |
| 1278 | if (data == NULL) { |
| 1279 | dprintk("%s: missing data argument\n", __FUNCTION__); |
| 1280 | return ERR_PTR(-EINVAL); |
| 1281 | } |
| 1282 | if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) { |
| 1283 | dprintk("%s: bad mount version\n", __FUNCTION__); |
| 1284 | return ERR_PTR(-EINVAL); |
| 1285 | } |
| 1286 | |
| 1287 | server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL); |
| 1288 | if (!server) |
| 1289 | return ERR_PTR(-ENOMEM); |
| 1290 | /* Zero out the NFS state stuff */ |
| 1291 | init_nfsv4_state(server); |
| 1292 | server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL); |
| 1293 | |
| 1294 | p = nfs_copy_user_string(NULL, &data->hostname, 256); |
| 1295 | if (IS_ERR(p)) |
| 1296 | goto out_err; |
| 1297 | server->hostname = p; |
| 1298 | |
| 1299 | p = nfs_copy_user_string(NULL, &data->mnt_path, 1024); |
| 1300 | if (IS_ERR(p)) |
| 1301 | goto out_err; |
| 1302 | server->mnt_path = p; |
| 1303 | |
| 1304 | p = nfs_copy_user_string(server->ip_addr, &data->client_addr, |
| 1305 | sizeof(server->ip_addr) - 1); |
| 1306 | if (IS_ERR(p)) |
| 1307 | goto out_err; |
| 1308 | |
| 1309 | /* We now require that the mount process passes the remote address */ |
| 1310 | if (data->host_addrlen != sizeof(server->addr)) { |
| 1311 | s = ERR_PTR(-EINVAL); |
| 1312 | goto out_free; |
| 1313 | } |
| 1314 | if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) { |
| 1315 | s = ERR_PTR(-EFAULT); |
| 1316 | goto out_free; |
| 1317 | } |
| 1318 | if (server->addr.sin_family != AF_INET || |
| 1319 | server->addr.sin_addr.s_addr == INADDR_ANY) { |
| 1320 | dprintk("%s: mount program didn't pass remote IP address!\n", |
| 1321 | __FUNCTION__); |
| 1322 | s = ERR_PTR(-EINVAL); |
| 1323 | goto out_free; |
| 1324 | } |
| 1325 | |
| 1326 | /* Fire up rpciod if not yet running */ |
| 1327 | s = ERR_PTR(rpciod_up()); |
| 1328 | if (IS_ERR(s)) { |
| 1329 | dprintk("%s: couldn't start rpciod! Error = %ld\n", |
| 1330 | __FUNCTION__, PTR_ERR(s)); |
| 1331 | goto out_free; |
| 1332 | } |
| 1333 | |
| 1334 | s = sget(fs_type, nfs4_compare_super, nfs_set_super, server); |
| 1335 | |
| 1336 | if (IS_ERR(s) || s->s_root) |
| 1337 | goto out_free; |
| 1338 | |
| 1339 | s->s_flags = flags; |
| 1340 | |
| 1341 | error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
| 1342 | if (error) { |
| 1343 | up_write(&s->s_umount); |
| 1344 | deactivate_super(s); |
| 1345 | return ERR_PTR(error); |
| 1346 | } |
| 1347 | s->s_flags |= MS_ACTIVE; |
| 1348 | return s; |
| 1349 | out_err: |
| 1350 | s = (struct super_block *)p; |
| 1351 | out_free: |
| 1352 | kfree(server->mnt_path); |
| 1353 | kfree(server->hostname); |
| 1354 | kfree(server); |
| 1355 | return s; |
| 1356 | } |
| 1357 | |
| 1358 | static void nfs4_kill_super(struct super_block *sb) |
| 1359 | { |
| 1360 | struct nfs_server *server = NFS_SB(sb); |
| 1361 | |
| 1362 | nfs_return_all_delegations(sb); |
| 1363 | kill_anon_super(sb); |
| 1364 | |
| 1365 | nfs4_renewd_prepare_shutdown(server); |
| 1366 | |
| 1367 | if (server->client != NULL && !IS_ERR(server->client)) |
| 1368 | rpc_shutdown_client(server->client); |
| 1369 | |
| 1370 | destroy_nfsv4_state(server); |
| 1371 | |
| 1372 | rpciod_down(); |
| 1373 | |
| 1374 | nfs_free_iostats(server->io_stats); |
| 1375 | kfree(server->hostname); |
| 1376 | kfree(server); |
| 1377 | nfs_release_automount_timer(); |
| 1378 | } |
| 1379 | |
| 1380 | /* |
| 1381 | * Constructs the SERVER-side path |
| 1382 | */ |
| 1383 | static inline char *nfs4_dup_path(const struct dentry *dentry) |
| 1384 | { |
| 1385 | char *page = (char *) __get_free_page(GFP_USER); |
| 1386 | char *path; |
| 1387 | |
| 1388 | path = nfs4_path(dentry, page, PAGE_SIZE); |
| 1389 | if (!IS_ERR(path)) { |
| 1390 | int len = PAGE_SIZE + page - path; |
| 1391 | char *tmp = path; |
| 1392 | |
| 1393 | path = kmalloc(len, GFP_KERNEL); |
| 1394 | if (path) |
| 1395 | memcpy(path, tmp, len); |
| 1396 | else |
| 1397 | path = ERR_PTR(-ENOMEM); |
| 1398 | } |
| 1399 | free_page((unsigned long)page); |
| 1400 | return path; |
| 1401 | } |
| 1402 | |
| 1403 | static struct super_block *nfs4_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data) |
| 1404 | { |
| 1405 | const struct dentry *dentry = data->dentry; |
| 1406 | struct nfs4_client *clp = server->nfs4_state; |
| 1407 | struct super_block *sb; |
| 1408 | |
| 1409 | server->fsid = data->fattr->fsid; |
| 1410 | nfs_copy_fh(&server->fh, data->fh); |
| 1411 | server->mnt_path = nfs4_dup_path(dentry); |
| 1412 | if (IS_ERR(server->mnt_path)) { |
| 1413 | sb = (struct super_block *)server->mnt_path; |
| 1414 | goto err; |
| 1415 | } |
| 1416 | sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server); |
| 1417 | if (IS_ERR(sb) || sb->s_root) |
| 1418 | goto free_path; |
| 1419 | nfs4_server_capabilities(server, &server->fh); |
| 1420 | |
| 1421 | down_write(&clp->cl_sem); |
| 1422 | atomic_inc(&clp->cl_count); |
| 1423 | list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks); |
| 1424 | up_write(&clp->cl_sem); |
| 1425 | return sb; |
| 1426 | free_path: |
| 1427 | kfree(server->mnt_path); |
| 1428 | err: |
| 1429 | server->mnt_path = NULL; |
| 1430 | return sb; |
| 1431 | } |
| 1432 | |
| 1433 | static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type, |
| 1434 | int flags, const char *dev_name, void *raw_data) |
| 1435 | { |
| 1436 | struct nfs_clone_mount *data = raw_data; |
| 1437 | return nfs_clone_generic_sb(data, nfs4_clone_sb, nfs_clone_server); |
| 1438 | } |
| 1439 | |
| 1440 | static struct super_block *nfs4_referral_sb(struct nfs_server *server, struct nfs_clone_mount *data) |
| 1441 | { |
| 1442 | struct super_block *sb = ERR_PTR(-ENOMEM); |
| 1443 | int len; |
| 1444 | |
| 1445 | len = strlen(data->mnt_path) + 1; |
| 1446 | server->mnt_path = kmalloc(len, GFP_KERNEL); |
| 1447 | if (server->mnt_path == NULL) |
| 1448 | goto err; |
| 1449 | memcpy(server->mnt_path, data->mnt_path, len); |
| 1450 | memcpy(&server->addr, data->addr, sizeof(struct sockaddr_in)); |
| 1451 | |
| 1452 | sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server); |
| 1453 | if (IS_ERR(sb) || sb->s_root) |
| 1454 | goto free_path; |
| 1455 | return sb; |
| 1456 | free_path: |
| 1457 | kfree(server->mnt_path); |
| 1458 | err: |
| 1459 | server->mnt_path = NULL; |
| 1460 | return sb; |
| 1461 | } |
| 1462 | |
| 1463 | static struct nfs_server *nfs4_referral_server(struct super_block *sb, struct nfs_clone_mount *data) |
| 1464 | { |
| 1465 | struct nfs_server *server = NFS_SB(sb); |
| 1466 | struct rpc_timeout timeparms; |
| 1467 | int proto, timeo, retrans; |
| 1468 | void *err; |
| 1469 | |
| 1470 | proto = IPPROTO_TCP; |
| 1471 | /* Since we are following a referral and there may be alternatives, |
| 1472 | set the timeouts and retries to low values */ |
| 1473 | timeo = 2; |
| 1474 | retrans = 1; |
| 1475 | nfs_init_timeout_values(&timeparms, proto, timeo, retrans); |
| 1476 | |
| 1477 | server->client = nfs4_create_client(server, &timeparms, proto, data->authflavor); |
| 1478 | if (IS_ERR((err = server->client))) |
| 1479 | goto out_err; |
| 1480 | |
| 1481 | sb->s_time_gran = 1; |
| 1482 | sb->s_op = &nfs4_sops; |
| 1483 | err = ERR_PTR(nfs_sb_init(sb, data->authflavor)); |
| 1484 | if (!IS_ERR(err)) |
| 1485 | return server; |
| 1486 | out_err: |
| 1487 | return (struct nfs_server *)err; |
| 1488 | } |
| 1489 | |
| 1490 | static struct super_block *nfs_referral_nfs4_sb(struct file_system_type *fs_type, |
| 1491 | int flags, const char *dev_name, void *raw_data) |
| 1492 | { |
| 1493 | struct nfs_clone_mount *data = raw_data; |
| 1494 | return nfs_clone_generic_sb(data, nfs4_referral_sb, nfs4_referral_server); |
| 1495 | } |
| 1496 | |
| 1497 | #endif |