xfs_trans_priv.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_TRANS_PRIV_H__
  7. #define __XFS_TRANS_PRIV_H__
  8. struct xlog;
  9. struct xfs_log_item;
  10. struct xfs_mount;
  11. struct xfs_trans;
  12. struct xfs_ail;
  13. struct xfs_log_vec;
  14. void xfs_trans_init(struct xfs_mount *);
  15. void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
  16. void xfs_trans_del_item(struct xfs_log_item *);
  17. void xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp);
  18. /*
  19. * AIL traversal cursor.
  20. *
  21. * Rather than using a generation number for detecting changes in the ail, use
  22. * a cursor that is protected by the ail lock. The aild cursor exists in the
  23. * struct xfs_ail, but other traversals can declare it on the stack and link it
  24. * to the ail list.
  25. *
  26. * When an object is deleted from or moved int the AIL, the cursor list is
  27. * searched to see if the object is a designated cursor item. If it is, it is
  28. * deleted from the cursor so that the next time the cursor is used traversal
  29. * will return to the start.
  30. *
  31. * This means a traversal colliding with a removal will cause a restart of the
  32. * list scan, rather than any insertion or deletion anywhere in the list. The
  33. * low bit of the item pointer is set if the cursor has been invalidated so
  34. * that we can tell the difference between invalidation and reaching the end
  35. * of the list to trigger traversal restarts.
  36. */
  37. struct xfs_ail_cursor {
  38. struct list_head list;
  39. struct xfs_log_item *item;
  40. };
  41. /*
  42. * Private AIL structures.
  43. *
  44. * Eventually we need to drive the locking in here as well.
  45. */
  46. struct xfs_ail {
  47. struct xlog *ail_log;
  48. struct task_struct *ail_task;
  49. struct list_head ail_head;
  50. struct list_head ail_cursors;
  51. spinlock_t ail_lock;
  52. xfs_lsn_t ail_last_pushed_lsn;
  53. xfs_lsn_t ail_head_lsn;
  54. int ail_log_flush;
  55. unsigned long ail_opstate;
  56. struct list_head ail_buf_list;
  57. wait_queue_head_t ail_empty;
  58. xfs_lsn_t ail_target;
  59. };
  60. /* Push all items out of the AIL immediately. */
  61. #define XFS_AIL_OPSTATE_PUSH_ALL 0u
  62. /*
  63. * From xfs_trans_ail.c
  64. */
  65. void xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
  66. struct xfs_ail_cursor *cur,
  67. struct xfs_log_item **log_items, int nr_items,
  68. xfs_lsn_t lsn) __releases(ailp->ail_lock);
  69. /*
  70. * Return a pointer to the first item in the AIL. If the AIL is empty, then
  71. * return NULL.
  72. */
  73. static inline struct xfs_log_item *
  74. xfs_ail_min(
  75. struct xfs_ail *ailp)
  76. {
  77. return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item,
  78. li_ail);
  79. }
  80. static inline void
  81. xfs_trans_ail_update(
  82. struct xfs_ail *ailp,
  83. struct xfs_log_item *lip,
  84. xfs_lsn_t lsn) __releases(ailp->ail_lock)
  85. {
  86. xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn);
  87. }
  88. void xfs_trans_ail_insert(struct xfs_ail *ailp, struct xfs_log_item *lip,
  89. xfs_lsn_t lsn);
  90. xfs_lsn_t xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip);
  91. void xfs_ail_update_finish(struct xfs_ail *ailp, xfs_lsn_t old_lsn)
  92. __releases(ailp->ail_lock);
  93. void xfs_trans_ail_delete(struct xfs_log_item *lip, int shutdown_type);
  94. static inline void xfs_ail_push(struct xfs_ail *ailp)
  95. {
  96. wake_up_process(ailp->ail_task);
  97. }
  98. static inline void xfs_ail_push_all(struct xfs_ail *ailp)
  99. {
  100. if (!test_and_set_bit(XFS_AIL_OPSTATE_PUSH_ALL, &ailp->ail_opstate))
  101. xfs_ail_push(ailp);
  102. }
  103. static inline xfs_lsn_t xfs_ail_get_push_target(struct xfs_ail *ailp)
  104. {
  105. return READ_ONCE(ailp->ail_target);
  106. }
  107. void xfs_ail_push_all_sync(struct xfs_ail *ailp);
  108. xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp);
  109. struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
  110. struct xfs_ail_cursor *cur,
  111. xfs_lsn_t lsn);
  112. struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
  113. struct xfs_ail_cursor *cur,
  114. xfs_lsn_t lsn);
  115. struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
  116. struct xfs_ail_cursor *cur);
  117. void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
  118. void __xfs_ail_assign_tail_lsn(struct xfs_ail *ailp);
  119. static inline void
  120. xfs_ail_assign_tail_lsn(
  121. struct xfs_ail *ailp)
  122. {
  123. spin_lock(&ailp->ail_lock);
  124. __xfs_ail_assign_tail_lsn(ailp);
  125. spin_unlock(&ailp->ail_lock);
  126. }
  127. #if BITS_PER_LONG != 64
  128. static inline void
  129. xfs_trans_ail_copy_lsn(
  130. struct xfs_ail *ailp,
  131. xfs_lsn_t *dst,
  132. xfs_lsn_t *src)
  133. {
  134. ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */
  135. spin_lock(&ailp->ail_lock);
  136. *dst = *src;
  137. spin_unlock(&ailp->ail_lock);
  138. }
  139. #else
  140. static inline void
  141. xfs_trans_ail_copy_lsn(
  142. struct xfs_ail *ailp,
  143. xfs_lsn_t *dst,
  144. xfs_lsn_t *src)
  145. {
  146. ASSERT(sizeof(xfs_lsn_t) == 8);
  147. *dst = *src;
  148. }
  149. #endif
  150. static inline void
  151. xfs_clear_li_failed(
  152. struct xfs_log_item *lip)
  153. {
  154. struct xfs_buf *bp = lip->li_buf;
  155. ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
  156. lockdep_assert_held(&lip->li_ailp->ail_lock);
  157. if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
  158. lip->li_buf = NULL;
  159. xfs_buf_rele(bp);
  160. }
  161. }
  162. static inline void
  163. xfs_set_li_failed(
  164. struct xfs_log_item *lip,
  165. struct xfs_buf *bp)
  166. {
  167. lockdep_assert_held(&lip->li_ailp->ail_lock);
  168. if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
  169. xfs_buf_hold(bp);
  170. lip->li_buf = bp;
  171. }
  172. }
  173. #endif /* __XFS_TRANS_PRIV_H__ */