| 1714 | #endif |
| 1715 | |
| 1716 | void |
| 1717 | _lockmgr_assert(const struct lock *lk, int what, const char *file, int line) |
| 1718 | { |
| 1719 | int slocked = 0; |
| 1720 | |
| 1721 | if (KERNEL_PANICKED()) |
| 1722 | return; |
| 1723 | switch (what) { |
| 1724 | case KA_SLOCKED: |
| 1725 | case KA_SLOCKED | KA_NOTRECURSED: |
| 1726 | case KA_SLOCKED | KA_RECURSED: |
| 1727 | slocked = 1; |
| 1728 | case KA_LOCKED: |
| 1729 | case KA_LOCKED | KA_NOTRECURSED: |
| 1730 | case KA_LOCKED | KA_RECURSED: |
| 1731 | #ifdef WITNESS |
| 1732 | |
| 1733 | /* |
| 1734 | * We cannot trust WITNESS if the lock is held in exclusive |
| 1735 | * mode and a call to lockmgr_disown() happened. |
| 1736 | * Workaround this skipping the check if the lock is held in |
| 1737 | * exclusive mode even for the KA_LOCKED case. |
| 1738 | */ |
| 1739 | if (slocked || (lk->lk_lock & LK_SHARE)) { |
| 1740 | witness_assert(&lk->lock_object, what, file, line); |
| 1741 | break; |
| 1742 | } |
| 1743 | #endif |
| 1744 | if (lk->lk_lock == LK_UNLOCKED || |
| 1745 | ((lk->lk_lock & LK_SHARE) == 0 && (slocked || |
| 1746 | (!lockmgr_xlocked(lk) && !lockmgr_disowned(lk))))) |
| 1747 | panic("Lock %s not %slocked @ %s:%d\n", |
| 1748 | lk->lock_object.lo_name, slocked ? "share" : "", |
| 1749 | file, line); |
| 1750 | |
| 1751 | if ((lk->lk_lock & LK_SHARE) == 0) { |
| 1752 | if (lockmgr_recursed(lk)) { |
| 1753 | if (what & KA_NOTRECURSED) |
| 1754 | panic("Lock %s recursed @ %s:%d\n", |
| 1755 | lk->lock_object.lo_name, file, |
| 1756 | line); |
| 1757 | } else if (what & KA_RECURSED) |
| 1758 | panic("Lock %s not recursed @ %s:%d\n", |
| 1759 | lk->lock_object.lo_name, file, line); |
| 1760 | } |
| 1761 | break; |
| 1762 | case KA_XLOCKED: |
| 1763 | case KA_XLOCKED | KA_NOTRECURSED: |
| 1764 | case KA_XLOCKED | KA_RECURSED: |
| 1765 | if (!lockmgr_xlocked(lk) && !lockmgr_disowned(lk)) |
| 1766 | panic("Lock %s not exclusively locked @ %s:%d\n", |
| 1767 | lk->lock_object.lo_name, file, line); |
| 1768 | if (lockmgr_recursed(lk)) { |
| 1769 | if (what & KA_NOTRECURSED) |
| 1770 | panic("Lock %s recursed @ %s:%d\n", |
| 1771 | lk->lock_object.lo_name, file, line); |
| 1772 | } else if (what & KA_RECURSED) |
| 1773 | panic("Lock %s not recursed @ %s:%d\n", |
no test coverage detected