2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef __XFS_BEHAVIOR_H__
19 #define __XFS_BEHAVIOR_H__
22 * Header file used to associate behaviors with virtualized objects.
24 * A virtualized object is an internal, virtualized representation of
25 * OS entities such as persistent files, processes, or sockets. Examples
26 * of virtualized objects include vnodes, vprocs, and vsockets. Often
27 * a virtualized object is referred to simply as an "object."
29 * A behavior is essentially an implementation layer associated with
30 * an object. Multiple behaviors for an object are chained together,
31 * the order of chaining determining the order of invocation. Each
32 * behavior of a given object implements the same set of interfaces
33 * (e.g., the VOP interfaces).
35 * Behaviors may be dynamically inserted into an object's behavior chain,
36 * such that the addition is transparent to consumers that already have
37 * references to the object. Typically, a given behavior will be inserted
38 * at a particular location in the behavior chain. Insertion of new
39 * behaviors is synchronized with operations-in-progress (oip's) so that
40 * the oip's always see a consistent view of the chain.
42 * The term "interposition" is used to refer to the act of inserting
43 * a behavior such that it interposes on (i.e., is inserted in front
44 * of) a particular other behavior. A key example of this is when a
45 * system implementing distributed single system image wishes to
46 * interpose a distribution layer (providing distributed coherency)
47 * in front of an object that is otherwise only accessed locally.
49 * Note that the traditional vnode/inode combination is simply a virtualized
50 * object that has exactly one associated behavior.
52 * Behavior synchronization is logic which is necessary under certain
53 * circumstances that there is no conflict between ongoing operations
54 * traversing the behavior chain and those dynamically modifying the
55 * behavior chain. Because behavior synchronization adds extra overhead
56 * to virtual operation invocation, we want to restrict, as much as
57 * we can, the requirement for this extra code, to those situations
58 * in which it is truly necessary.
60 * Behavior synchronization is needed whenever there's at least one class
61 * of object in the system for which:
62 * 1) multiple behaviors for a given object are supported,
64 * 2a) insertion of a new behavior can happen dynamically at any time during
65 * the life of an active object,
67 * 3a) insertion of a new behavior needs to synchronize with existing
70 * 3b) multiple different behaviors can be dynamically inserted at
71 * any time during the life of an active object
73 * 3c) removal of a behavior can occur at any time during the life of
76 * 2b) removal of a behavior can occur at any time during the life of an
82 * Behavior head. Head of the chain of behaviors.
83 * Contained within each virtualized object data structure.
85 typedef struct bhv_head
{
86 struct bhv_desc
*bh_first
; /* first behavior in chain */
90 * Behavior descriptor. Descriptor associated with each behavior.
91 * Contained within the behavior's private data structure.
93 typedef struct bhv_desc
{
94 void *bd_pdata
; /* private data for this behavior */
95 void *bd_vobj
; /* virtual object associated with */
96 void *bd_ops
; /* ops for this behavior */
97 struct bhv_desc
*bd_next
; /* next behavior in chain */
101 * Behavior identity field. A behavior's identity determines the position
102 * where it lives within a behavior chain, and it's always the first field
103 * of the behavior's ops vector. The optional id field further identifies the
104 * subsystem responsible for the behavior.
106 typedef struct bhv_identity
{
107 __u16 bi_id
; /* owning subsystem id */
108 __u16 bi_position
; /* position in chain */
111 typedef bhv_identity_t bhv_position_t
;
113 #define BHV_IDENTITY_INIT(id,pos) {id, pos}
114 #define BHV_IDENTITY_INIT_POSITION(pos) BHV_IDENTITY_INIT(0, pos)
117 * Define boundaries of position values.
119 #define BHV_POSITION_INVALID 0 /* invalid position number */
120 #define BHV_POSITION_BASE 1 /* base (last) implementation layer */
121 #define BHV_POSITION_TOP 63 /* top (first) implementation layer */
126 #define BHV_HEAD_FIRST(bhp) (ASSERT((bhp)->bh_first), (bhp)->bh_first)
127 #define BHV_NEXT(bdp) (ASSERT((bdp)->bd_next), (bdp)->bd_next)
128 #define BHV_NEXTNULL(bdp) ((bdp)->bd_next)
129 #define BHV_VOBJ(bdp) (ASSERT((bdp)->bd_vobj), (bdp)->bd_vobj)
130 #define BHV_VOBJNULL(bdp) ((bdp)->bd_vobj)
131 #define BHV_PDATA(bdp) (bdp)->bd_pdata
132 #define BHV_OPS(bdp) (bdp)->bd_ops
133 #define BHV_IDENTITY(bdp) ((bhv_identity_t *)(bdp)->bd_ops)
134 #define BHV_POSITION(bdp) (BHV_IDENTITY(bdp)->bi_position)
136 extern void bhv_head_init(bhv_head_t
*, char *);
137 extern void bhv_head_destroy(bhv_head_t
*);
138 extern int bhv_insert(bhv_head_t
*, bhv_desc_t
*);
139 extern void bhv_insert_initial(bhv_head_t
*, bhv_desc_t
*);
142 * Initialize a new behavior descriptor.
144 * bdp - pointer to behavior descriptor
145 * pdata - pointer to behavior's private data
146 * vobj - pointer to associated virtual object
147 * ops - pointer to ops for this behavior
149 #define bhv_desc_init(bdp, pdata, vobj, ops) \
151 (bdp)->bd_pdata = pdata; \
152 (bdp)->bd_vobj = vobj; \
153 (bdp)->bd_ops = ops; \
154 (bdp)->bd_next = NULL; \
158 * Remove a behavior descriptor from a behavior chain.
160 #define bhv_remove(bhp, bdp) \
162 if ((bhp)->bh_first == (bdp)) { \
164 * Remove from front of chain. \
165 * Atomic wrt oip's. \
167 (bhp)->bh_first = (bdp)->bd_next; \
169 /* remove from non-front of chain */ \
170 bhv_remove_not_first(bhp, bdp); \
172 (bdp)->bd_vobj = NULL; \
176 * Behavior module prototypes.
178 extern void bhv_remove_not_first(bhv_head_t
*bhp
, bhv_desc_t
*bdp
);
179 extern bhv_desc_t
* bhv_lookup_range(bhv_head_t
*bhp
, int low
, int high
);
180 extern bhv_desc_t
* bhv_base(bhv_head_t
*bhp
);
182 /* No bhv locking on Linux */
183 #define bhv_base_unlocked bhv_base
185 #endif /* __XFS_BEHAVIOR_H__ */