xfs_behavior.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "interposition" 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 dynamically 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. /*
  80. * Behavior head. Head of the chain of behaviors.
  81. * Contained within each virtualized object data structure.
  82. */
  83. typedef struct bhv_head {
  84. struct bhv_desc *bh_first; /* first behavior in chain */
  85. } bhv_head_t;
  86. /*
  87. * Behavior descriptor. Descriptor associated with each behavior.
  88. * Contained within the behavior's private data structure.
  89. */
  90. typedef struct bhv_desc {
  91. void *bd_pdata; /* private data for this behavior */
  92. void *bd_vobj; /* virtual object associated with */
  93. void *bd_ops; /* ops for this behavior */
  94. struct bhv_desc *bd_next; /* next behavior in chain */
  95. } bhv_desc_t;
  96. /*
  97. * Behavior identity field. A behavior's identity determines the position
  98. * where it lives within a behavior chain, and it's always the first field
  99. * of the behavior's ops vector. The optional id field further identifies the
  100. * subsystem responsible for the behavior.
  101. */
  102. typedef struct bhv_identity {
  103. __u16 bi_id; /* owning subsystem id */
  104. __u16 bi_position; /* position in chain */
  105. } bhv_identity_t;
  106. typedef bhv_identity_t bhv_position_t;
  107. #define BHV_IDENTITY_INIT(id,pos) {id, pos}
  108. #define BHV_IDENTITY_INIT_POSITION(pos) BHV_IDENTITY_INIT(0, pos)
  109. /*
  110. * Define boundaries of position values.
  111. */
  112. #define BHV_POSITION_INVALID 0 /* invalid position number */
  113. #define BHV_POSITION_BASE 1 /* base (last) implementation layer */
  114. #define BHV_POSITION_TOP 63 /* top (first) implementation layer */
  115. /*
  116. * Plumbing macros.
  117. */
  118. #define BHV_HEAD_FIRST(bhp) (ASSERT((bhp)->bh_first), (bhp)->bh_first)
  119. #define BHV_NEXT(bdp) (ASSERT((bdp)->bd_next), (bdp)->bd_next)
  120. #define BHV_NEXTNULL(bdp) ((bdp)->bd_next)
  121. #define BHV_VOBJ(bdp) (ASSERT((bdp)->bd_vobj), (bdp)->bd_vobj)
  122. #define BHV_VOBJNULL(bdp) ((bdp)->bd_vobj)
  123. #define BHV_PDATA(bdp) (bdp)->bd_pdata
  124. #define BHV_OPS(bdp) (bdp)->bd_ops
  125. #define BHV_IDENTITY(bdp) ((bhv_identity_t *)(bdp)->bd_ops)
  126. #define BHV_POSITION(bdp) (BHV_IDENTITY(bdp)->bi_position)
  127. extern void bhv_head_init(bhv_head_t *, char *);
  128. extern void bhv_head_destroy(bhv_head_t *);
  129. extern int bhv_insert(bhv_head_t *, bhv_desc_t *);
  130. extern void bhv_insert_initial(bhv_head_t *, bhv_desc_t *);
  131. /*
  132. * Initialize a new behavior descriptor.
  133. * Arguments:
  134. * bdp - pointer to behavior descriptor
  135. * pdata - pointer to behavior's private data
  136. * vobj - pointer to associated virtual object
  137. * ops - pointer to ops for this behavior
  138. */
  139. #define bhv_desc_init(bdp, pdata, vobj, ops) \
  140. { \
  141. (bdp)->bd_pdata = pdata; \
  142. (bdp)->bd_vobj = vobj; \
  143. (bdp)->bd_ops = ops; \
  144. (bdp)->bd_next = NULL; \
  145. }
  146. /*
  147. * Remove a behavior descriptor from a behavior chain.
  148. */
  149. #define bhv_remove(bhp, bdp) \
  150. { \
  151. if ((bhp)->bh_first == (bdp)) { \
  152. /* \
  153. * Remove from front of chain. \
  154. * Atomic wrt oip's. \
  155. */ \
  156. (bhp)->bh_first = (bdp)->bd_next; \
  157. } else { \
  158. /* remove from non-front of chain */ \
  159. bhv_remove_not_first(bhp, bdp); \
  160. } \
  161. (bdp)->bd_vobj = NULL; \
  162. }
  163. /*
  164. * Behavior module prototypes.
  165. */
  166. extern void bhv_remove_not_first(bhv_head_t *bhp, bhv_desc_t *bdp);
  167. extern bhv_desc_t * bhv_lookup_range(bhv_head_t *bhp, int low, int high);
  168. extern bhv_desc_t * bhv_base(bhv_head_t *bhp);
  169. /* No bhv locking on Linux */
  170. #define bhv_base_unlocked bhv_base
  171. #endif /* __XFS_BEHAVIOR_H__ */