2 * Copyright (c) 2004 Joerg Sonnenberger <joerg@bec.de>. All rights reserved.
3 * Copyright (c) 2006 Matthew Dillon <dillon@backplane.com>. All rights reserved.
5 * Copyright (c) 1982, 1986, 1989, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Scooter Morris at Genentech Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)ufs_lockf.c 8.3 (Berkeley) 1/6/94
36 * $FreeBSD: src/sys/kern/kern_lockf.c,v 1.25 1999/11/16 16:28:56 phk Exp $
39 #include "opt_debug_lockf.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
46 #include <sys/unistd.h>
47 #include <sys/vnode.h>
48 #include <sys/malloc.h>
49 #include <sys/fcntl.h>
50 #include <sys/resourcevar.h>
52 #include <sys/lockf.h>
53 #include <machine/limits.h> /* for LLONG_MAX */
54 #include <machine/stdarg.h>
56 #include <sys/spinlock2.h>
59 int lf_global_counter
= 0;
63 int lf_print_ranges
= 0;
65 static void _lf_print_lock(const struct lockf
*);
66 static void _lf_printf(const char *, ...) __printflike(1, 2);
68 #define lf_print_lock(lock) if (lf_print_ranges) _lf_print_lock(lock)
69 #define lf_printf(ctl, args...) if (lf_print_ranges) _lf_printf(ctl, args)
71 #define lf_print_lock(lock)
72 #define lf_printf(ctl, args...)
75 static MALLOC_DEFINE(M_LOCKF
, "lockf", "Byte-range locking structures");
77 static void lf_wakeup(struct lockf
*, off_t
, off_t
);
78 static struct lockf_range
*lf_alloc_range(void);
79 static void lf_create_range(struct lockf_range
*, struct proc
*, int, int,
81 static void lf_insert(struct lockf_range_list
*list
,
82 struct lockf_range
*elm
,
83 struct lockf_range
*insert_point
);
84 static void lf_destroy_range(struct lockf_range
*);
86 static int lf_setlock(struct lockf
*, struct proc
*, int, int,
88 static int lf_getlock(struct flock
*, struct lockf
*, struct proc
*,
89 int, int, off_t
, off_t
);
91 static int lf_count_change(struct proc
*, int);
94 * Return TRUE (non-zero) if the type and posix flags match.
98 lf_match(struct lockf_range
*range
, int type
, int flags
)
100 if (range
->lf_type
!= type
)
102 if ((range
->lf_flags
^ flags
) & F_POSIX
)
108 * Check whether range and [start, end] overlap.
112 lf_overlap(const struct lockf_range
*range
, off_t start
, off_t end
)
114 if (range
->lf_start
>= start
&& range
->lf_start
<= end
)
116 else if (start
>= range
->lf_start
&& start
<= range
->lf_end
)
124 * Change the POSIX lock accounting for the given process.
127 lf_count_adjust(struct proc
*p
, int increase
)
133 uip
= p
->p_ucred
->cr_uidinfo
;
135 atomic_add_int(&uip
->ui_posixlocks
, p
->p_numposixlocks
);
137 atomic_add_int(&uip
->ui_posixlocks
, -p
->p_numposixlocks
);
139 KASSERT(uip
->ui_posixlocks
>= 0,
140 ("Negative number of POSIX locks held by %s user: %d.",
141 increase
? "new" : "old", uip
->ui_posixlocks
));
145 lf_count_change(struct proc
*owner
, int diff
)
150 /* we might actually not have a process context */
154 uip
= owner
->p_ucred
->cr_uidinfo
;
156 max
= MIN(owner
->p_rlimit
[RLIMIT_POSIXLOCKS
].rlim_cur
,
157 maxposixlocksperuid
);
159 if (diff
> 0 && owner
->p_ucred
->cr_uid
!= 0 && max
!= -1 &&
160 uip
->ui_posixlocks
>= max
) {
163 atomic_add_int(&uip
->ui_posixlocks
, diff
);
164 atomic_add_int(&owner
->p_numposixlocks
, diff
);
165 KASSERT(uip
->ui_posixlocks
>= 0,
166 ("Negative number of POSIX locks held by user: %d.",
167 uip
->ui_posixlocks
));
168 KASSERT(owner
->p_numposixlocks
>= 0,
169 ("Negative number of POSIX locks held by proc: %d.",
170 uip
->ui_posixlocks
));
177 * Advisory record locking support
180 lf_advlock(struct vop_advlock_args
*ap
, struct lockf
*lock
, u_quad_t size
)
182 struct flock
*fl
= ap
->a_fl
;
185 int type
, flags
, error
;
189 * Convert the flock structure into a start and end.
191 switch (fl
->l_whence
) {
195 * Caller is responsible for adding any necessary offset
196 * when SEEK_CUR is used.
202 start
= size
+ fl
->l_start
;
212 if (fl
->l_len
== 0) {
215 } else if (fl
->l_len
< 0) {
218 end
= start
+ fl
->l_len
- 1;
225 * This isn't really correct for flock-style locks,
226 * but the current handling is somewhat broken anyway.
228 owner
= (struct proc
*)ap
->a_id
;
231 * Do the requested operation.
233 token
= lwkt_getpooltoken(lock
);
235 if (lock
->init_done
== 0) {
236 TAILQ_INIT(&lock
->lf_range
);
237 TAILQ_INIT(&lock
->lf_blocked
);
244 * NOTE: It is possible for both lf_range and lf_blocked to
245 * be empty if we block and get woken up, but another process
246 * then gets in and issues an unlock. So VMAYHAVELOCKS must
247 * be set after the lf_setlock() operation completes rather
250 error
= lf_setlock(lock
, owner
, type
, flags
, start
, end
);
251 vsetflags(ap
->a_vp
, VMAYHAVELOCKS
);
255 error
= lf_setlock(lock
, owner
, type
, flags
, start
, end
);
256 if (TAILQ_EMPTY(&lock
->lf_range
) &&
257 TAILQ_EMPTY(&lock
->lf_blocked
)) {
258 vclrflags(ap
->a_vp
, VMAYHAVELOCKS
);
263 error
= lf_getlock(fl
, lock
, owner
, type
, flags
, start
, end
);
270 lwkt_reltoken(token
);
275 lf_setlock(struct lockf
*lock
, struct proc
*owner
, int type
, int flags
,
276 off_t start
, off_t end
)
278 struct lockf_range
*range
;
279 struct lockf_range
*brange
;
280 struct lockf_range
*next
;
281 struct lockf_range
*first_match
;
282 struct lockf_range
*last_match
;
283 struct lockf_range
*insert_point
;
284 struct lockf_range
*new_range1
;
285 struct lockf_range
*new_range2
;
291 struct lockf_range_list deadlist
;
299 * Preallocate two ranges so we don't have to worry about blocking
300 * in the middle of the lock code.
302 if (new_range1
== NULL
)
303 new_range1
= lf_alloc_range();
304 if (new_range2
== NULL
)
305 new_range2
= lf_alloc_range();
314 * Locate the insertion point for the new lock (the first range
315 * with an lf_start >= start).
317 * Locate the first and latch ranges owned by us that overlap
318 * the requested range.
320 TAILQ_FOREACH(range
, &lock
->lf_range
, lf_link
) {
321 if (insert_point
== NULL
&& range
->lf_start
>= start
)
322 insert_point
= range
;
325 * Skip non-overlapping locks. Locks are sorted by lf_start
326 * So we can terminate the search when lf_start exceeds the
327 * requested range (insert_point is still guarenteed to be
330 if (range
->lf_end
< start
)
332 if (range
->lf_start
> end
) {
338 * Overlapping lock. Set first_match and last_match if we
341 if (range
->lf_owner
== owner
) {
342 if (first_match
== NULL
)
349 * If we aren't the owner check for a conflicting lock. Only
352 if (type
!= F_UNLCK
) {
353 if (type
== F_WRLCK
|| range
->lf_type
== F_WRLCK
)
359 * If a conflicting lock was observed, block or fail as appropriate.
360 * (this code is skipped when unlocking)
363 if ((flags
& F_WAIT
) == 0) {
369 * We are blocked. For POSIX locks we have to check
370 * for deadlocks and return with EDEADLK. This is done
371 * by checking whether range->lf_owner is already
374 * Since flock-style locks cover the whole file, a
375 * deadlock between those is nearly impossible.
376 * This can only occur if a process tries to lock the
377 * same inode exclusively while holding a shared lock
378 * with another descriptor.
379 * XXX How can we cleanly detect this?
380 * XXX The current mixing of flock & fcntl/lockf is evil.
382 * Handle existing locks of flock-style like POSIX locks.
384 if (flags
& F_POSIX
) {
385 TAILQ_FOREACH(brange
, &lock
->lf_blocked
, lf_link
) {
386 if (brange
->lf_owner
== range
->lf_owner
) {
394 * For flock-style locks, we must first remove
395 * any shared locks that we hold before we sleep
396 * waiting for an exclusive lock.
398 if ((flags
& F_POSIX
) == 0 && type
== F_WRLCK
)
399 lf_setlock(lock
, owner
, F_UNLCK
, 0, start
, end
);
403 lf_create_range(brange
, owner
, type
, 0, start
, end
);
404 TAILQ_INSERT_TAIL(&lock
->lf_blocked
, brange
, lf_link
);
405 error
= tsleep(brange
, PCATCH
, "lockf", 0);
408 * We may have been awaked by a signal and/or by a
409 * debugger continuing us (in which case we must remove
410 * ourselves from the blocked list) and/or by another
411 * process releasing/downgrading a lock (in which case
412 * we have already been removed from the blocked list
413 * and our lf_flags field is 1).
415 * Sleep if it looks like we might be livelocking.
417 if (brange
->lf_flags
== 0)
418 TAILQ_REMOVE(&lock
->lf_blocked
, brange
, lf_link
);
420 tsleep(brange
, 0, "lockfz", 2);
423 lf_destroy_range(brange
);
431 * If there are no overlapping locks owned by us then creating
432 * the new lock is easy. This is the most common case.
434 if (first_match
== NULL
) {
437 if (flags
& F_POSIX
) {
438 if (lf_count_change(owner
, 1)) {
445 lf_create_range(range
, owner
, type
, flags
, start
, end
);
446 lf_insert(&lock
->lf_range
, range
, insert_point
);
451 * double_clip - Calculate a special case where TWO locks may have
452 * to be added due to the new lock breaking up an
453 * existing incompatible lock in the middle.
455 * unlock_override - Calculate a special case where NO locks
456 * need to be created. This occurs when an unlock
457 * does not clip any locks at the front and rear.
459 * WARNING! closef() and fdrop() assume that an F_UNLCK of the
460 * entire range will always succeed so the unlock_override
465 if (first_match
->lf_start
< start
) {
466 if (first_match
== last_match
&& last_match
->lf_end
> end
)
468 } else if (type
== F_UNLCK
&& last_match
->lf_end
<= end
) {
473 * Figure out the worst case net increase in POSIX locks and account
474 * for it now before we start modifying things. If neither the
475 * first or last locks match we have an issue. If there is only
476 * one overlapping range which needs to be clipped on both ends
477 * we wind up having to create up to two new locks, else only one.
479 * When unlocking the worst case is always 1 new lock if our
480 * unlock request cuts the middle out of an existing lock range.
482 * count represents the 'cleanup' adjustment needed. It starts
483 * negative, is incremented whenever we create a new POSIX lock,
484 * and decremented whenever we delete an existing one. At the
485 * end of the day it had better be <= 0 or we didn't calculate the
486 * worse case properly here.
489 if ((flags
& F_POSIX
) && !unlock_override
) {
490 if (!lf_match(first_match
, type
, flags
) &&
491 !lf_match(last_match
, type
, flags
)
493 if (double_clip
&& type
!= F_UNLCK
)
498 if (count
&& lf_count_change(owner
, -count
)) {
503 /* else flock style lock which encompasses entire range */
506 * Create and insert the lock represented the requested range.
507 * Adjust the net POSIX lock count. We have to move our insertion
508 * point since brange now represents the first record >= start.
510 * When unlocking, no new lock is inserted but we still clip.
512 if (type
!= F_UNLCK
) {
515 lf_create_range(brange
, owner
, type
, flags
, start
, end
);
516 lf_insert(&lock
->lf_range
, brange
, insert_point
);
517 insert_point
= brange
;
525 * Handle the double_clip case. This is the only case where
526 * we wind up having to add TWO locks.
529 KKASSERT(first_match
== last_match
);
530 last_match
= new_range2
;
532 lf_create_range(last_match
, first_match
->lf_owner
,
533 first_match
->lf_type
, first_match
->lf_flags
,
534 end
+ 1, first_match
->lf_end
);
535 first_match
->lf_end
= start
- 1;
536 first_match
->lf_flags
&= ~F_NOEND
;
539 * Figure out where to insert the right side clip.
541 lf_insert(&lock
->lf_range
, last_match
, first_match
);
542 if (last_match
->lf_flags
& F_POSIX
)
547 * Clip or destroy the locks between first_match and last_match,
548 * inclusive. Ignore the primary lock we created (brange). Note
549 * that if double-clipped, first_match and last_match will be
550 * outside our clipping range. Otherwise first_match and last_match
553 * We have already taken care of any double clipping.
555 * The insert_point may become invalid as we delete records, do not
556 * use that pointer any more. Also, when removing something other
557 * then 'range' we have to check to see if the item we are removing
558 * is 'next' and adjust 'next' properly.
560 * NOTE: brange will be NULL if F_UNLCKing.
562 TAILQ_INIT(&deadlist
);
565 while ((range
= next
) != NULL
) {
566 next
= TAILQ_NEXT(range
, lf_link
);
569 * Ignore elements that we do not own and ignore the
570 * primary request range which we just created.
572 if (range
->lf_owner
!= owner
|| range
== brange
)
576 * We may have to wakeup a waiter when downgrading a lock.
580 if (type
== F_RDLCK
&& range
->lf_type
== F_WRLCK
)
584 * Clip left. This can only occur on first_match.
586 * Merge the left clip with brange if possible. This must
587 * be done specifically, not in the optimized merge heuristic
588 * below, since we may have counted on it in our 'count'
591 if (range
->lf_start
< start
) {
592 KKASSERT(range
== first_match
);
594 range
->lf_end
>= start
- 1 &&
595 lf_match(range
, type
, flags
)) {
596 range
->lf_end
= brange
->lf_end
;
597 range
->lf_flags
|= brange
->lf_flags
& F_NOEND
;
599 * Removing something other then 'range',
600 * adjust 'next' if necessary.
603 next
= TAILQ_NEXT(next
, lf_link
);
604 TAILQ_REMOVE(&lock
->lf_range
, brange
, lf_link
);
605 if (brange
->lf_flags
& F_POSIX
)
607 TAILQ_INSERT_TAIL(&deadlist
, brange
, lf_link
);
609 } else if (range
->lf_end
>= start
) {
610 range
->lf_end
= start
- 1;
612 range
->lf_flags
&= ~F_NOEND
;
614 if (range
== last_match
)
620 * Clip right. This can only occur on last_match.
622 * Merge the right clip if possible. This must be done
623 * specifically, not in the optimized merge heuristic
624 * below, since we may have counted on it in our 'count'
627 * Since we are adjusting lf_start, we have to move the
628 * record to maintain the sorted list. Since lf_start is
629 * only getting larger we can use the next element as the
630 * insert point (we don't have to backtrack).
632 if (range
->lf_end
> end
) {
633 KKASSERT(range
== last_match
);
635 range
->lf_start
<= end
+ 1 &&
636 lf_match(range
, type
, flags
)) {
637 brange
->lf_end
= range
->lf_end
;
638 brange
->lf_flags
|= range
->lf_flags
& F_NOEND
;
639 TAILQ_REMOVE(&lock
->lf_range
, range
, lf_link
);
640 if (range
->lf_flags
& F_POSIX
)
642 TAILQ_INSERT_TAIL(&deadlist
, range
, lf_link
);
643 } else if (range
->lf_start
<= end
) {
644 range
->lf_start
= end
+ 1;
645 TAILQ_REMOVE(&lock
->lf_range
, range
, lf_link
);
646 lf_insert(&lock
->lf_range
, range
, next
);
648 /* range == last_match, we are done */
653 * The record must be entirely enclosed. Note that the
654 * record could be first_match or last_match, and will be
657 KKASSERT(range
->lf_start
>= start
&& range
->lf_end
<= end
);
658 TAILQ_REMOVE(&lock
->lf_range
, range
, lf_link
);
659 if (range
->lf_flags
& F_POSIX
)
661 TAILQ_INSERT_TAIL(&deadlist
, range
, lf_link
);
662 if (range
== last_match
)
667 * Attempt to merge locks adjacent to brange. For example, we may
668 * have had to clip first_match and/or last_match, and they might
669 * be adjacent. Or there might simply have been an adjacent lock
672 * Don't get fancy, just check adjacent elements in the list if they
673 * happen to be owned by us.
675 * This case only gets hit if we have a situation where a shared
676 * and exclusive lock are adjacent, and the exclusive lock is
677 * downgraded to shared or the shared lock is upgraded to exclusive.
680 range
= TAILQ_PREV(brange
, lockf_range_list
, lf_link
);
682 range
->lf_owner
== owner
&&
683 range
->lf_end
== brange
->lf_start
- 1 &&
684 lf_match(range
, type
, flags
)
687 * Extend range to cover brange and scrap brange.
689 range
->lf_end
= brange
->lf_end
;
690 range
->lf_flags
|= brange
->lf_flags
& F_NOEND
;
691 TAILQ_REMOVE(&lock
->lf_range
, brange
, lf_link
);
692 if (brange
->lf_flags
& F_POSIX
)
694 TAILQ_INSERT_TAIL(&deadlist
, brange
, lf_link
);
697 range
= TAILQ_NEXT(brange
, lf_link
);
699 range
->lf_owner
== owner
&&
700 range
->lf_start
== brange
->lf_end
+ 1 &&
701 lf_match(range
, type
, flags
)
704 * Extend brange to cover range and scrap range.
706 brange
->lf_end
= range
->lf_end
;
707 brange
->lf_flags
|= range
->lf_flags
& F_NOEND
;
708 TAILQ_REMOVE(&lock
->lf_range
, range
, lf_link
);
709 if (range
->lf_flags
& F_POSIX
)
711 TAILQ_INSERT_TAIL(&deadlist
, range
, lf_link
);
716 * Destroy deleted elements. We didn't want to do it in the loop
717 * because the free() might have blocked.
719 * Adjust the count for any posix locks we thought we might create
722 while ((range
= TAILQ_FIRST(&deadlist
)) != NULL
) {
723 TAILQ_REMOVE(&deadlist
, range
, lf_link
);
724 lf_destroy_range(range
);
727 KKASSERT(count
<= 0);
729 lf_count_change(owner
, count
);
733 lf_wakeup(lock
, start
, end
);
736 if (new_range1
!= NULL
)
737 lf_destroy_range(new_range1
);
738 if (new_range2
!= NULL
)
739 lf_destroy_range(new_range2
);
744 * Check whether there is a blocking lock,
745 * and if so return its process identifier.
748 lf_getlock(struct flock
*fl
, struct lockf
*lock
, struct proc
*owner
,
749 int type
, int flags
, off_t start
, off_t end
)
751 struct lockf_range
*range
;
753 TAILQ_FOREACH(range
, &lock
->lf_range
, lf_link
)
754 if (range
->lf_owner
!= owner
&&
755 lf_overlap(range
, start
, end
) &&
756 (type
== F_WRLCK
|| range
->lf_type
== F_WRLCK
))
759 fl
->l_type
= F_UNLCK
;
762 fl
->l_type
= range
->lf_type
;
763 fl
->l_whence
= SEEK_SET
;
764 fl
->l_start
= range
->lf_start
;
765 if (range
->lf_flags
& F_NOEND
)
768 fl
->l_len
= range
->lf_end
- range
->lf_start
+ 1;
769 if (range
->lf_owner
!= NULL
&& (range
->lf_flags
& F_POSIX
))
770 fl
->l_pid
= range
->lf_owner
->p_pid
;
777 * Wakeup pending lock attempts. Theoretically we can stop as soon as
778 * we encounter an exclusive request that covers the whole range (at least
779 * insofar as the sleep code above calls lf_wakeup() if it would otherwise
780 * exit instead of loop), but for now just wakeup all overlapping
784 lf_wakeup(struct lockf
*lock
, off_t start
, off_t end
)
786 struct lockf_range
*range
, *nrange
;
788 TAILQ_FOREACH_MUTABLE(range
, &lock
->lf_blocked
, lf_link
, nrange
) {
789 if (lf_overlap(range
, start
, end
) == 0)
791 TAILQ_REMOVE(&lock
->lf_blocked
, range
, lf_link
);
798 * Allocate a range structure and initialize it sufficiently such that
799 * lf_destroy_range() does not barf.
801 static struct lockf_range
*
804 struct lockf_range
*range
;
807 atomic_add_int(&lf_global_counter
, 1);
809 range
= kmalloc(sizeof(struct lockf_range
), M_LOCKF
, M_WAITOK
);
810 range
->lf_owner
= NULL
;
815 lf_insert(struct lockf_range_list
*list
, struct lockf_range
*elm
,
816 struct lockf_range
*insert_point
)
818 while (insert_point
&& insert_point
->lf_start
< elm
->lf_start
)
819 insert_point
= TAILQ_NEXT(insert_point
, lf_link
);
820 if (insert_point
!= NULL
)
821 TAILQ_INSERT_BEFORE(insert_point
, elm
, lf_link
);
823 TAILQ_INSERT_TAIL(list
, elm
, lf_link
);
827 lf_create_range(struct lockf_range
*range
, struct proc
*owner
, int type
,
828 int flags
, off_t start
, off_t end
)
830 KKASSERT(start
<= end
);
831 range
->lf_type
= type
;
832 range
->lf_flags
= flags
;
833 range
->lf_start
= start
;
835 range
->lf_owner
= owner
;
837 lf_printf("lf_create_range: %ju..%ju\n",
838 (uintmax_t)range
->lf_start
, (uintmax_t)range
->lf_end
);
842 lf_destroy_range(struct lockf_range
*range
)
844 lf_printf("lf_destroy_range: %ju..%ju\n",
845 (uintmax_t)range
->lf_start
, (uintmax_t)range
->lf_end
);
846 kfree(range
, M_LOCKF
);
848 atomic_add_int(&lf_global_counter
, -1);
849 KKASSERT(lf_global_counter
>= 0);
856 _lf_printf(const char *ctl
, ...)
861 if (lf_print_ranges
) {
862 if ((p
= curproc
) != NULL
)
863 kprintf("pid %d (%s): ", p
->p_pid
, p
->p_comm
);
871 _lf_print_lock(const struct lockf
*lock
)
873 struct lockf_range
*range
;
875 if (lf_print_ranges
== 0)
878 if (TAILQ_EMPTY(&lock
->lf_range
)) {
879 lf_printf("lockf %p: no ranges locked\n", lock
);
881 lf_printf("lockf %p:\n", lock
);
883 TAILQ_FOREACH(range
, &lock
->lf_range
, lf_link
)
884 kprintf("\t%jd..%jd type %s owned by %d\n",
885 (uintmax_t)range
->lf_start
, (uintmax_t)range
->lf_end
,
886 range
->lf_type
== F_RDLCK
? "shared" : "exclusive",
887 range
->lf_flags
& F_POSIX
? range
->lf_owner
->p_pid
: -1);
888 if (TAILQ_EMPTY(&lock
->lf_blocked
))
889 kprintf("no process waiting for range\n");
891 kprintf("blocked locks:");
892 TAILQ_FOREACH(range
, &lock
->lf_blocked
, lf_link
)
893 kprintf("\t%jd..%jd type %s waiting on %p\n",
894 (uintmax_t)range
->lf_start
, (uintmax_t)range
->lf_end
,
895 range
->lf_type
== F_RDLCK
? "shared" : "exclusive",
898 #endif /* LOCKF_DEBUG */