xfs_behavior.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  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.
  7. *
  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.
  11. *
  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.
  18. *
  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.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_BEHAVIOR_H__
  33. #define __XFS_BEHAVIOR_H__
  34. /*
  35. * Header file used to associate behaviors with virtualized objects.
  36. *
  37. * A virtualized object is an internal, virtualized representation of
  38. * OS entities such as persistent files, processes, or sockets. Examples
  39. * of virtualized objects include vnodes, vprocs, and vsockets. Often
  40. * a virtualized object is referred to simply as an "object."
  41. *
  42. * A behavior is essentially an implementation layer associated with
  43. * an object. Multiple behaviors for an object are chained together,
  44. * the order of chaining determining the order of invocation. Each
  45. * behavior of a given object implements the same set of interfaces
  46. * (e.g., the VOP interfaces).
  47. *
  48. * Behaviors may be dynamically inserted into an object's behavior chain,
  49. * such that the addition is transparent to consumers that already have
  50. * references to the object. Typically, a given behavior will be inserted
  51. * at a particular location in the behavior chain. Insertion of new
  52. * behaviors is synchronized with operations-in-progress (oip's) so that
  53. * the oip's always see a consistent view of the chain.
  54. *
  55. * The term "interpostion" is used to refer to the act of inserting
  56. * a behavior such that it interposes on (i.e., is inserted in front
  57. * of) a particular other behavior. A key example of this is when a
  58. * system implementing distributed single system image wishes to
  59. * interpose a distribution layer (providing distributed coherency)
  60. * in front of an object that is otherwise only accessed locally.
  61. *
  62. * Note that the traditional vnode/inode combination is simply a virtualized
  63. * object that has exactly one associated behavior.
  64. *
  65. * Behavior synchronization is logic which is necessary under certain
  66. * circumstances that there is no conflict between ongoing operations
  67. * traversing the behavior chain and those dunamically modifying the
  68. * behavior chain. Because behavior synchronization adds extra overhead
  69. * to virtual operation invocation, we want to restrict, as much as
  70. * we can, the requirement for this extra code, to those situations
  71. * in which it is truly necessary.
  72. *
  73. * Behavior synchronization is needed whenever there's at least one class
  74. * of object in the system for which:
  75. * 1) multiple behaviors for a given object are supported,
  76. * -- AND --
  77. * 2a) insertion of a new behavior can happen dynamically at any time during
  78. * the life of an active object,
  79. * -- AND --
  80. * 3a) insertion of a new behavior needs to synchronize with existing
  81. * ops-in-progress.
  82. * -- OR --
  83. * 3b) multiple different behaviors can be dynamically inserted at
  84. * any time during the life of an active object
  85. * -- OR --
  86. * 3c) removal of a behavior can occur at any time during the life of
  87. * an active object.
  88. * -- OR --
  89. * 2b) removal of a behavior can occur at any time during the life of an
  90. * active object
  91. *
  92. */
  93. struct bhv_head_lock;
  94. /*
  95. * Behavior head. Head of the chain of behaviors.
  96. * Contained within each virtualized object data structure.
  97. */
  98. typedef struct bhv_head {
  99. struct bhv_desc *bh_first; /* first behavior in chain */
  100. struct bhv_head_lock *bh_lockp; /* pointer to lock info struct */
  101. } bhv_head_t;
  102. /*
  103. * Behavior descriptor. Descriptor associated with each behavior.
  104. * Contained within the behavior's private data structure.
  105. */
  106. typedef struct bhv_desc {
  107. void *bd_pdata; /* private data for this behavior */
  108. void *bd_vobj; /* virtual object associated with */
  109. void *bd_ops; /* ops for this behavior */
  110. struct bhv_desc *bd_next; /* next behavior in chain */
  111. } bhv_desc_t;
  112. /*
  113. * Behavior identity field. A behavior's identity determines the position
  114. * where it lives within a behavior chain, and it's always the first field
  115. * of the behavior's ops vector. The optional id field further identifies the
  116. * subsystem responsible for the behavior.
  117. */
  118. typedef struct bhv_identity {
  119. __u16 bi_id; /* owning subsystem id */
  120. __u16 bi_position; /* position in chain */
  121. } bhv_identity_t;
  122. typedef bhv_identity_t bhv_position_t;
  123. #define BHV_IDENTITY_INIT(id,pos) {id, pos}
  124. #define BHV_IDENTITY_INIT_POSITION(pos) BHV_IDENTITY_INIT(0, pos)
  125. /*
  126. * Define boundaries of position values.
  127. */
  128. #define BHV_POSITION_INVALID 0 /* invalid position number */
  129. #define BHV_POSITION_BASE 1 /* base (last) implementation layer */
  130. #define BHV_POSITION_TOP 63 /* top (first) implementation layer */
  131. /*
  132. * Plumbing macros.
  133. */
  134. #define BHV_HEAD_FIRST(bhp) (ASSERT((bhp)->bh_first), (bhp)->bh_first)
  135. #define BHV_NEXT(bdp) (ASSERT((bdp)->bd_next), (bdp)->bd_next)
  136. #define BHV_NEXTNULL(bdp) ((bdp)->bd_next)
  137. #define BHV_VOBJ(bdp) (ASSERT((bdp)->bd_vobj), (bdp)->bd_vobj)
  138. #define BHV_VOBJNULL(bdp) ((bdp)->bd_vobj)
  139. #define BHV_PDATA(bdp) (bdp)->bd_pdata
  140. #define BHV_OPS(bdp) (bdp)->bd_ops
  141. #define BHV_IDENTITY(bdp) ((bhv_identity_t *)(bdp)->bd_ops)
  142. #define BHV_POSITION(bdp) (BHV_IDENTITY(bdp)->bi_position)
  143. extern void bhv_head_init(bhv_head_t *, char *);
  144. extern void bhv_head_destroy(bhv_head_t *);
  145. extern int bhv_insert(bhv_head_t *, bhv_desc_t *);
  146. extern void bhv_insert_initial(bhv_head_t *, bhv_desc_t *);
  147. /*
  148. * Initialize a new behavior descriptor.
  149. * Arguments:
  150. * bdp - pointer to behavior descriptor
  151. * pdata - pointer to behavior's private data
  152. * vobj - pointer to associated virtual object
  153. * ops - pointer to ops for this behavior
  154. */
  155. #define bhv_desc_init(bdp, pdata, vobj, ops) \
  156. { \
  157. (bdp)->bd_pdata = pdata; \
  158. (bdp)->bd_vobj = vobj; \
  159. (bdp)->bd_ops = ops; \
  160. (bdp)->bd_next = NULL; \
  161. }
  162. /*
  163. * Remove a behavior descriptor from a behavior chain.
  164. */
  165. #define bhv_remove(bhp, bdp) \
  166. { \
  167. if ((bhp)->bh_first == (bdp)) { \
  168. /* \
  169. * Remove from front of chain. \
  170. * Atomic wrt oip's. \
  171. */ \
  172. (bhp)->bh_first = (bdp)->bd_next; \
  173. } else { \
  174. /* remove from non-front of chain */ \
  175. bhv_remove_not_first(bhp, bdp); \
  176. } \
  177. (bdp)->bd_vobj = NULL; \
  178. }
  179. /*
  180. * Behavior module prototypes.
  181. */
  182. extern void bhv_remove_not_first(bhv_head_t *bhp, bhv_desc_t *bdp);
  183. extern bhv_desc_t * bhv_lookup(bhv_head_t *bhp, void *ops);
  184. extern bhv_desc_t * bhv_lookup_range(bhv_head_t *bhp, int low, int high);
  185. extern bhv_desc_t * bhv_base(bhv_head_t *bhp);
  186. /* No bhv locking on Linux */
  187. #define bhv_lookup_unlocked bhv_lookup
  188. #define bhv_base_unlocked bhv_base
  189. #endif /* __XFS_BEHAVIOR_H__ */