RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / fs / xfs / xfs_behavior.h
blobe7ca1fed955a98ff3e15a68ac1dddcdf9e1e020a
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
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,
63 * -- AND --
64 * 2a) insertion of a new behavior can happen dynamically at any time during
65 * the life of an active object,
66 * -- AND --
67 * 3a) insertion of a new behavior needs to synchronize with existing
68 * ops-in-progress.
69 * -- OR --
70 * 3b) multiple different behaviors can be dynamically inserted at
71 * any time during the life of an active object
72 * -- OR --
73 * 3c) removal of a behavior can occur at any time during the life of
74 * an active object.
75 * -- OR --
76 * 2b) removal of a behavior can occur at any time during the life of an
77 * active object
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 */
87 } bhv_head_t;
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 */
98 } bhv_desc_t;
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 */
109 } bhv_identity_t;
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 */
124 * Plumbing macros.
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.
143 * Arguments:
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)) { \
163 /* \
164 * Remove from front of chain. \
165 * Atomic wrt oip's. \
166 */ \
167 (bhp)->bh_first = (bdp)->bd_next; \
168 } else { \
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__ */