diff options
Diffstat (limited to 'fs/xfs/xfs_trans_ail.c')
-rw-r--r-- | fs/xfs/xfs_trans_ail.c | 362 |
1 files changed, 219 insertions, 143 deletions
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c index 1f77c00af566..2d47f10f8bed 100644 --- a/fs/xfs/xfs_trans_ail.c +++ b/fs/xfs/xfs_trans_ail.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. | 2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * Copyright (c) 2008 Dave Chinner | ||
3 | * All Rights Reserved. | 4 | * All Rights Reserved. |
4 | * | 5 | * |
5 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
@@ -28,13 +29,13 @@ | |||
28 | #include "xfs_trans_priv.h" | 29 | #include "xfs_trans_priv.h" |
29 | #include "xfs_error.h" | 30 | #include "xfs_error.h" |
30 | 31 | ||
31 | STATIC void xfs_ail_insert(xfs_ail_t *, xfs_log_item_t *); | 32 | STATIC void xfs_ail_insert(struct xfs_ail *, xfs_log_item_t *); |
32 | STATIC xfs_log_item_t * xfs_ail_delete(xfs_ail_t *, xfs_log_item_t *); | 33 | STATIC xfs_log_item_t * xfs_ail_delete(struct xfs_ail *, xfs_log_item_t *); |
33 | STATIC xfs_log_item_t * xfs_ail_min(xfs_ail_t *); | 34 | STATIC xfs_log_item_t * xfs_ail_min(struct xfs_ail *); |
34 | STATIC xfs_log_item_t * xfs_ail_next(xfs_ail_t *, xfs_log_item_t *); | 35 | STATIC xfs_log_item_t * xfs_ail_next(struct xfs_ail *, xfs_log_item_t *); |
35 | 36 | ||
36 | #ifdef DEBUG | 37 | #ifdef DEBUG |
37 | STATIC void xfs_ail_check(xfs_ail_t *, xfs_log_item_t *); | 38 | STATIC void xfs_ail_check(struct xfs_ail *, xfs_log_item_t *); |
38 | #else | 39 | #else |
39 | #define xfs_ail_check(a,l) | 40 | #define xfs_ail_check(a,l) |
40 | #endif /* DEBUG */ | 41 | #endif /* DEBUG */ |
@@ -50,20 +51,20 @@ STATIC void xfs_ail_check(xfs_ail_t *, xfs_log_item_t *); | |||
50 | * lsn of the last item in the AIL. | 51 | * lsn of the last item in the AIL. |
51 | */ | 52 | */ |
52 | xfs_lsn_t | 53 | xfs_lsn_t |
53 | xfs_trans_tail_ail( | 54 | xfs_trans_ail_tail( |
54 | xfs_mount_t *mp) | 55 | struct xfs_ail *ailp) |
55 | { | 56 | { |
56 | xfs_lsn_t lsn; | 57 | xfs_lsn_t lsn; |
57 | xfs_log_item_t *lip; | 58 | xfs_log_item_t *lip; |
58 | 59 | ||
59 | spin_lock(&mp->m_ail_lock); | 60 | spin_lock(&ailp->xa_lock); |
60 | lip = xfs_ail_min(&mp->m_ail); | 61 | lip = xfs_ail_min(ailp); |
61 | if (lip == NULL) { | 62 | if (lip == NULL) { |
62 | lsn = (xfs_lsn_t)0; | 63 | lsn = (xfs_lsn_t)0; |
63 | } else { | 64 | } else { |
64 | lsn = lip->li_lsn; | 65 | lsn = lip->li_lsn; |
65 | } | 66 | } |
66 | spin_unlock(&mp->m_ail_lock); | 67 | spin_unlock(&ailp->xa_lock); |
67 | 68 | ||
68 | return lsn; | 69 | return lsn; |
69 | } | 70 | } |
@@ -85,16 +86,125 @@ xfs_trans_tail_ail( | |||
85 | * any of the objects, so the lock is not needed. | 86 | * any of the objects, so the lock is not needed. |
86 | */ | 87 | */ |
87 | void | 88 | void |
88 | xfs_trans_push_ail( | 89 | xfs_trans_ail_push( |
89 | xfs_mount_t *mp, | 90 | struct xfs_ail *ailp, |
90 | xfs_lsn_t threshold_lsn) | 91 | xfs_lsn_t threshold_lsn) |
91 | { | 92 | { |
92 | xfs_log_item_t *lip; | 93 | xfs_log_item_t *lip; |
94 | |||
95 | lip = xfs_ail_min(ailp); | ||
96 | if (lip && !XFS_FORCED_SHUTDOWN(ailp->xa_mount)) { | ||
97 | if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) | ||
98 | xfsaild_wakeup(ailp, threshold_lsn); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * AIL traversal cursor initialisation. | ||
104 | * | ||
105 | * The cursor keeps track of where our current traversal is up | ||
106 | * to by tracking the next ƣtem in the list for us. However, for | ||
107 | * this to be safe, removing an object from the AIL needs to invalidate | ||
108 | * any cursor that points to it. hence the traversal cursor needs to | ||
109 | * be linked to the struct xfs_ail so that deletion can search all the | ||
110 | * active cursors for invalidation. | ||
111 | * | ||
112 | * We don't link the push cursor because it is embedded in the struct | ||
113 | * xfs_ail and hence easily findable. | ||
114 | */ | ||
115 | STATIC void | ||
116 | xfs_trans_ail_cursor_init( | ||
117 | struct xfs_ail *ailp, | ||
118 | struct xfs_ail_cursor *cur) | ||
119 | { | ||
120 | cur->item = NULL; | ||
121 | if (cur == &ailp->xa_cursors) | ||
122 | return; | ||
123 | |||
124 | cur->next = ailp->xa_cursors.next; | ||
125 | ailp->xa_cursors.next = cur; | ||
126 | } | ||
127 | |||
128 | /* | ||
129 | * Set the cursor to the next item, because when we look | ||
130 | * up the cursor the current item may have been freed. | ||
131 | */ | ||
132 | STATIC void | ||
133 | xfs_trans_ail_cursor_set( | ||
134 | struct xfs_ail *ailp, | ||
135 | struct xfs_ail_cursor *cur, | ||
136 | struct xfs_log_item *lip) | ||
137 | { | ||
138 | if (lip) | ||
139 | cur->item = xfs_ail_next(ailp, lip); | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * Get the next item in the traversal and advance the cursor. | ||
144 | * If the cursor was invalidated (inidicated by a lip of 1), | ||
145 | * restart the traversal. | ||
146 | */ | ||
147 | struct xfs_log_item * | ||
148 | xfs_trans_ail_cursor_next( | ||
149 | struct xfs_ail *ailp, | ||
150 | struct xfs_ail_cursor *cur) | ||
151 | { | ||
152 | struct xfs_log_item *lip = cur->item; | ||
153 | |||
154 | if ((__psint_t)lip & 1) | ||
155 | lip = xfs_ail_min(ailp); | ||
156 | xfs_trans_ail_cursor_set(ailp, cur, lip); | ||
157 | return lip; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * Now that the traversal is complete, we need to remove the cursor | ||
162 | * from the list of traversing cursors. Avoid removing the embedded | ||
163 | * push cursor, but use the fact it is alway present to make the | ||
164 | * list deletion simple. | ||
165 | */ | ||
166 | void | ||
167 | xfs_trans_ail_cursor_done( | ||
168 | struct xfs_ail *ailp, | ||
169 | struct xfs_ail_cursor *done) | ||
170 | { | ||
171 | struct xfs_ail_cursor *prev = NULL; | ||
172 | struct xfs_ail_cursor *cur; | ||
173 | |||
174 | done->item = NULL; | ||
175 | if (done == &ailp->xa_cursors) | ||
176 | return; | ||
177 | prev = &ailp->xa_cursors; | ||
178 | for (cur = prev->next; cur; prev = cur, cur = prev->next) { | ||
179 | if (cur == done) { | ||
180 | prev->next = cur->next; | ||
181 | break; | ||
182 | } | ||
183 | } | ||
184 | ASSERT(cur); | ||
185 | } | ||
186 | |||
187 | /* | ||
188 | * Invalidate any cursor that is pointing to this item. This is | ||
189 | * called when an item is removed from the AIL. Any cursor pointing | ||
190 | * to this object is now invalid and the traversal needs to be | ||
191 | * terminated so it doesn't reference a freed object. We set the | ||
192 | * cursor item to a value of 1 so we can distinguish between an | ||
193 | * invalidation and the end of the list when getting the next item | ||
194 | * from the cursor. | ||
195 | */ | ||
196 | STATIC void | ||
197 | xfs_trans_ail_cursor_clear( | ||
198 | struct xfs_ail *ailp, | ||
199 | struct xfs_log_item *lip) | ||
200 | { | ||
201 | struct xfs_ail_cursor *cur; | ||
93 | 202 | ||
94 | lip = xfs_ail_min(&mp->m_ail); | 203 | /* need to search all cursors */ |
95 | if (lip && !XFS_FORCED_SHUTDOWN(mp)) { | 204 | for (cur = &ailp->xa_cursors; cur; cur = cur->next) { |
96 | if (XFS_LSN_CMP(threshold_lsn, mp->m_ail.xa_target) > 0) | 205 | if (cur->item == lip) |
97 | xfsaild_wakeup(mp, threshold_lsn); | 206 | cur->item = (struct xfs_log_item *) |
207 | ((__psint_t)cur->item | 1); | ||
98 | } | 208 | } |
99 | } | 209 | } |
100 | 210 | ||
@@ -103,25 +213,27 @@ xfs_trans_push_ail( | |||
103 | * Return the current tree generation number for use | 213 | * Return the current tree generation number for use |
104 | * in calls to xfs_trans_next_ail(). | 214 | * in calls to xfs_trans_next_ail(). |
105 | */ | 215 | */ |
106 | STATIC xfs_log_item_t * | 216 | xfs_log_item_t * |
107 | xfs_trans_first_push_ail( | 217 | xfs_trans_ail_cursor_first( |
108 | xfs_mount_t *mp, | 218 | struct xfs_ail *ailp, |
109 | int *gen, | 219 | struct xfs_ail_cursor *cur, |
110 | xfs_lsn_t lsn) | 220 | xfs_lsn_t lsn) |
111 | { | 221 | { |
112 | xfs_log_item_t *lip; | 222 | xfs_log_item_t *lip; |
113 | 223 | ||
114 | lip = xfs_ail_min(&mp->m_ail); | 224 | xfs_trans_ail_cursor_init(ailp, cur); |
115 | *gen = (int)mp->m_ail.xa_gen; | 225 | lip = xfs_ail_min(ailp); |
116 | if (lsn == 0) | 226 | if (lsn == 0) |
117 | return lip; | 227 | goto out; |
118 | 228 | ||
119 | list_for_each_entry(lip, &mp->m_ail.xa_ail, li_ail) { | 229 | list_for_each_entry(lip, &ailp->xa_ail, li_ail) { |
120 | if (XFS_LSN_CMP(lip->li_lsn, lsn) >= 0) | 230 | if (XFS_LSN_CMP(lip->li_lsn, lsn) >= 0) |
121 | return lip; | 231 | goto out; |
122 | } | 232 | } |
123 | 233 | lip = NULL; | |
124 | return NULL; | 234 | out: |
235 | xfs_trans_ail_cursor_set(ailp, cur, lip); | ||
236 | return lip; | ||
125 | } | 237 | } |
126 | 238 | ||
127 | /* | 239 | /* |
@@ -129,29 +241,29 @@ xfs_trans_first_push_ail( | |||
129 | */ | 241 | */ |
130 | long | 242 | long |
131 | xfsaild_push( | 243 | xfsaild_push( |
132 | xfs_mount_t *mp, | 244 | struct xfs_ail *ailp, |
133 | xfs_lsn_t *last_lsn) | 245 | xfs_lsn_t *last_lsn) |
134 | { | 246 | { |
135 | long tout = 1000; /* milliseconds */ | 247 | long tout = 1000; /* milliseconds */ |
136 | xfs_lsn_t last_pushed_lsn = *last_lsn; | 248 | xfs_lsn_t last_pushed_lsn = *last_lsn; |
137 | xfs_lsn_t target = mp->m_ail.xa_target; | 249 | xfs_lsn_t target = ailp->xa_target; |
138 | xfs_lsn_t lsn; | 250 | xfs_lsn_t lsn; |
139 | xfs_log_item_t *lip; | 251 | xfs_log_item_t *lip; |
140 | int gen; | ||
141 | int restarts; | ||
142 | int flush_log, count, stuck; | 252 | int flush_log, count, stuck; |
253 | xfs_mount_t *mp = ailp->xa_mount; | ||
254 | struct xfs_ail_cursor *cur = &ailp->xa_cursors; | ||
143 | 255 | ||
144 | #define XFS_TRANS_PUSH_AIL_RESTARTS 10 | 256 | spin_lock(&ailp->xa_lock); |
145 | 257 | xfs_trans_ail_cursor_init(ailp, cur); | |
146 | spin_lock(&mp->m_ail_lock); | 258 | lip = xfs_trans_ail_cursor_first(ailp, cur, *last_lsn); |
147 | lip = xfs_trans_first_push_ail(mp, &gen, *last_lsn); | ||
148 | if (!lip || XFS_FORCED_SHUTDOWN(mp)) { | 259 | if (!lip || XFS_FORCED_SHUTDOWN(mp)) { |
149 | /* | 260 | /* |
150 | * AIL is empty or our push has reached the end. | 261 | * AIL is empty or our push has reached the end. |
151 | */ | 262 | */ |
152 | spin_unlock(&mp->m_ail_lock); | 263 | xfs_trans_ail_cursor_done(ailp, cur); |
264 | spin_unlock(&ailp->xa_lock); | ||
153 | last_pushed_lsn = 0; | 265 | last_pushed_lsn = 0; |
154 | goto out; | 266 | return tout; |
155 | } | 267 | } |
156 | 268 | ||
157 | XFS_STATS_INC(xs_push_ail); | 269 | XFS_STATS_INC(xs_push_ail); |
@@ -169,7 +281,7 @@ xfsaild_push( | |||
169 | */ | 281 | */ |
170 | tout = 10; | 282 | tout = 10; |
171 | lsn = lip->li_lsn; | 283 | lsn = lip->li_lsn; |
172 | flush_log = stuck = count = restarts = 0; | 284 | flush_log = stuck = count = 0; |
173 | while ((XFS_LSN_CMP(lip->li_lsn, target) < 0)) { | 285 | while ((XFS_LSN_CMP(lip->li_lsn, target) < 0)) { |
174 | int lock_result; | 286 | int lock_result; |
175 | /* | 287 | /* |
@@ -184,7 +296,7 @@ xfsaild_push( | |||
184 | * skip to the next item in the list. | 296 | * skip to the next item in the list. |
185 | */ | 297 | */ |
186 | lock_result = IOP_TRYLOCK(lip); | 298 | lock_result = IOP_TRYLOCK(lip); |
187 | spin_unlock(&mp->m_ail_lock); | 299 | spin_unlock(&ailp->xa_lock); |
188 | switch (lock_result) { | 300 | switch (lock_result) { |
189 | case XFS_ITEM_SUCCESS: | 301 | case XFS_ITEM_SUCCESS: |
190 | XFS_STATS_INC(xs_push_ail_success); | 302 | XFS_STATS_INC(xs_push_ail_success); |
@@ -221,7 +333,7 @@ xfsaild_push( | |||
221 | break; | 333 | break; |
222 | } | 334 | } |
223 | 335 | ||
224 | spin_lock(&mp->m_ail_lock); | 336 | spin_lock(&ailp->xa_lock); |
225 | /* should we bother continuing? */ | 337 | /* should we bother continuing? */ |
226 | if (XFS_FORCED_SHUTDOWN(mp)) | 338 | if (XFS_FORCED_SHUTDOWN(mp)) |
227 | break; | 339 | break; |
@@ -244,14 +356,13 @@ xfsaild_push( | |||
244 | if (stuck > 100) | 356 | if (stuck > 100) |
245 | break; | 357 | break; |
246 | 358 | ||
247 | lip = xfs_trans_next_ail(mp, lip, &gen, &restarts); | 359 | lip = xfs_trans_ail_cursor_next(ailp, cur); |
248 | if (lip == NULL) | 360 | if (lip == NULL) |
249 | break; | 361 | break; |
250 | if (restarts > XFS_TRANS_PUSH_AIL_RESTARTS) | ||
251 | break; | ||
252 | lsn = lip->li_lsn; | 362 | lsn = lip->li_lsn; |
253 | } | 363 | } |
254 | spin_unlock(&mp->m_ail_lock); | 364 | xfs_trans_ail_cursor_done(ailp, cur); |
365 | spin_unlock(&ailp->xa_lock); | ||
255 | 366 | ||
256 | if (flush_log) { | 367 | if (flush_log) { |
257 | /* | 368 | /* |
@@ -274,8 +385,7 @@ xfsaild_push( | |||
274 | */ | 385 | */ |
275 | tout += 20; | 386 | tout += 20; |
276 | last_pushed_lsn = 0; | 387 | last_pushed_lsn = 0; |
277 | } else if ((restarts > XFS_TRANS_PUSH_AIL_RESTARTS) || | 388 | } else if ((stuck * 100) / count > 90) { |
278 | ((stuck * 100) / count > 90)) { | ||
279 | /* | 389 | /* |
280 | * Either there is a lot of contention on the AIL or we | 390 | * Either there is a lot of contention on the AIL or we |
281 | * are stuck due to operations in progress. "Stuck" in this | 391 | * are stuck due to operations in progress. "Stuck" in this |
@@ -287,7 +397,6 @@ xfsaild_push( | |||
287 | */ | 397 | */ |
288 | tout += 10; | 398 | tout += 10; |
289 | } | 399 | } |
290 | out: | ||
291 | *last_lsn = last_pushed_lsn; | 400 | *last_lsn = last_pushed_lsn; |
292 | return tout; | 401 | return tout; |
293 | } /* xfsaild_push */ | 402 | } /* xfsaild_push */ |
@@ -303,7 +412,7 @@ out: | |||
303 | */ | 412 | */ |
304 | void | 413 | void |
305 | xfs_trans_unlocked_item( | 414 | xfs_trans_unlocked_item( |
306 | xfs_mount_t *mp, | 415 | struct xfs_ail *ailp, |
307 | xfs_log_item_t *lip) | 416 | xfs_log_item_t *lip) |
308 | { | 417 | { |
309 | xfs_log_item_t *min_lip; | 418 | xfs_log_item_t *min_lip; |
@@ -315,7 +424,7 @@ xfs_trans_unlocked_item( | |||
315 | * over some potentially valid data. | 424 | * over some potentially valid data. |
316 | */ | 425 | */ |
317 | if (!(lip->li_flags & XFS_LI_IN_AIL) || | 426 | if (!(lip->li_flags & XFS_LI_IN_AIL) || |
318 | XFS_FORCED_SHUTDOWN(mp)) { | 427 | XFS_FORCED_SHUTDOWN(ailp->xa_mount)) { |
319 | return; | 428 | return; |
320 | } | 429 | } |
321 | 430 | ||
@@ -331,10 +440,10 @@ xfs_trans_unlocked_item( | |||
331 | * the call to xfs_log_move_tail() doesn't do anything if there's | 440 | * the call to xfs_log_move_tail() doesn't do anything if there's |
332 | * not enough free space to wake people up so we're safe calling it. | 441 | * not enough free space to wake people up so we're safe calling it. |
333 | */ | 442 | */ |
334 | min_lip = xfs_ail_min(&mp->m_ail); | 443 | min_lip = xfs_ail_min(ailp); |
335 | 444 | ||
336 | if (min_lip == lip) | 445 | if (min_lip == lip) |
337 | xfs_log_move_tail(mp, 1); | 446 | xfs_log_move_tail(ailp->xa_mount, 1); |
338 | } /* xfs_trans_unlocked_item */ | 447 | } /* xfs_trans_unlocked_item */ |
339 | 448 | ||
340 | 449 | ||
@@ -347,41 +456,37 @@ xfs_trans_unlocked_item( | |||
347 | * we move in the AIL is the minimum one, update the tail lsn in the | 456 | * we move in the AIL is the minimum one, update the tail lsn in the |
348 | * log manager. | 457 | * log manager. |
349 | * | 458 | * |
350 | * Increment the AIL's generation count to indicate that the tree | ||
351 | * has changed. | ||
352 | * | ||
353 | * This function must be called with the AIL lock held. The lock | 459 | * This function must be called with the AIL lock held. The lock |
354 | * is dropped before returning. | 460 | * is dropped before returning. |
355 | */ | 461 | */ |
356 | void | 462 | void |
357 | xfs_trans_update_ail( | 463 | xfs_trans_ail_update( |
358 | xfs_mount_t *mp, | 464 | struct xfs_ail *ailp, |
359 | xfs_log_item_t *lip, | 465 | xfs_log_item_t *lip, |
360 | xfs_lsn_t lsn) __releases(mp->m_ail_lock) | 466 | xfs_lsn_t lsn) __releases(ailp->xa_lock) |
361 | { | 467 | { |
362 | xfs_log_item_t *dlip=NULL; | 468 | xfs_log_item_t *dlip = NULL; |
363 | xfs_log_item_t *mlip; /* ptr to minimum lip */ | 469 | xfs_log_item_t *mlip; /* ptr to minimum lip */ |
364 | 470 | ||
365 | mlip = xfs_ail_min(&mp->m_ail); | 471 | mlip = xfs_ail_min(ailp); |
366 | 472 | ||
367 | if (lip->li_flags & XFS_LI_IN_AIL) { | 473 | if (lip->li_flags & XFS_LI_IN_AIL) { |
368 | dlip = xfs_ail_delete(&mp->m_ail, lip); | 474 | dlip = xfs_ail_delete(ailp, lip); |
369 | ASSERT(dlip == lip); | 475 | ASSERT(dlip == lip); |
476 | xfs_trans_ail_cursor_clear(ailp, dlip); | ||
370 | } else { | 477 | } else { |
371 | lip->li_flags |= XFS_LI_IN_AIL; | 478 | lip->li_flags |= XFS_LI_IN_AIL; |
372 | } | 479 | } |
373 | 480 | ||
374 | lip->li_lsn = lsn; | 481 | lip->li_lsn = lsn; |
375 | 482 | xfs_ail_insert(ailp, lip); | |
376 | xfs_ail_insert(&mp->m_ail, lip); | ||
377 | mp->m_ail.xa_gen++; | ||
378 | 483 | ||
379 | if (mlip == dlip) { | 484 | if (mlip == dlip) { |
380 | mlip = xfs_ail_min(&mp->m_ail); | 485 | mlip = xfs_ail_min(ailp); |
381 | spin_unlock(&mp->m_ail_lock); | 486 | spin_unlock(&ailp->xa_lock); |
382 | xfs_log_move_tail(mp, mlip->li_lsn); | 487 | xfs_log_move_tail(ailp->xa_mount, mlip->li_lsn); |
383 | } else { | 488 | } else { |
384 | spin_unlock(&mp->m_ail_lock); | 489 | spin_unlock(&ailp->xa_lock); |
385 | } | 490 | } |
386 | 491 | ||
387 | 492 | ||
@@ -403,29 +508,30 @@ xfs_trans_update_ail( | |||
403 | * is dropped before returning. | 508 | * is dropped before returning. |
404 | */ | 509 | */ |
405 | void | 510 | void |
406 | xfs_trans_delete_ail( | 511 | xfs_trans_ail_delete( |
407 | xfs_mount_t *mp, | 512 | struct xfs_ail *ailp, |
408 | xfs_log_item_t *lip) __releases(mp->m_ail_lock) | 513 | xfs_log_item_t *lip) __releases(ailp->xa_lock) |
409 | { | 514 | { |
410 | xfs_log_item_t *dlip; | 515 | xfs_log_item_t *dlip; |
411 | xfs_log_item_t *mlip; | 516 | xfs_log_item_t *mlip; |
412 | 517 | ||
413 | if (lip->li_flags & XFS_LI_IN_AIL) { | 518 | if (lip->li_flags & XFS_LI_IN_AIL) { |
414 | mlip = xfs_ail_min(&mp->m_ail); | 519 | mlip = xfs_ail_min(ailp); |
415 | dlip = xfs_ail_delete(&mp->m_ail, lip); | 520 | dlip = xfs_ail_delete(ailp, lip); |
416 | ASSERT(dlip == lip); | 521 | ASSERT(dlip == lip); |
522 | xfs_trans_ail_cursor_clear(ailp, dlip); | ||
417 | 523 | ||
418 | 524 | ||
419 | lip->li_flags &= ~XFS_LI_IN_AIL; | 525 | lip->li_flags &= ~XFS_LI_IN_AIL; |
420 | lip->li_lsn = 0; | 526 | lip->li_lsn = 0; |
421 | mp->m_ail.xa_gen++; | ||
422 | 527 | ||
423 | if (mlip == dlip) { | 528 | if (mlip == dlip) { |
424 | mlip = xfs_ail_min(&mp->m_ail); | 529 | mlip = xfs_ail_min(ailp); |
425 | spin_unlock(&mp->m_ail_lock); | 530 | spin_unlock(&ailp->xa_lock); |
426 | xfs_log_move_tail(mp, (mlip ? mlip->li_lsn : 0)); | 531 | xfs_log_move_tail(ailp->xa_mount, |
532 | (mlip ? mlip->li_lsn : 0)); | ||
427 | } else { | 533 | } else { |
428 | spin_unlock(&mp->m_ail_lock); | 534 | spin_unlock(&ailp->xa_lock); |
429 | } | 535 | } |
430 | } | 536 | } |
431 | else { | 537 | else { |
@@ -433,13 +539,13 @@ xfs_trans_delete_ail( | |||
433 | * If the file system is not being shutdown, we are in | 539 | * If the file system is not being shutdown, we are in |
434 | * serious trouble if we get to this stage. | 540 | * serious trouble if we get to this stage. |
435 | */ | 541 | */ |
436 | if (XFS_FORCED_SHUTDOWN(mp)) | 542 | struct xfs_mount *mp = ailp->xa_mount; |
437 | spin_unlock(&mp->m_ail_lock); | 543 | |
438 | else { | 544 | spin_unlock(&ailp->xa_lock); |
545 | if (!XFS_FORCED_SHUTDOWN(mp)) { | ||
439 | xfs_cmn_err(XFS_PTAG_AILDELETE, CE_ALERT, mp, | 546 | xfs_cmn_err(XFS_PTAG_AILDELETE, CE_ALERT, mp, |
440 | "%s: attempting to delete a log item that is not in the AIL", | 547 | "%s: attempting to delete a log item that is not in the AIL", |
441 | __func__); | 548 | __func__); |
442 | spin_unlock(&mp->m_ail_lock); | ||
443 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); | 549 | xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); |
444 | } | 550 | } |
445 | } | 551 | } |
@@ -448,56 +554,6 @@ xfs_trans_delete_ail( | |||
448 | 554 | ||
449 | 555 | ||
450 | /* | 556 | /* |
451 | * Return the item in the AIL with the smallest lsn. | ||
452 | * Return the current tree generation number for use | ||
453 | * in calls to xfs_trans_next_ail(). | ||
454 | */ | ||
455 | xfs_log_item_t * | ||
456 | xfs_trans_first_ail( | ||
457 | xfs_mount_t *mp, | ||
458 | int *gen) | ||
459 | { | ||
460 | xfs_log_item_t *lip; | ||
461 | |||
462 | lip = xfs_ail_min(&mp->m_ail); | ||
463 | *gen = (int)mp->m_ail.xa_gen; | ||
464 | |||
465 | return lip; | ||
466 | } | ||
467 | |||
468 | /* | ||
469 | * If the generation count of the tree has not changed since the | ||
470 | * caller last took something from the AIL, then return the elmt | ||
471 | * in the tree which follows the one given. If the count has changed, | ||
472 | * then return the minimum elmt of the AIL and bump the restarts counter | ||
473 | * if one is given. | ||
474 | */ | ||
475 | xfs_log_item_t * | ||
476 | xfs_trans_next_ail( | ||
477 | xfs_mount_t *mp, | ||
478 | xfs_log_item_t *lip, | ||
479 | int *gen, | ||
480 | int *restarts) | ||
481 | { | ||
482 | xfs_log_item_t *nlip; | ||
483 | |||
484 | ASSERT(mp && lip && gen); | ||
485 | if (mp->m_ail.xa_gen == *gen) { | ||
486 | nlip = xfs_ail_next(&mp->m_ail, lip); | ||
487 | } else { | ||
488 | nlip = xfs_ail_min(&mp->m_ail); | ||
489 | *gen = (int)mp->m_ail.xa_gen; | ||
490 | if (restarts != NULL) { | ||
491 | XFS_STATS_INC(xs_push_ail_restarts); | ||
492 | (*restarts)++; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | return (nlip); | ||
497 | } | ||
498 | |||
499 | |||
500 | /* | ||
501 | * The active item list (AIL) is a doubly linked list of log | 557 | * The active item list (AIL) is a doubly linked list of log |
502 | * items sorted by ascending lsn. The base of the list is | 558 | * items sorted by ascending lsn. The base of the list is |
503 | * a forw/back pointer pair embedded in the xfs mount structure. | 559 | * a forw/back pointer pair embedded in the xfs mount structure. |
@@ -515,15 +571,35 @@ int | |||
515 | xfs_trans_ail_init( | 571 | xfs_trans_ail_init( |
516 | xfs_mount_t *mp) | 572 | xfs_mount_t *mp) |
517 | { | 573 | { |
518 | INIT_LIST_HEAD(&mp->m_ail.xa_ail); | 574 | struct xfs_ail *ailp; |
519 | return xfsaild_start(mp); | 575 | int error; |
576 | |||
577 | ailp = kmem_zalloc(sizeof(struct xfs_ail), KM_MAYFAIL); | ||
578 | if (!ailp) | ||
579 | return ENOMEM; | ||
580 | |||
581 | ailp->xa_mount = mp; | ||
582 | INIT_LIST_HEAD(&ailp->xa_ail); | ||
583 | spin_lock_init(&ailp->xa_lock); | ||
584 | error = xfsaild_start(ailp); | ||
585 | if (error) | ||
586 | goto out_free_ailp; | ||
587 | mp->m_ail = ailp; | ||
588 | return 0; | ||
589 | |||
590 | out_free_ailp: | ||
591 | kmem_free(ailp); | ||
592 | return error; | ||
520 | } | 593 | } |
521 | 594 | ||
522 | void | 595 | void |
523 | xfs_trans_ail_destroy( | 596 | xfs_trans_ail_destroy( |
524 | xfs_mount_t *mp) | 597 | xfs_mount_t *mp) |
525 | { | 598 | { |
526 | xfsaild_stop(mp); | 599 | struct xfs_ail *ailp = mp->m_ail; |
600 | |||
601 | xfsaild_stop(ailp); | ||
602 | kmem_free(ailp); | ||
527 | } | 603 | } |
528 | 604 | ||
529 | /* | 605 | /* |
@@ -534,7 +610,7 @@ xfs_trans_ail_destroy( | |||
534 | */ | 610 | */ |
535 | STATIC void | 611 | STATIC void |
536 | xfs_ail_insert( | 612 | xfs_ail_insert( |
537 | xfs_ail_t *ailp, | 613 | struct xfs_ail *ailp, |
538 | xfs_log_item_t *lip) | 614 | xfs_log_item_t *lip) |
539 | /* ARGSUSED */ | 615 | /* ARGSUSED */ |
540 | { | 616 | { |
@@ -568,7 +644,7 @@ xfs_ail_insert( | |||
568 | /*ARGSUSED*/ | 644 | /*ARGSUSED*/ |
569 | STATIC xfs_log_item_t * | 645 | STATIC xfs_log_item_t * |
570 | xfs_ail_delete( | 646 | xfs_ail_delete( |
571 | xfs_ail_t *ailp, | 647 | struct xfs_ail *ailp, |
572 | xfs_log_item_t *lip) | 648 | xfs_log_item_t *lip) |
573 | /* ARGSUSED */ | 649 | /* ARGSUSED */ |
574 | { | 650 | { |
@@ -585,7 +661,7 @@ xfs_ail_delete( | |||
585 | */ | 661 | */ |
586 | STATIC xfs_log_item_t * | 662 | STATIC xfs_log_item_t * |
587 | xfs_ail_min( | 663 | xfs_ail_min( |
588 | xfs_ail_t *ailp) | 664 | struct xfs_ail *ailp) |
589 | /* ARGSUSED */ | 665 | /* ARGSUSED */ |
590 | { | 666 | { |
591 | if (list_empty(&ailp->xa_ail)) | 667 | if (list_empty(&ailp->xa_ail)) |
@@ -601,7 +677,7 @@ xfs_ail_min( | |||
601 | */ | 677 | */ |
602 | STATIC xfs_log_item_t * | 678 | STATIC xfs_log_item_t * |
603 | xfs_ail_next( | 679 | xfs_ail_next( |
604 | xfs_ail_t *ailp, | 680 | struct xfs_ail *ailp, |
605 | xfs_log_item_t *lip) | 681 | xfs_log_item_t *lip) |
606 | /* ARGSUSED */ | 682 | /* ARGSUSED */ |
607 | { | 683 | { |
@@ -617,7 +693,7 @@ xfs_ail_next( | |||
617 | */ | 693 | */ |
618 | STATIC void | 694 | STATIC void |
619 | xfs_ail_check( | 695 | xfs_ail_check( |
620 | xfs_ail_t *ailp, | 696 | struct xfs_ail *ailp, |
621 | xfs_log_item_t *lip) | 697 | xfs_log_item_t *lip) |
622 | { | 698 | { |
623 | xfs_log_item_t *prev_lip; | 699 | xfs_log_item_t *prev_lip; |