xfs_behavior.h 6.9 KB

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