xref: /linux/fs/xfs/xfs_trans_priv.h (revision 613e2fdbbc7b4bd0cd324e3a025b3061eb8c947d)
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 	xfs_lsn_t		ail_target;
56 	xfs_lsn_t		ail_target_prev;
57 	struct list_head	ail_cursors;
58 	spinlock_t		ail_lock;
59 	xfs_lsn_t		ail_last_pushed_lsn;
60 	int			ail_log_flush;
61 	struct list_head	ail_buf_list;
62 	wait_queue_head_t	ail_empty;
63 };
64 
65 /*
66  * From xfs_trans_ail.c
67  */
68 void	xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
69 				struct xfs_ail_cursor *cur,
70 				struct xfs_log_item **log_items, int nr_items,
71 				xfs_lsn_t lsn) __releases(ailp->ail_lock);
72 /*
73  * Return a pointer to the first item in the AIL.  If the AIL is empty, then
74  * return NULL.
75  */
76 static inline struct xfs_log_item *
77 xfs_ail_min(
78 	struct xfs_ail  *ailp)
79 {
80 	return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item,
81 					li_ail);
82 }
83 
84 static inline void
85 xfs_trans_ail_update(
86 	struct xfs_ail		*ailp,
87 	struct xfs_log_item	*lip,
88 	xfs_lsn_t		lsn) __releases(ailp->ail_lock)
89 {
90 	xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn);
91 }
92 
93 void xfs_trans_ail_insert(struct xfs_ail *ailp, struct xfs_log_item *lip,
94 		xfs_lsn_t lsn);
95 
96 xfs_lsn_t xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip);
97 void xfs_ail_update_finish(struct xfs_ail *ailp, xfs_lsn_t old_lsn)
98 			__releases(ailp->ail_lock);
99 void xfs_trans_ail_delete(struct xfs_log_item *lip, int shutdown_type);
100 
101 void			xfs_ail_push(struct xfs_ail *, xfs_lsn_t);
102 void			xfs_ail_push_all(struct xfs_ail *);
103 void			xfs_ail_push_all_sync(struct xfs_ail *);
104 struct xfs_log_item	*xfs_ail_min(struct xfs_ail  *ailp);
105 xfs_lsn_t		xfs_ail_min_lsn(struct xfs_ail *ailp);
106 
107 struct xfs_log_item *	xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
108 					struct xfs_ail_cursor *cur,
109 					xfs_lsn_t lsn);
110 struct xfs_log_item *	xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
111 					struct xfs_ail_cursor *cur,
112 					xfs_lsn_t lsn);
113 struct xfs_log_item *	xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
114 					struct xfs_ail_cursor *cur);
115 void			xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
116 
117 #if BITS_PER_LONG != 64
118 static inline void
119 xfs_trans_ail_copy_lsn(
120 	struct xfs_ail	*ailp,
121 	xfs_lsn_t	*dst,
122 	xfs_lsn_t	*src)
123 {
124 	ASSERT(sizeof(xfs_lsn_t) == 8);	/* don't lock if it shrinks */
125 	spin_lock(&ailp->ail_lock);
126 	*dst = *src;
127 	spin_unlock(&ailp->ail_lock);
128 }
129 #else
130 static inline void
131 xfs_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);
137 	*dst = *src;
138 }
139 #endif
140 
141 static inline void
142 xfs_clear_li_failed(
143 	struct xfs_log_item	*lip)
144 {
145 	struct xfs_buf	*bp = lip->li_buf;
146 
147 	ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
148 	lockdep_assert_held(&lip->li_ailp->ail_lock);
149 
150 	if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
151 		lip->li_buf = NULL;
152 		xfs_buf_rele(bp);
153 	}
154 }
155 
156 static inline void
157 xfs_set_li_failed(
158 	struct xfs_log_item	*lip,
159 	struct xfs_buf		*bp)
160 {
161 	lockdep_assert_held(&lip->li_ailp->ail_lock);
162 
163 	if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
164 		xfs_buf_hold(bp);
165 		lip->li_buf = bp;
166 	}
167 }
168 
169 #endif	/* __XFS_TRANS_PRIV_H__ */
170