]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 LT |
17 | */ |
18 | #ifndef __XFS_TRANS_PRIV_H__ | |
19 | #define __XFS_TRANS_PRIV_H__ | |
20 | ||
21 | struct xfs_log_item; | |
1da177e4 LT |
22 | struct xfs_mount; |
23 | struct xfs_trans; | |
0e57f6a3 DC |
24 | struct xfs_ail; |
25 | struct xfs_log_vec; | |
1da177e4 | 26 | |
d386b32b DC |
27 | |
28 | void xfs_trans_init(struct xfs_mount *); | |
e98c414f CH |
29 | void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *); |
30 | void xfs_trans_del_item(struct xfs_log_item *); | |
d17c701c | 31 | void xfs_trans_free_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn, |
eacb24e7 | 32 | bool abort); |
71e330b5 | 33 | void xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp); |
1da177e4 | 34 | |
0e57f6a3 DC |
35 | void xfs_trans_committed_bulk(struct xfs_ail *ailp, struct xfs_log_vec *lv, |
36 | xfs_lsn_t commit_lsn, int aborted); | |
1da177e4 | 37 | /* |
27d8d5fe DC |
38 | * AIL traversal cursor. |
39 | * | |
40 | * Rather than using a generation number for detecting changes in the ail, use | |
41 | * a cursor that is protected by the ail lock. The aild cursor exists in the | |
42 | * struct xfs_ail, but other traversals can declare it on the stack and link it | |
43 | * to the ail list. | |
44 | * | |
45 | * When an object is deleted from or moved int the AIL, the cursor list is | |
46 | * searched to see if the object is a designated cursor item. If it is, it is | |
47 | * deleted from the cursor so that the next time the cursor is used traversal | |
48 | * will return to the start. | |
49 | * | |
50 | * This means a traversal colliding with a removal will cause a restart of the | |
51 | * list scan, rather than any insertion or deletion anywhere in the list. The | |
52 | * low bit of the item pointer is set if the cursor has been invalidated so | |
53 | * that we can tell the difference between invalidation and reaching the end | |
54 | * of the list to trigger traversal restarts. | |
1da177e4 | 55 | */ |
27d8d5fe | 56 | struct xfs_ail_cursor { |
af3e4022 | 57 | struct list_head list; |
27d8d5fe DC |
58 | struct xfs_log_item *item; |
59 | }; | |
1da177e4 | 60 | |
249a8c11 | 61 | /* |
27d8d5fe DC |
62 | * Private AIL structures. |
63 | * | |
64 | * Eventually we need to drive the locking in here as well. | |
249a8c11 | 65 | */ |
82fa9012 | 66 | struct xfs_ail { |
57e80956 MW |
67 | struct xfs_mount *ail_mount; |
68 | struct task_struct *ail_task; | |
69 | struct list_head ail_head; | |
70 | xfs_lsn_t ail_target; | |
71 | xfs_lsn_t ail_target_prev; | |
72 | struct list_head ail_cursors; | |
73 | spinlock_t ail_lock; | |
74 | xfs_lsn_t ail_last_pushed_lsn; | |
75 | int ail_log_flush; | |
76 | struct list_head ail_buf_list; | |
77 | wait_queue_head_t ail_empty; | |
82fa9012 DC |
78 | }; |
79 | ||
27d8d5fe DC |
80 | /* |
81 | * From xfs_trans_ail.c | |
82 | */ | |
e6059949 | 83 | void xfs_trans_ail_update_bulk(struct xfs_ail *ailp, |
1d8c95a3 | 84 | struct xfs_ail_cursor *cur, |
e6059949 | 85 | struct xfs_log_item **log_items, int nr_items, |
57e80956 | 86 | xfs_lsn_t lsn) __releases(ailp->ail_lock); |
8d1d4083 JL |
87 | /* |
88 | * Return a pointer to the first item in the AIL. If the AIL is empty, then | |
89 | * return NULL. | |
90 | */ | |
91 | static inline struct xfs_log_item * | |
92 | xfs_ail_min( | |
93 | struct xfs_ail *ailp) | |
94 | { | |
57e80956 | 95 | return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item, |
8d1d4083 JL |
96 | li_ail); |
97 | } | |
98 | ||
e6059949 DC |
99 | static inline void |
100 | xfs_trans_ail_update( | |
101 | struct xfs_ail *ailp, | |
102 | struct xfs_log_item *lip, | |
57e80956 | 103 | xfs_lsn_t lsn) __releases(ailp->ail_lock) |
e6059949 | 104 | { |
1d8c95a3 | 105 | xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn); |
e6059949 DC |
106 | } |
107 | ||
27af1bbf CH |
108 | bool xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip); |
109 | void xfs_trans_ail_delete(struct xfs_ail *ailp, struct xfs_log_item *lip, | |
57e80956 | 110 | int shutdown_type) __releases(ailp->ail_lock); |
9552e7f2 | 111 | |
146e54b7 BF |
112 | static inline void |
113 | xfs_trans_ail_remove( | |
114 | struct xfs_log_item *lip, | |
115 | int shutdown_type) | |
116 | { | |
117 | struct xfs_ail *ailp = lip->li_ailp; | |
118 | ||
57e80956 | 119 | spin_lock(&ailp->ail_lock); |
146e54b7 | 120 | /* xfs_trans_ail_delete() drops the AIL lock */ |
22525c17 | 121 | if (test_bit(XFS_LI_IN_AIL, &lip->li_flags)) |
146e54b7 BF |
122 | xfs_trans_ail_delete(ailp, lip, shutdown_type); |
123 | else | |
57e80956 | 124 | spin_unlock(&ailp->ail_lock); |
146e54b7 BF |
125 | } |
126 | ||
fd074841 DC |
127 | void xfs_ail_push(struct xfs_ail *, xfs_lsn_t); |
128 | void xfs_ail_push_all(struct xfs_ail *); | |
211e4d43 | 129 | void xfs_ail_push_all_sync(struct xfs_ail *); |
1c304625 | 130 | struct xfs_log_item *xfs_ail_min(struct xfs_ail *ailp); |
fd074841 DC |
131 | xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp); |
132 | ||
1d8c95a3 | 133 | struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp, |
5b00f14f DC |
134 | struct xfs_ail_cursor *cur, |
135 | xfs_lsn_t lsn); | |
1d8c95a3 DC |
136 | struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp, |
137 | struct xfs_ail_cursor *cur, | |
138 | xfs_lsn_t lsn); | |
139 | struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp, | |
27d8d5fe | 140 | struct xfs_ail_cursor *cur); |
e4a1e29c | 141 | void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur); |
27d8d5fe | 142 | |
7b2e2a31 DC |
143 | #if BITS_PER_LONG != 64 |
144 | static inline void | |
145 | xfs_trans_ail_copy_lsn( | |
146 | struct xfs_ail *ailp, | |
147 | xfs_lsn_t *dst, | |
148 | xfs_lsn_t *src) | |
149 | { | |
150 | ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */ | |
57e80956 | 151 | spin_lock(&ailp->ail_lock); |
7b2e2a31 | 152 | *dst = *src; |
57e80956 | 153 | spin_unlock(&ailp->ail_lock); |
7b2e2a31 DC |
154 | } |
155 | #else | |
156 | static inline void | |
157 | xfs_trans_ail_copy_lsn( | |
158 | struct xfs_ail *ailp, | |
159 | xfs_lsn_t *dst, | |
160 | xfs_lsn_t *src) | |
161 | { | |
162 | ASSERT(sizeof(xfs_lsn_t) == 8); | |
163 | *dst = *src; | |
164 | } | |
165 | #endif | |
d3a304b6 CM |
166 | |
167 | static inline void | |
168 | xfs_clear_li_failed( | |
169 | struct xfs_log_item *lip) | |
170 | { | |
171 | struct xfs_buf *bp = lip->li_buf; | |
172 | ||
22525c17 | 173 | ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags)); |
57e80956 | 174 | lockdep_assert_held(&lip->li_ailp->ail_lock); |
d3a304b6 | 175 | |
22525c17 | 176 | if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) { |
d3a304b6 CM |
177 | lip->li_buf = NULL; |
178 | xfs_buf_rele(bp); | |
179 | } | |
180 | } | |
181 | ||
182 | static inline void | |
183 | xfs_set_li_failed( | |
184 | struct xfs_log_item *lip, | |
185 | struct xfs_buf *bp) | |
186 | { | |
57e80956 | 187 | lockdep_assert_held(&lip->li_ailp->ail_lock); |
d3a304b6 | 188 | |
22525c17 | 189 | if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) { |
d3a304b6 | 190 | xfs_buf_hold(bp); |
d3a304b6 CM |
191 | lip->li_buf = bp; |
192 | } | |
193 | } | |
194 | ||
1da177e4 | 195 | #endif /* __XFS_TRANS_PRIV_H__ */ |