blob: 2e073c1c4614f2a79cc9452854da1cead65fb06c [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_TRANS_PRIV_H__
7#define __XFS_TRANS_PRIV_H__
8
9struct xfs_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010struct xfs_mount;
11struct xfs_trans;
Dave Chinner0e57f6a2010-12-20 12:02:19 +110012struct xfs_ail;
13struct xfs_log_vec;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Dave Chinnerd386b322013-08-12 20:49:31 +100015
16void xfs_trans_init(struct xfs_mount *);
Christoph Hellwige98c4142010-06-23 18:11:15 +100017void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
18void xfs_trans_del_item(struct xfs_log_item *);
Dave Chinner71e330b2010-05-21 14:37:18 +100019void xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Dave Chinner0e57f6a2010-12-20 12:02:19 +110021void xfs_trans_committed_bulk(struct xfs_ail *ailp, struct xfs_log_vec *lv,
Christoph Hellwigd15cbf22019-06-28 19:27:30 -070022 xfs_lsn_t commit_lsn, bool aborted);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
David Chinner27d8d5f2008-10-30 17:38:39 +110024 * AIL traversal cursor.
25 *
26 * Rather than using a generation number for detecting changes in the ail, use
27 * a cursor that is protected by the ail lock. The aild cursor exists in the
28 * struct xfs_ail, but other traversals can declare it on the stack and link it
29 * to the ail list.
30 *
31 * When an object is deleted from or moved int the AIL, the cursor list is
32 * searched to see if the object is a designated cursor item. If it is, it is
33 * deleted from the cursor so that the next time the cursor is used traversal
34 * will return to the start.
35 *
36 * This means a traversal colliding with a removal will cause a restart of the
37 * list scan, rather than any insertion or deletion anywhere in the list. The
38 * low bit of the item pointer is set if the cursor has been invalidated so
39 * that we can tell the difference between invalidation and reaching the end
40 * of the list to trigger traversal restarts.
41 */
42struct xfs_ail_cursor {
Dave Chinneraf3e4022011-07-18 03:40:18 +000043 struct list_head list;
David Chinner27d8d5f2008-10-30 17:38:39 +110044 struct xfs_log_item *item;
45};
46
47/*
48 * Private AIL structures.
49 *
50 * Eventually we need to drive the locking in here as well.
51 */
52struct xfs_ail {
Matthew Wilcox57e80952018-03-07 14:59:39 -080053 struct xfs_mount *ail_mount;
54 struct task_struct *ail_task;
55 struct list_head ail_head;
56 xfs_lsn_t ail_target;
57 xfs_lsn_t ail_target_prev;
58 struct list_head ail_cursors;
59 spinlock_t ail_lock;
60 xfs_lsn_t ail_last_pushed_lsn;
61 int ail_log_flush;
62 struct list_head ail_buf_list;
63 wait_queue_head_t ail_empty;
David Chinner27d8d5f2008-10-30 17:38:39 +110064};
65
66/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 * From xfs_trans_ail.c
68 */
Dave Chinnere6059942010-12-20 12:34:26 +110069void xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
Dave Chinner1d8c95a2011-07-18 03:40:16 +000070 struct xfs_ail_cursor *cur,
Dave Chinnere6059942010-12-20 12:34:26 +110071 struct xfs_log_item **log_items, int nr_items,
Matthew Wilcox57e80952018-03-07 14:59:39 -080072 xfs_lsn_t lsn) __releases(ailp->ail_lock);
Jie Liu8d1d4082013-08-15 13:08:35 +080073/*
74 * Return a pointer to the first item in the AIL. If the AIL is empty, then
75 * return NULL.
76 */
77static inline struct xfs_log_item *
78xfs_ail_min(
79 struct xfs_ail *ailp)
80{
Matthew Wilcox57e80952018-03-07 14:59:39 -080081 return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item,
Jie Liu8d1d4082013-08-15 13:08:35 +080082 li_ail);
83}
84
Dave Chinnere6059942010-12-20 12:34:26 +110085static inline void
86xfs_trans_ail_update(
87 struct xfs_ail *ailp,
88 struct xfs_log_item *lip,
Matthew Wilcox57e80952018-03-07 14:59:39 -080089 xfs_lsn_t lsn) __releases(ailp->ail_lock)
Dave Chinnere6059942010-12-20 12:34:26 +110090{
Dave Chinner1d8c95a2011-07-18 03:40:16 +000091 xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn);
Dave Chinnere6059942010-12-20 12:34:26 +110092}
93
Christoph Hellwig27af1bb2017-04-21 11:24:42 -070094bool xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip);
95void xfs_trans_ail_delete(struct xfs_ail *ailp, struct xfs_log_item *lip,
Matthew Wilcox57e80952018-03-07 14:59:39 -080096 int shutdown_type) __releases(ailp->ail_lock);
Dave Chinner9552e7f2010-12-20 12:36:15 +110097
Brian Foster146e54b2015-08-19 10:01:08 +100098static inline void
99xfs_trans_ail_remove(
100 struct xfs_log_item *lip,
101 int shutdown_type)
102{
103 struct xfs_ail *ailp = lip->li_ailp;
104
Matthew Wilcox57e80952018-03-07 14:59:39 -0800105 spin_lock(&ailp->ail_lock);
Brian Foster146e54b2015-08-19 10:01:08 +1000106 /* xfs_trans_ail_delete() drops the AIL lock */
Dave Chinner22525c12018-05-09 07:47:34 -0700107 if (test_bit(XFS_LI_IN_AIL, &lip->li_flags))
Brian Foster146e54b2015-08-19 10:01:08 +1000108 xfs_trans_ail_delete(ailp, lip, shutdown_type);
109 else
Matthew Wilcox57e80952018-03-07 14:59:39 -0800110 spin_unlock(&ailp->ail_lock);
Brian Foster146e54b2015-08-19 10:01:08 +1000111}
112
Dave Chinnerfd074842011-04-08 12:45:07 +1000113void xfs_ail_push(struct xfs_ail *, xfs_lsn_t);
114void xfs_ail_push_all(struct xfs_ail *);
Christoph Hellwig211e4d42012-04-23 15:58:34 +1000115void xfs_ail_push_all_sync(struct xfs_ail *);
Christoph Hellwig1c304622012-04-23 15:58:33 +1000116struct xfs_log_item *xfs_ail_min(struct xfs_ail *ailp);
Dave Chinnerfd074842011-04-08 12:45:07 +1000117xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp);
118
Dave Chinner1d8c95a2011-07-18 03:40:16 +0000119struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
David Chinner5b00f142008-10-30 17:39:00 +1100120 struct xfs_ail_cursor *cur,
121 xfs_lsn_t lsn);
Dave Chinner1d8c95a2011-07-18 03:40:16 +0000122struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
123 struct xfs_ail_cursor *cur,
124 xfs_lsn_t lsn);
125struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
David Chinner27d8d5f2008-10-30 17:38:39 +1100126 struct xfs_ail_cursor *cur);
Eric Sandeene4a1e292014-04-14 19:06:05 +1000127void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
David Chinner82fa9012008-10-30 17:38:26 +1100128
David Chinner7b2e2a32008-10-30 17:39:12 +1100129#if BITS_PER_LONG != 64
130static inline void
131xfs_trans_ail_copy_lsn(
132 struct xfs_ail *ailp,
133 xfs_lsn_t *dst,
134 xfs_lsn_t *src)
135{
136 ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */
Matthew Wilcox57e80952018-03-07 14:59:39 -0800137 spin_lock(&ailp->ail_lock);
David Chinner7b2e2a32008-10-30 17:39:12 +1100138 *dst = *src;
Matthew Wilcox57e80952018-03-07 14:59:39 -0800139 spin_unlock(&ailp->ail_lock);
David Chinner7b2e2a32008-10-30 17:39:12 +1100140}
141#else
142static inline void
143xfs_trans_ail_copy_lsn(
144 struct xfs_ail *ailp,
145 xfs_lsn_t *dst,
146 xfs_lsn_t *src)
147{
148 ASSERT(sizeof(xfs_lsn_t) == 8);
149 *dst = *src;
150}
151#endif
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700152
153static inline void
154xfs_clear_li_failed(
155 struct xfs_log_item *lip)
156{
157 struct xfs_buf *bp = lip->li_buf;
158
Dave Chinner22525c12018-05-09 07:47:34 -0700159 ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
Matthew Wilcox57e80952018-03-07 14:59:39 -0800160 lockdep_assert_held(&lip->li_ailp->ail_lock);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700161
Dave Chinner22525c12018-05-09 07:47:34 -0700162 if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700163 lip->li_buf = NULL;
164 xfs_buf_rele(bp);
165 }
166}
167
168static inline void
169xfs_set_li_failed(
170 struct xfs_log_item *lip,
171 struct xfs_buf *bp)
172{
Matthew Wilcox57e80952018-03-07 14:59:39 -0800173 lockdep_assert_held(&lip->li_ailp->ail_lock);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700174
Dave Chinner22525c12018-05-09 07:47:34 -0700175 if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700176 xfs_buf_hold(bp);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700177 lip->li_buf = bp;
178 }
179}
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#endif /* __XFS_TRANS_PRIV_H__ */