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