MCPcopy Create free account
hub / github.com/F-Stack/f-stack / lf_split

Function lf_split

freebsd/kern/kern_lockf.c:1808–1859  ·  view source on GitHub ↗

* Split an the existing 'lock1', based on the extent of the lock * described by 'lock2'. The existing lock should cover 'lock2' * entirely. * * Any pending locks which have been been unblocked are added to * 'granted' */

Source from the content-addressed store, hash-verified

1806 * 'granted'
1807 */
1808static void
1809lf_split(struct lockf *state, struct lockf_entry *lock1,
1810 struct lockf_entry *lock2, struct lockf_entry_list *granted)
1811{
1812 struct lockf_entry *splitlock;
1813
1814#ifdef LOCKF_DEBUG
1815 if (lockf_debug & 2) {
1816 lf_print("lf_split", lock1);
1817 lf_print("splitting from", lock2);
1818 }
1819#endif /* LOCKF_DEBUG */
1820 /*
1821 * Check to see if we don't need to split at all.
1822 */
1823 if (lock1->lf_start == lock2->lf_start) {
1824 lf_set_start(state, lock1, lock2->lf_end + 1, granted);
1825 return;
1826 }
1827 if (lock1->lf_end == lock2->lf_end) {
1828 lf_set_end(state, lock1, lock2->lf_start - 1, granted);
1829 return;
1830 }
1831 /*
1832 * Make a new lock consisting of the last part of
1833 * the encompassing lock.
1834 */
1835 splitlock = lf_alloc_lock(lock1->lf_owner);
1836 memcpy(splitlock, lock1, sizeof *splitlock);
1837 splitlock->lf_refs = 1;
1838 if (splitlock->lf_flags & F_REMOTE)
1839 vref(splitlock->lf_vnode);
1840
1841 /*
1842 * This cannot cause a deadlock since any edges we would add
1843 * to splitlock already exist in lock1. We must be sure to add
1844 * necessary dependencies to splitlock before we reduce lock1
1845 * otherwise we may accidentally grant a pending lock that
1846 * was blocked by the tail end of lock1.
1847 */
1848 splitlock->lf_start = lock2->lf_end + 1;
1849 LIST_INIT(&splitlock->lf_outedges);
1850 LIST_INIT(&splitlock->lf_inedges);
1851 lf_add_incoming(state, splitlock);
1852
1853 lf_set_end(state, lock1, lock2->lf_start - 1, granted);
1854
1855 /*
1856 * OK, now link it in
1857 */
1858 lf_insert_lock(state, splitlock);
1859}
1860
1861struct lockdesc {
1862 STAILQ_ENTRY(lockdesc) link;

Callers 1

lf_activate_lockFunction · 0.85

Calls 8

lf_printFunction · 0.85
lf_set_startFunction · 0.85
lf_set_endFunction · 0.85
lf_alloc_lockFunction · 0.85
lf_add_incomingFunction · 0.85
lf_insert_lockFunction · 0.85
vrefFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected