xfs_trans_priv.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2000,2002,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_TRANS_PRIV_H__
  19. #define __XFS_TRANS_PRIV_H__
  20. struct xfs_log_item;
  21. struct xfs_log_item_desc;
  22. struct xfs_mount;
  23. struct xfs_trans;
  24. struct xfs_ail;
  25. struct xfs_log_vec;
  26. void xfs_trans_init(struct xfs_mount *);
  27. void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
  28. void xfs_trans_del_item(struct xfs_log_item *);
  29. void xfs_trans_free_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn,
  30. bool abort);
  31. void xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp);
  32. void xfs_trans_committed_bulk(struct xfs_ail *ailp, struct xfs_log_vec *lv,
  33. xfs_lsn_t commit_lsn, int aborted);
  34. /*
  35. * AIL traversal cursor.
  36. *
  37. * Rather than using a generation number for detecting changes in the ail, use
  38. * a cursor that is protected by the ail lock. The aild cursor exists in the
  39. * struct xfs_ail, but other traversals can declare it on the stack and link it
  40. * to the ail list.
  41. *
  42. * When an object is deleted from or moved int the AIL, the cursor list is
  43. * searched to see if the object is a designated cursor item. If it is, it is
  44. * deleted from the cursor so that the next time the cursor is used traversal
  45. * will return to the start.
  46. *
  47. * This means a traversal colliding with a removal will cause a restart of the
  48. * list scan, rather than any insertion or deletion anywhere in the list. The
  49. * low bit of the item pointer is set if the cursor has been invalidated so
  50. * that we can tell the difference between invalidation and reaching the end
  51. * of the list to trigger traversal restarts.
  52. */
  53. struct xfs_ail_cursor {
  54. struct list_head list;
  55. struct xfs_log_item *item;
  56. };
  57. /*
  58. * Private AIL structures.
  59. *
  60. * Eventually we need to drive the locking in here as well.
  61. */
  62. struct xfs_ail {
  63. struct xfs_mount *xa_mount;
  64. struct task_struct *xa_task;
  65. struct list_head xa_ail;
  66. xfs_lsn_t xa_target;
  67. xfs_lsn_t xa_target_prev;
  68. struct list_head xa_cursors;
  69. spinlock_t xa_lock;
  70. xfs_lsn_t xa_last_pushed_lsn;
  71. int xa_log_flush;
  72. struct list_head xa_buf_list;
  73. wait_queue_head_t xa_empty;
  74. };
  75. /*
  76. * From xfs_trans_ail.c
  77. */
  78. void xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
  79. struct xfs_ail_cursor *cur,
  80. struct xfs_log_item **log_items, int nr_items,
  81. xfs_lsn_t lsn) __releases(ailp->xa_lock);
  82. /*
  83. * Return a pointer to the first item in the AIL. If the AIL is empty, then
  84. * return NULL.
  85. */
  86. static inline struct xfs_log_item *
  87. xfs_ail_min(
  88. struct xfs_ail *ailp)
  89. {
  90. return list_first_entry_or_null(&ailp->xa_ail, struct xfs_log_item,
  91. li_ail);
  92. }
  93. static inline void
  94. xfs_trans_ail_update(
  95. struct xfs_ail *ailp,
  96. struct xfs_log_item *lip,
  97. xfs_lsn_t lsn) __releases(ailp->xa_lock)
  98. {
  99. xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn);
  100. }
  101. void xfs_trans_ail_delete_bulk(struct xfs_ail *ailp,
  102. struct xfs_log_item **log_items, int nr_items,
  103. int shutdown_type)
  104. __releases(ailp->xa_lock);
  105. static inline void
  106. xfs_trans_ail_delete(
  107. struct xfs_ail *ailp,
  108. xfs_log_item_t *lip,
  109. int shutdown_type) __releases(ailp->xa_lock)
  110. {
  111. xfs_trans_ail_delete_bulk(ailp, &lip, 1, shutdown_type);
  112. }
  113. static inline void
  114. xfs_trans_ail_remove(
  115. struct xfs_log_item *lip,
  116. int shutdown_type)
  117. {
  118. struct xfs_ail *ailp = lip->li_ailp;
  119. spin_lock(&ailp->xa_lock);
  120. /* xfs_trans_ail_delete() drops the AIL lock */
  121. if (lip->li_flags & XFS_LI_IN_AIL)
  122. xfs_trans_ail_delete(ailp, lip, shutdown_type);
  123. else
  124. spin_unlock(&ailp->xa_lock);
  125. }
  126. void xfs_ail_push(struct xfs_ail *, xfs_lsn_t);
  127. void xfs_ail_push_all(struct xfs_ail *);
  128. void xfs_ail_push_all_sync(struct xfs_ail *);
  129. struct xfs_log_item *xfs_ail_min(struct xfs_ail *ailp);
  130. xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp);
  131. struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
  132. struct xfs_ail_cursor *cur,
  133. xfs_lsn_t lsn);
  134. struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
  135. struct xfs_ail_cursor *cur,
  136. xfs_lsn_t lsn);
  137. struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
  138. struct xfs_ail_cursor *cur);
  139. void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
  140. #if BITS_PER_LONG != 64
  141. static inline void
  142. xfs_trans_ail_copy_lsn(
  143. struct xfs_ail *ailp,
  144. xfs_lsn_t *dst,
  145. xfs_lsn_t *src)
  146. {
  147. ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */
  148. spin_lock(&ailp->xa_lock);
  149. *dst = *src;
  150. spin_unlock(&ailp->xa_lock);
  151. }
  152. #else
  153. static inline void
  154. xfs_trans_ail_copy_lsn(
  155. struct xfs_ail *ailp,
  156. xfs_lsn_t *dst,
  157. xfs_lsn_t *src)
  158. {
  159. ASSERT(sizeof(xfs_lsn_t) == 8);
  160. *dst = *src;
  161. }
  162. #endif
  163. #endif /* __XFS_TRANS_PRIV_H__ */