Deleted Added
full compact
kern_lockf.c (8876) kern_lockf.c (12819)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Scooter Morris at Genentech Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)ufs_lockf.c 8.3 (Berkeley) 1/6/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Scooter Morris at Genentech Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)ufs_lockf.c 8.3 (Berkeley) 1/6/94
37 * $Id: kern_lockf.c,v 1.3 1994/10/25 11:27:51 davidg Exp $
37 * $Id: kern_lockf.c,v 1.4 1995/05/30 08:05:31 rgrimes Exp $
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/file.h>
44#include <sys/proc.h>
45#include <sys/vnode.h>

--- 10 unchanged lines hidden (view full) ---

56
57#ifdef LOCKF_DEBUG
58int lockf_debug = 0;
59#endif
60
61#define NOLOCKF (struct lockf *)0
62#define SELF 0x1
63#define OTHERS 0x2
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/file.h>
44#include <sys/proc.h>
45#include <sys/vnode.h>

--- 10 unchanged lines hidden (view full) ---

56
57#ifdef LOCKF_DEBUG
58int lockf_debug = 0;
59#endif
60
61#define NOLOCKF (struct lockf *)0
62#define SELF 0x1
63#define OTHERS 0x2
64static void lf_addblock __P((struct lockf *, struct lockf *));
65static int lf_clearlock __P((struct lockf *));
66static int lf_findoverlap __P((struct lockf *,
67 struct lockf *, int, struct lockf ***, struct lockf **));
68static struct lockf *
69 lf_getblock __P((struct lockf *));
70static int lf_getlock __P((struct lockf *, struct flock *));
71static int lf_setlock __P((struct lockf *));
72static void lf_split __P((struct lockf *, struct lockf *));
73static void lf_wakelock __P((struct lockf *));
64
65/*
66 * Advisory record locking support
67 */
68int
69lf_advlock(ap, head, size)
70 struct vop_advlock_args /* {
71 struct vnode *a_vp;

--- 80 unchanged lines hidden (view full) ---

152 return (EINVAL);
153 }
154 /* NOTREACHED */
155}
156
157/*
158 * Set a byte-range lock.
159 */
74
75/*
76 * Advisory record locking support
77 */
78int
79lf_advlock(ap, head, size)
80 struct vop_advlock_args /* {
81 struct vnode *a_vp;

--- 80 unchanged lines hidden (view full) ---

162 return (EINVAL);
163 }
164 /* NOTREACHED */
165}
166
167/*
168 * Set a byte-range lock.
169 */
160int
170static int
161lf_setlock(lock)
162 register struct lockf *lock;
163{
164 register struct lockf *block;
165 struct lockf **head = lock->lf_head;
166 struct lockf **prev, *overlap, *ltmp;
167 static char lockstr[] = "lockf";
168 int ovcase, priority, needtolink, error;

--- 225 unchanged lines hidden (view full) ---

394}
395
396/*
397 * Remove a byte-range lock on an inode.
398 *
399 * Generally, find the lock (or an overlap to that lock)
400 * and remove it (or shrink it), then wakeup anyone we can.
401 */
171lf_setlock(lock)
172 register struct lockf *lock;
173{
174 register struct lockf *block;
175 struct lockf **head = lock->lf_head;
176 struct lockf **prev, *overlap, *ltmp;
177 static char lockstr[] = "lockf";
178 int ovcase, priority, needtolink, error;

--- 225 unchanged lines hidden (view full) ---

404}
405
406/*
407 * Remove a byte-range lock on an inode.
408 *
409 * Generally, find the lock (or an overlap to that lock)
410 * and remove it (or shrink it), then wakeup anyone we can.
411 */
402int
412static int
403lf_clearlock(unlock)
404 register struct lockf *unlock;
405{
406 struct lockf **head = unlock->lf_head;
407 register struct lockf *lf = *head;
408 struct lockf *overlap, **prev;
409 int ovcase;
410

--- 52 unchanged lines hidden (view full) ---

463#endif /* LOCKF_DEBUG */
464 return (0);
465}
466
467/*
468 * Check whether there is a blocking lock,
469 * and if so return its process identifier.
470 */
413lf_clearlock(unlock)
414 register struct lockf *unlock;
415{
416 struct lockf **head = unlock->lf_head;
417 register struct lockf *lf = *head;
418 struct lockf *overlap, **prev;
419 int ovcase;
420

--- 52 unchanged lines hidden (view full) ---

473#endif /* LOCKF_DEBUG */
474 return (0);
475}
476
477/*
478 * Check whether there is a blocking lock,
479 * and if so return its process identifier.
480 */
471int
481static int
472lf_getlock(lock, fl)
473 register struct lockf *lock;
474 register struct flock *fl;
475{
476 register struct lockf *block;
477
478#ifdef LOCKF_DEBUG
479 if (lockf_debug & 1)

--- 17 unchanged lines hidden (view full) ---

497 }
498 return (0);
499}
500
501/*
502 * Walk the list of locks for an inode and
503 * return the first blocking lock.
504 */
482lf_getlock(lock, fl)
483 register struct lockf *lock;
484 register struct flock *fl;
485{
486 register struct lockf *block;
487
488#ifdef LOCKF_DEBUG
489 if (lockf_debug & 1)

--- 17 unchanged lines hidden (view full) ---

507 }
508 return (0);
509}
510
511/*
512 * Walk the list of locks for an inode and
513 * return the first blocking lock.
514 */
505struct lockf *
515static struct lockf *
506lf_getblock(lock)
507 register struct lockf *lock;
508{
509 struct lockf **prev, *overlap, *lf = *(lock->lf_head);
510 int ovcase;
511
512 prev = lock->lf_head;
513 while ((ovcase = lf_findoverlap(lf, lock, OTHERS, &prev, &overlap))) {

--- 13 unchanged lines hidden (view full) ---

527
528/*
529 * Walk the list of locks for an inode to
530 * find an overlapping lock (if any).
531 *
532 * NOTE: this returns only the FIRST overlapping lock. There
533 * may be more than one.
534 */
516lf_getblock(lock)
517 register struct lockf *lock;
518{
519 struct lockf **prev, *overlap, *lf = *(lock->lf_head);
520 int ovcase;
521
522 prev = lock->lf_head;
523 while ((ovcase = lf_findoverlap(lf, lock, OTHERS, &prev, &overlap))) {

--- 13 unchanged lines hidden (view full) ---

537
538/*
539 * Walk the list of locks for an inode to
540 * find an overlapping lock (if any).
541 *
542 * NOTE: this returns only the FIRST overlapping lock. There
543 * may be more than one.
544 */
535int
545static int
536lf_findoverlap(lf, lock, type, prev, overlap)
537 register struct lockf *lf;
538 struct lockf *lock;
539 int type;
540 struct lockf ***prev;
541 struct lockf **overlap;
542{
543 off_t start, end;

--- 92 unchanged lines hidden (view full) ---

636 panic("lf_findoverlap: default");
637 }
638 return (0);
639}
640
641/*
642 * Add a lock to the end of the blocked list.
643 */
546lf_findoverlap(lf, lock, type, prev, overlap)
547 register struct lockf *lf;
548 struct lockf *lock;
549 int type;
550 struct lockf ***prev;
551 struct lockf **overlap;
552{
553 off_t start, end;

--- 92 unchanged lines hidden (view full) ---

646 panic("lf_findoverlap: default");
647 }
648 return (0);
649}
650
651/*
652 * Add a lock to the end of the blocked list.
653 */
644void
654static void
645lf_addblock(blocklist, lock)
646 struct lockf *blocklist;
647 struct lockf *lock;
648{
649 register struct lockf *lf;
650
651 if (lock == NOLOCKF)
652 return;

--- 12 unchanged lines hidden (view full) ---

665 lf->lf_block = lock;
666 return;
667}
668
669/*
670 * Split a lock and a contained region into
671 * two or three locks as necessary.
672 */
655lf_addblock(blocklist, lock)
656 struct lockf *blocklist;
657 struct lockf *lock;
658{
659 register struct lockf *lf;
660
661 if (lock == NOLOCKF)
662 return;

--- 12 unchanged lines hidden (view full) ---

675 lf->lf_block = lock;
676 return;
677}
678
679/*
680 * Split a lock and a contained region into
681 * two or three locks as necessary.
682 */
673void
683static void
674lf_split(lock1, lock2)
675 register struct lockf *lock1;
676 register struct lockf *lock2;
677{
678 register struct lockf *splitlock;
679
680#ifdef LOCKF_DEBUG
681 if (lockf_debug & 2) {

--- 30 unchanged lines hidden (view full) ---

712 splitlock->lf_next = lock1->lf_next;
713 lock2->lf_next = splitlock;
714 lock1->lf_next = lock2;
715}
716
717/*
718 * Wakeup a blocklist
719 */
684lf_split(lock1, lock2)
685 register struct lockf *lock1;
686 register struct lockf *lock2;
687{
688 register struct lockf *splitlock;
689
690#ifdef LOCKF_DEBUG
691 if (lockf_debug & 2) {

--- 30 unchanged lines hidden (view full) ---

722 splitlock->lf_next = lock1->lf_next;
723 lock2->lf_next = splitlock;
724 lock1->lf_next = lock2;
725}
726
727/*
728 * Wakeup a blocklist
729 */
720void
730static void
721lf_wakelock(listhead)
722 struct lockf *listhead;
723{
724 register struct lockf *blocklist, *wakelock;
725
726 blocklist = listhead->lf_block;
727 listhead->lf_block = NOLOCKF;
728 while (blocklist != NOLOCKF) {

--- 70 unchanged lines hidden ---
731lf_wakelock(listhead)
732 struct lockf *listhead;
733{
734 register struct lockf *blocklist, *wakelock;
735
736 blocklist = listhead->lf_block;
737 listhead->lf_block = NOLOCKF;
738 while (blocklist != NOLOCKF) {

--- 70 unchanged lines hidden ---