xfs_trans_priv.h 4.6 KB

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