* Walk the list of locks for an inode to find an overlapping lock (if * any) and return a classification of that overlap. * * Arguments: * *overlap The place in the lock list to start looking * lock The lock which is being tested * type Pass 'SELF' to test only locks with the same * owner as lock, or 'OTHER' to test only locks * with a different owner * * Returns one of six values:
| 1698 | * may be more than one. |
| 1699 | */ |
| 1700 | static int |
| 1701 | lf_findoverlap(struct lockf_entry **overlap, struct lockf_entry *lock, int type) |
| 1702 | { |
| 1703 | struct lockf_entry *lf; |
| 1704 | off_t start, end; |
| 1705 | int res; |
| 1706 | |
| 1707 | if ((*overlap) == NOLOCKF) { |
| 1708 | return (0); |
| 1709 | } |
| 1710 | #ifdef LOCKF_DEBUG |
| 1711 | if (lockf_debug & 2) |
| 1712 | lf_print("lf_findoverlap: looking for overlap in", lock); |
| 1713 | #endif /* LOCKF_DEBUG */ |
| 1714 | start = lock->lf_start; |
| 1715 | end = lock->lf_end; |
| 1716 | res = 0; |
| 1717 | while (*overlap) { |
| 1718 | lf = *overlap; |
| 1719 | if (lf->lf_start > end) |
| 1720 | break; |
| 1721 | if (((type & SELF) && lf->lf_owner != lock->lf_owner) || |
| 1722 | ((type & OTHERS) && lf->lf_owner == lock->lf_owner)) { |
| 1723 | *overlap = LIST_NEXT(lf, lf_link); |
| 1724 | continue; |
| 1725 | } |
| 1726 | #ifdef LOCKF_DEBUG |
| 1727 | if (lockf_debug & 2) |
| 1728 | lf_print("\tchecking", lf); |
| 1729 | #endif /* LOCKF_DEBUG */ |
| 1730 | /* |
| 1731 | * OK, check for overlap |
| 1732 | * |
| 1733 | * Six cases: |
| 1734 | * 0) no overlap |
| 1735 | * 1) overlap == lock |
| 1736 | * 2) overlap contains lock |
| 1737 | * 3) lock contains overlap |
| 1738 | * 4) overlap starts before lock |
| 1739 | * 5) overlap ends after lock |
| 1740 | */ |
| 1741 | if (start > lf->lf_end) { |
| 1742 | /* Case 0 */ |
| 1743 | #ifdef LOCKF_DEBUG |
| 1744 | if (lockf_debug & 2) |
| 1745 | printf("no overlap\n"); |
| 1746 | #endif /* LOCKF_DEBUG */ |
| 1747 | *overlap = LIST_NEXT(lf, lf_link); |
| 1748 | continue; |
| 1749 | } |
| 1750 | if (lf->lf_start == start && lf->lf_end == end) { |
| 1751 | /* Case 1 */ |
| 1752 | #ifdef LOCKF_DEBUG |
| 1753 | if (lockf_debug & 2) |
| 1754 | printf("overlap == lock\n"); |
| 1755 | #endif /* LOCKF_DEBUG */ |
| 1756 | res = 1; |
| 1757 | break; |
no test coverage detected