Deleted Added
full compact
lockf.h (169660) lockf.h (177633)
1/*-
2 * Copyright (c) 1991, 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

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

25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)lockf.h 8.1 (Berkeley) 6/11/93
1/*-
2 * Copyright (c) 1991, 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

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

25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)lockf.h 8.1 (Berkeley) 6/11/93
33 * $FreeBSD: head/sys/sys/lockf.h 169660 2007-05-17 16:03:14Z csjp $
33 * $FreeBSD: head/sys/sys/lockf.h 177633 2008-03-26 15:23:12Z dfr $
34 */
35
36#ifndef _SYS_LOCKF_H_
37#define _SYS_LOCKF_H_
38
39#include <sys/queue.h>
34 */
35
36#ifndef _SYS_LOCKF_H_
37#define _SYS_LOCKF_H_
38
39#include <sys/queue.h>
40#include <sys/_lock.h>
41#include <sys/_sx.h>
40
41struct vop_advlock_args;
42
43struct vop_advlock_args;
44struct vop_advlockasync_args;
42
43/*
45
46/*
44 * The lockf structure is a kernel structure which contains the information
45 * associated with a byte range lock. The lockf structures are linked into
46 * the inode structure. Locks are sorted by the starting byte of the lock for
47 * efficiency.
47 * The lockf_entry structure is a kernel structure which contains the
48 * information associated with a byte range lock. The lockf_entry
49 * structures are linked into the inode structure. Locks are sorted by
50 * the starting byte of the lock for efficiency.
51 *
52 * Active and pending locks on a vnode are organised into a
53 * graph. Each pending lock has an out-going edge to each active lock
54 * that blocks it.
55 *
56 * Locks:
57 * (i) locked by the vnode interlock
58 * (s) locked by state->ls_lock
59 * (S) locked by lf_lock_states_lock
60 * (c) const until freeing
48 */
61 */
49TAILQ_HEAD(locklist, lockf);
62struct lockf_edge {
63 LIST_ENTRY(lockf_edge) le_outlink; /* (s) link from's out-edge list */
64 LIST_ENTRY(lockf_edge) le_inlink; /* (s) link to's in-edge list */
65 struct lockf_entry *le_from; /* (c) out-going from here */
66 struct lockf_entry *le_to; /* (s) in-coming to here */
67};
68LIST_HEAD(lockf_edge_list, lockf_edge);
50
69
51struct lockf {
52 short lf_flags; /* Semantics: F_POSIX, F_FLOCK, F_WAIT */
53 short lf_type; /* Lock type: F_RDLCK, F_WRLCK */
54 off_t lf_start; /* Byte # of the start of the lock */
55 off_t lf_end; /* Byte # of the end of the lock (-1=EOF) */
56 caddr_t lf_id; /* Id of the resource holding the lock */
57 struct lockf **lf_head; /* Back pointer to the head of the lockf list */
58 struct inode *lf_inode; /* Back pointer to the inode */
59 struct lockf *lf_next; /* Pointer to the next lock on this inode */
60 struct locklist lf_blkhd; /* List of requests blocked on this lock */
61 TAILQ_ENTRY(lockf) lf_block;/* A request waiting for a lock */
70struct lockf_entry {
71 short lf_flags; /* (c) Semantics: F_POSIX, F_FLOCK, F_WAIT */
72 short lf_type; /* (s) Lock type: F_RDLCK, F_WRLCK */
73 off_t lf_start; /* (s) Byte # of the start of the lock */
74 off_t lf_end; /* (s) Byte # of the end of the lock (OFF_MAX=EOF) */
75 struct lock_owner *lf_owner; /* (c) Owner of the lock */
76 struct vnode *lf_vnode; /* (c) File being locked (only valid for active lock) */
77 struct inode *lf_inode; /* (c) Back pointer to the inode */
78 struct task *lf_async_task;/* (c) Async lock callback */
79 LIST_ENTRY(lockf_entry) lf_link; /* (s) Linkage for lock lists */
80 struct lockf_edge_list lf_outedges; /* (s) list of out-edges */
81 struct lockf_edge_list lf_inedges; /* (s) list of out-edges */
62};
82};
83LIST_HEAD(lockf_entry_list, lockf_entry);
63
84
64/* Maximum length of sleep chains to traverse to try and detect deadlock. */
65#define MAXDEPTH 50
85/*
86 * Filesystem private node structures should include space for a
87 * pointer to a struct lockf_state. This pointer is used by the lock
88 * manager to track the locking state for a file.
89 *
90 * The ls_active list contains the set of active locks on the file. It
91 * is strictly ordered by the lock's lf_start value. Each active lock
92 * will have in-coming edges to any pending lock which it blocks.
93 *
94 * Lock requests which are blocked by some other active lock are
95 * listed in ls_pending with newer requests first in the list. Lock
96 * requests in this list will have out-going edges to each active lock
97 * that blocks then. They will also have out-going edges to each
98 * pending lock that is older in the queue - this helps to ensure
99 * fairness when several processes are contenting to lock the same
100 * record.
66
101
102 * The value of ls_threads is the number of threads currently using
103 * the state structure (typically either setting/clearing locks or
104 * sleeping waiting to do so). This is used to defer freeing the
105 * structure while some thread is still using it.
106 */
107struct lockf {
108 LIST_ENTRY(lockf) ls_link; /* (S) all active lockf states */
109 struct sx ls_lock;
110 struct lockf_entry_list ls_active; /* (s) Active locks */
111 struct lockf_entry_list ls_pending; /* (s) Pending locks */
112 int ls_threads; /* (i) Thread count */
113};
114LIST_HEAD(lockf_list, lockf);
115
67int lf_advlock(struct vop_advlock_args *, struct lockf **, u_quad_t);
116int lf_advlock(struct vop_advlock_args *, struct lockf **, u_quad_t);
117int lf_advlockasync(struct vop_advlockasync_args *, struct lockf **, u_quad_t);
118int lf_countlocks(int sysid);
119void lf_clearremotesys(int sysid);
68
69#endif /* !_SYS_LOCKF_H_ */
120
121#endif /* !_SYS_LOCKF_H_ */