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