2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_BEHAVIOR_H__
33 #define __XFS_BEHAVIOR_H__
36 * Header file used to associate behaviors with virtualized objects.
38 * A virtualized object is an internal, virtualized representation of
39 * OS entities such as persistent files, processes, or sockets. Examples
40 * of virtualized objects include vnodes, vprocs, and vsockets. Often
41 * a virtualized object is referred to simply as an "object."
43 * A behavior is essentially an implementation layer associated with
44 * an object. Multiple behaviors for an object are chained together,
45 * the order of chaining determining the order of invocation. Each
46 * behavior of a given object implements the same set of interfaces
47 * (e.g., the VOP interfaces).
49 * Behaviors may be dynamically inserted into an object's behavior chain,
50 * such that the addition is transparent to consumers that already have
51 * references to the object. Typically, a given behavior will be inserted
52 * at a particular location in the behavior chain. Insertion of new
53 * behaviors is synchronized with operations-in-progress (oip's) so that
54 * the oip's always see a consistent view of the chain.
56 * The term "interpostion" is used to refer to the act of inserting
57 * a behavior such that it interposes on (i.e., is inserted in front
58 * of) a particular other behavior. A key example of this is when a
59 * system implementing distributed single system image wishes to
60 * interpose a distribution layer (providing distributed coherency)
61 * in front of an object that is otherwise only accessed locally.
63 * Note that the traditional vnode/inode combination is simply a virtualized
64 * object that has exactly one associated behavior.
66 * Behavior synchronization is logic which is necessary under certain
67 * circumstances that there is no conflict between ongoing operations
68 * traversing the behavior chain and those dunamically modifying the
69 * behavior chain. Because behavior synchronization adds extra overhead
70 * to virtual operation invocation, we want to restrict, as much as
71 * we can, the requirement for this extra code, to those situations
72 * in which it is truly necessary.
74 * Behavior synchronization is needed whenever there's at least one class
75 * of object in the system for which:
76 * 1) multiple behaviors for a given object are supported,
78 * 2a) insertion of a new behavior can happen dynamically at any time during
79 * the life of an active object,
81 * 3a) insertion of a new behavior needs to synchronize with existing
84 * 3b) multiple different behaviors can be dynamically inserted at
85 * any time during the life of an active object
87 * 3c) removal of a behavior can occur at any time during the life of
90 * 2b) removal of a behavior can occur at any time during the life of an
98 * Behavior head. Head of the chain of behaviors.
99 * Contained within each virtualized object data structure.
101 typedef struct bhv_head
{
102 struct bhv_desc
*bh_first
; /* first behavior in chain */
103 struct bhv_head_lock
*bh_lockp
; /* pointer to lock info struct */
107 * Behavior descriptor. Descriptor associated with each behavior.
108 * Contained within the behavior's private data structure.
110 typedef struct bhv_desc
{
111 void *bd_pdata
; /* private data for this behavior */
112 void *bd_vobj
; /* virtual object associated with */
113 void *bd_ops
; /* ops for this behavior */
114 struct bhv_desc
*bd_next
; /* next behavior in chain */
118 * Behavior identity field. A behavior's identity determines the position
119 * where it lives within a behavior chain, and it's always the first field
120 * of the behavior's ops vector. The optional id field further identifies the
121 * subsystem responsible for the behavior.
123 typedef struct bhv_identity
{
124 __u16 bi_id
; /* owning subsystem id */
125 __u16 bi_position
; /* position in chain */
128 typedef bhv_identity_t bhv_position_t
;
130 #define BHV_IDENTITY_INIT(id,pos) {id, pos}
131 #define BHV_IDENTITY_INIT_POSITION(pos) BHV_IDENTITY_INIT(0, pos)
134 * Define boundaries of position values.
136 #define BHV_POSITION_INVALID 0 /* invalid position number */
137 #define BHV_POSITION_BASE 1 /* base (last) implementation layer */
138 #define BHV_POSITION_TOP 63 /* top (first) implementation layer */
143 #define BHV_HEAD_FIRST(bhp) (ASSERT((bhp)->bh_first), (bhp)->bh_first)
144 #define BHV_NEXT(bdp) (ASSERT((bdp)->bd_next), (bdp)->bd_next)
145 #define BHV_NEXTNULL(bdp) ((bdp)->bd_next)
146 #define BHV_VOBJ(bdp) (ASSERT((bdp)->bd_vobj), (bdp)->bd_vobj)
147 #define BHV_VOBJNULL(bdp) ((bdp)->bd_vobj)
148 #define BHV_PDATA(bdp) (bdp)->bd_pdata
149 #define BHV_OPS(bdp) (bdp)->bd_ops
150 #define BHV_IDENTITY(bdp) ((bhv_identity_t *)(bdp)->bd_ops)
151 #define BHV_POSITION(bdp) (BHV_IDENTITY(bdp)->bi_position)
153 extern void bhv_head_init(bhv_head_t
*, char *);
154 extern void bhv_head_destroy(bhv_head_t
*);
155 extern int bhv_insert(bhv_head_t
*, bhv_desc_t
*);
156 extern void bhv_insert_initial(bhv_head_t
*, bhv_desc_t
*);
159 * Initialize a new behavior descriptor.
161 * bdp - pointer to behavior descriptor
162 * pdata - pointer to behavior's private data
163 * vobj - pointer to associated virtual object
164 * ops - pointer to ops for this behavior
166 #define bhv_desc_init(bdp, pdata, vobj, ops) \
168 (bdp)->bd_pdata = pdata; \
169 (bdp)->bd_vobj = vobj; \
170 (bdp)->bd_ops = ops; \
171 (bdp)->bd_next = NULL; \
175 * Remove a behavior descriptor from a behavior chain.
177 #define bhv_remove(bhp, bdp) \
179 if ((bhp)->bh_first == (bdp)) { \
181 * Remove from front of chain. \
182 * Atomic wrt oip's. \
184 (bhp)->bh_first = (bdp)->bd_next; \
186 /* remove from non-front of chain */ \
187 bhv_remove_not_first(bhp, bdp); \
189 (bdp)->bd_vobj = NULL; \
193 * Behavior module prototypes.
195 extern void bhv_remove_not_first(bhv_head_t
*bhp
, bhv_desc_t
*bdp
);
196 extern bhv_desc_t
* bhv_lookup(bhv_head_t
*bhp
, void *ops
);
197 extern bhv_desc_t
* bhv_lookup_range(bhv_head_t
*bhp
, int low
, int high
);
198 extern bhv_desc_t
* bhv_base(bhv_head_t
*bhp
);
200 /* No bhv locking on Linux */
201 #define bhv_lookup_unlocked bhv_lookup
202 #define bhv_base_unlocked bhv_base
204 #endif /* __XFS_BEHAVIOR_H__ */