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.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 |
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 *)); |
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 */ |
170static int |
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 */ |
412static int |
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 */ |
481static int |
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 */ |
515static struct lockf * |
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 */ |
545static int |
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 */ |
654static void |
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 */ |
683static void |
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 */ |
730static void |
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 --- |