* Destroy the mount struct previously allocated by vfs_mount_alloc(). */
| 536 | * Destroy the mount struct previously allocated by vfs_mount_alloc(). |
| 537 | */ |
| 538 | void |
| 539 | vfs_mount_destroy(struct mount *mp) |
| 540 | { |
| 541 | |
| 542 | if (mp->mnt_vfs_ops == 0) |
| 543 | panic("%s: entered with zero vfs_ops\n", __func__); |
| 544 | |
| 545 | vfs_assert_mount_counters(mp); |
| 546 | |
| 547 | MNT_ILOCK(mp); |
| 548 | mp->mnt_kern_flag |= MNTK_REFEXPIRE; |
| 549 | if (mp->mnt_kern_flag & MNTK_MWAIT) { |
| 550 | mp->mnt_kern_flag &= ~MNTK_MWAIT; |
| 551 | wakeup(mp); |
| 552 | } |
| 553 | while (mp->mnt_ref) |
| 554 | msleep(mp, MNT_MTX(mp), PVFS, "mntref", 0); |
| 555 | KASSERT(mp->mnt_ref == 0, |
| 556 | ("%s: invalid refcount in the drain path @ %s:%d", __func__, |
| 557 | __FILE__, __LINE__)); |
| 558 | if (mp->mnt_writeopcount != 0) |
| 559 | panic("vfs_mount_destroy: nonzero writeopcount"); |
| 560 | if (mp->mnt_secondary_writes != 0) |
| 561 | panic("vfs_mount_destroy: nonzero secondary_writes"); |
| 562 | atomic_subtract_rel_int(&mp->mnt_vfc->vfc_refcount, 1); |
| 563 | if (!TAILQ_EMPTY(&mp->mnt_nvnodelist)) { |
| 564 | struct vnode *vp; |
| 565 | |
| 566 | TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) |
| 567 | vn_printf(vp, "dangling vnode "); |
| 568 | panic("unmount: dangling vnode"); |
| 569 | } |
| 570 | KASSERT(TAILQ_EMPTY(&mp->mnt_uppers), ("mnt_uppers")); |
| 571 | if (mp->mnt_nvnodelistsize != 0) |
| 572 | panic("vfs_mount_destroy: nonzero nvnodelistsize"); |
| 573 | if (mp->mnt_lazyvnodelistsize != 0) |
| 574 | panic("vfs_mount_destroy: nonzero lazyvnodelistsize"); |
| 575 | if (mp->mnt_lockref != 0) |
| 576 | panic("vfs_mount_destroy: nonzero lock refcount"); |
| 577 | MNT_IUNLOCK(mp); |
| 578 | |
| 579 | if (mp->mnt_vfs_ops != 1) |
| 580 | panic("%s: vfs_ops should be 1 but %d found\n", __func__, |
| 581 | mp->mnt_vfs_ops); |
| 582 | |
| 583 | if (mp->mnt_rootvnode != NULL) |
| 584 | panic("%s: mount point still has a root vnode %p\n", __func__, |
| 585 | mp->mnt_rootvnode); |
| 586 | |
| 587 | if (mp->mnt_vnodecovered != NULL) |
| 588 | vrele(mp->mnt_vnodecovered); |
| 589 | #ifdef MAC |
| 590 | mac_mount_destroy(mp); |
| 591 | #endif |
| 592 | if (mp->mnt_opt != NULL) |
| 593 | vfs_freeopts(mp->mnt_opt); |
| 594 | crfree(mp->mnt_cred); |
| 595 | uma_zfree(mount_zone, mp); |
no test coverage detected