blob: 3004aeac91102c8a1649c7fa6382628e95de4afd [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
Darrick J. Wong86a37172020-05-01 16:00:54 -070094void xfs_trans_ail_insert(struct xfs_ail *ailp, struct xfs_log_item *lip,
95 xfs_lsn_t lsn);
96
Dave Chinner8eb807b2020-03-24 20:10:29 -070097xfs_lsn_t xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip);
98void xfs_ail_update_finish(struct xfs_ail *ailp, xfs_lsn_t old_lsn)
Dave Chinner41659942020-03-24 20:10:29 -070099 __releases(ailp->ail_lock);
Brian Foster849274c2020-05-06 13:25:23 -0700100void xfs_trans_ail_delete(struct xfs_log_item *lip, int shutdown_type);
Dave Chinner9552e7f2010-12-20 12:36:15 +1100101
Dave Chinnerfd074842011-04-08 12:45:07 +1000102void xfs_ail_push(struct xfs_ail *, xfs_lsn_t);
103void xfs_ail_push_all(struct xfs_ail *);
Christoph Hellwig211e4d42012-04-23 15:58:34 +1000104void xfs_ail_push_all_sync(struct xfs_ail *);
Christoph Hellwig1c304622012-04-23 15:58:33 +1000105struct xfs_log_item *xfs_ail_min(struct xfs_ail *ailp);
Dave Chinnerfd074842011-04-08 12:45:07 +1000106xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp);
107
Dave Chinner1d8c95a2011-07-18 03:40:16 +0000108struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
David Chinner5b00f142008-10-30 17:39:00 +1100109 struct xfs_ail_cursor *cur,
110 xfs_lsn_t lsn);
Dave Chinner1d8c95a2011-07-18 03:40:16 +0000111struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
112 struct xfs_ail_cursor *cur,
113 xfs_lsn_t lsn);
114struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
David Chinner27d8d5f2008-10-30 17:38:39 +1100115 struct xfs_ail_cursor *cur);
Eric Sandeene4a1e292014-04-14 19:06:05 +1000116void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
David Chinner82fa9012008-10-30 17:38:26 +1100117
David Chinner7b2e2a32008-10-30 17:39:12 +1100118#if BITS_PER_LONG != 64
119static inline void
120xfs_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); /* don't lock if it shrinks */
Matthew Wilcox57e80952018-03-07 14:59:39 -0800126 spin_lock(&ailp->ail_lock);
David Chinner7b2e2a32008-10-30 17:39:12 +1100127 *dst = *src;
Matthew Wilcox57e80952018-03-07 14:59:39 -0800128 spin_unlock(&ailp->ail_lock);
David Chinner7b2e2a32008-10-30 17:39:12 +1100129}
130#else
131static inline void
132xfs_trans_ail_copy_lsn(
133 struct xfs_ail *ailp,
134 xfs_lsn_t *dst,
135 xfs_lsn_t *src)
136{
137 ASSERT(sizeof(xfs_lsn_t) == 8);
138 *dst = *src;
139}
140#endif
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700141
142static inline void
143xfs_clear_li_failed(
144 struct xfs_log_item *lip)
145{
146 struct xfs_buf *bp = lip->li_buf;
147
Dave Chinner22525c12018-05-09 07:47:34 -0700148 ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
Matthew Wilcox57e80952018-03-07 14:59:39 -0800149 lockdep_assert_held(&lip->li_ailp->ail_lock);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700150
Dave Chinner22525c12018-05-09 07:47:34 -0700151 if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700152 lip->li_buf = NULL;
153 xfs_buf_rele(bp);
154 }
155}
156
157static inline void
158xfs_set_li_failed(
159 struct xfs_log_item *lip,
160 struct xfs_buf *bp)
161{
Matthew Wilcox57e80952018-03-07 14:59:39 -0800162 lockdep_assert_held(&lip->li_ailp->ail_lock);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700163
Dave Chinner22525c12018-05-09 07:47:34 -0700164 if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700165 xfs_buf_hold(bp);
Carlos Maiolinod3a304b2017-08-08 18:21:50 -0700166 lip->li_buf = bp;
167 }
168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#endif /* __XFS_TRANS_PRIV_H__ */