xfs_trans_ail.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  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
  7. * published by the Free Software Foundation.
  8. *
  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.
  13. *
  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
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dmapi.h"
  27. #include "xfs_mount.h"
  28. #include "xfs_trans_priv.h"
  29. #include "xfs_error.h"
  30. STATIC void xfs_ail_insert(xfs_ail_entry_t *, xfs_log_item_t *);
  31. STATIC xfs_log_item_t * xfs_ail_delete(xfs_ail_entry_t *, xfs_log_item_t *);
  32. STATIC xfs_log_item_t * xfs_ail_min(xfs_ail_entry_t *);
  33. STATIC xfs_log_item_t * xfs_ail_next(xfs_ail_entry_t *, xfs_log_item_t *);
  34. #ifdef DEBUG
  35. STATIC void xfs_ail_check(xfs_ail_entry_t *, xfs_log_item_t *);
  36. #else
  37. #define xfs_ail_check(a,l)
  38. #endif /* DEBUG */
  39. /*
  40. * This is called by the log manager code to determine the LSN
  41. * of the tail of the log. This is exactly the LSN of the first
  42. * item in the AIL. If the AIL is empty, then this function
  43. * returns 0.
  44. *
  45. * We need the AIL lock in order to get a coherent read of the
  46. * lsn of the last item in the AIL.
  47. */
  48. xfs_lsn_t
  49. xfs_trans_tail_ail(
  50. xfs_mount_t *mp)
  51. {
  52. xfs_lsn_t lsn;
  53. xfs_log_item_t *lip;
  54. spin_lock(&mp->m_ail_lock);
  55. lip = xfs_ail_min(&(mp->m_ail.xa_ail));
  56. if (lip == NULL) {
  57. lsn = (xfs_lsn_t)0;
  58. } else {
  59. lsn = lip->li_lsn;
  60. }
  61. spin_unlock(&mp->m_ail_lock);
  62. return lsn;
  63. }
  64. /*
  65. * xfs_trans_push_ail
  66. *
  67. * This routine is called to move the tail of the AIL forward. It does this by
  68. * trying to flush items in the AIL whose lsns are below the given
  69. * threshold_lsn.
  70. *
  71. * the push is run asynchronously in a separate thread, so we return the tail
  72. * of the log right now instead of the tail after the push. This means we will
  73. * either continue right away, or we will sleep waiting on the async thread to
  74. * do it's work.
  75. *
  76. * We do this unlocked - we only need to know whether there is anything in the
  77. * AIL at the time we are called. We don't need to access the contents of
  78. * any of the objects, so the lock is not needed.
  79. */
  80. void
  81. xfs_trans_push_ail(
  82. xfs_mount_t *mp,
  83. xfs_lsn_t threshold_lsn)
  84. {
  85. xfs_log_item_t *lip;
  86. lip = xfs_ail_min(&mp->m_ail.xa_ail);
  87. if (lip && !XFS_FORCED_SHUTDOWN(mp)) {
  88. if (XFS_LSN_CMP(threshold_lsn, mp->m_ail.xa_target) > 0)
  89. xfsaild_wakeup(mp, threshold_lsn);
  90. }
  91. }
  92. /*
  93. * Return the item in the AIL with the current lsn.
  94. * Return the current tree generation number for use
  95. * in calls to xfs_trans_next_ail().
  96. */
  97. STATIC xfs_log_item_t *
  98. xfs_trans_first_push_ail(
  99. xfs_mount_t *mp,
  100. int *gen,
  101. xfs_lsn_t lsn)
  102. {
  103. xfs_log_item_t *lip;
  104. lip = xfs_ail_min(&(mp->m_ail.xa_ail));
  105. *gen = (int)mp->m_ail.xa_gen;
  106. if (lsn == 0)
  107. return lip;
  108. while (lip && (XFS_LSN_CMP(lip->li_lsn, lsn) < 0))
  109. lip = lip->li_ail.ail_forw;
  110. return lip;
  111. }
  112. /*
  113. * Function that does the work of pushing on the AIL
  114. */
  115. long
  116. xfsaild_push(
  117. xfs_mount_t *mp,
  118. xfs_lsn_t *last_lsn)
  119. {
  120. long tout = 1000; /* milliseconds */
  121. xfs_lsn_t last_pushed_lsn = *last_lsn;
  122. xfs_lsn_t target = mp->m_ail.xa_target;
  123. xfs_lsn_t lsn;
  124. xfs_log_item_t *lip;
  125. int gen;
  126. int restarts;
  127. int flush_log, count, stuck;
  128. #define XFS_TRANS_PUSH_AIL_RESTARTS 10
  129. spin_lock(&mp->m_ail_lock);
  130. lip = xfs_trans_first_push_ail(mp, &gen, *last_lsn);
  131. if (!lip || XFS_FORCED_SHUTDOWN(mp)) {
  132. /*
  133. * AIL is empty or our push has reached the end.
  134. */
  135. spin_unlock(&mp->m_ail_lock);
  136. last_pushed_lsn = 0;
  137. goto out;
  138. }
  139. XFS_STATS_INC(xs_push_ail);
  140. /*
  141. * While the item we are looking at is below the given threshold
  142. * try to flush it out. We'd like not to stop until we've at least
  143. * tried to push on everything in the AIL with an LSN less than
  144. * the given threshold.
  145. *
  146. * However, we will stop after a certain number of pushes and wait
  147. * for a reduced timeout to fire before pushing further. This
  148. * prevents use from spinning when we can't do anything or there is
  149. * lots of contention on the AIL lists.
  150. */
  151. tout = 10;
  152. lsn = lip->li_lsn;
  153. flush_log = stuck = count = restarts = 0;
  154. while ((XFS_LSN_CMP(lip->li_lsn, target) < 0)) {
  155. int lock_result;
  156. /*
  157. * If we can lock the item without sleeping, unlock the AIL
  158. * lock and flush the item. Then re-grab the AIL lock so we
  159. * can look for the next item on the AIL. List changes are
  160. * handled by the AIL lookup functions internally
  161. *
  162. * If we can't lock the item, either its holder will flush it
  163. * or it is already being flushed or it is being relogged. In
  164. * any of these case it is being taken care of and we can just
  165. * skip to the next item in the list.
  166. */
  167. lock_result = IOP_TRYLOCK(lip);
  168. spin_unlock(&mp->m_ail_lock);
  169. switch (lock_result) {
  170. case XFS_ITEM_SUCCESS:
  171. XFS_STATS_INC(xs_push_ail_success);
  172. IOP_PUSH(lip);
  173. last_pushed_lsn = lsn;
  174. break;
  175. case XFS_ITEM_PUSHBUF:
  176. XFS_STATS_INC(xs_push_ail_pushbuf);
  177. IOP_PUSHBUF(lip);
  178. last_pushed_lsn = lsn;
  179. break;
  180. case XFS_ITEM_PINNED:
  181. XFS_STATS_INC(xs_push_ail_pinned);
  182. stuck++;
  183. flush_log = 1;
  184. break;
  185. case XFS_ITEM_LOCKED:
  186. XFS_STATS_INC(xs_push_ail_locked);
  187. last_pushed_lsn = lsn;
  188. stuck++;
  189. break;
  190. case XFS_ITEM_FLUSHING:
  191. XFS_STATS_INC(xs_push_ail_flushing);
  192. last_pushed_lsn = lsn;
  193. stuck++;
  194. break;
  195. default:
  196. ASSERT(0);
  197. break;
  198. }
  199. spin_lock(&mp->m_ail_lock);
  200. /* should we bother continuing? */
  201. if (XFS_FORCED_SHUTDOWN(mp))
  202. break;
  203. ASSERT(mp->m_log);
  204. count++;
  205. /*
  206. * Are there too many items we can't do anything with?
  207. * If we we are skipping too many items because we can't flush
  208. * them or they are already being flushed, we back off and
  209. * given them time to complete whatever operation is being
  210. * done. i.e. remove pressure from the AIL while we can't make
  211. * progress so traversals don't slow down further inserts and
  212. * removals to/from the AIL.
  213. *
  214. * The value of 100 is an arbitrary magic number based on
  215. * observation.
  216. */
  217. if (stuck > 100)
  218. break;
  219. lip = xfs_trans_next_ail(mp, lip, &gen, &restarts);
  220. if (lip == NULL)
  221. break;
  222. if (restarts > XFS_TRANS_PUSH_AIL_RESTARTS)
  223. break;
  224. lsn = lip->li_lsn;
  225. }
  226. spin_unlock(&mp->m_ail_lock);
  227. if (flush_log) {
  228. /*
  229. * If something we need to push out was pinned, then
  230. * push out the log so it will become unpinned and
  231. * move forward in the AIL.
  232. */
  233. XFS_STATS_INC(xs_push_ail_flush);
  234. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  235. }
  236. if (!count) {
  237. /* We're past our target or empty, so idle */
  238. tout = 1000;
  239. } else if (XFS_LSN_CMP(lsn, target) >= 0) {
  240. /*
  241. * We reached the target so wait a bit longer for I/O to
  242. * complete and remove pushed items from the AIL before we
  243. * start the next scan from the start of the AIL.
  244. */
  245. tout += 20;
  246. last_pushed_lsn = 0;
  247. } else if ((restarts > XFS_TRANS_PUSH_AIL_RESTARTS) ||
  248. ((stuck * 100) / count > 90)) {
  249. /*
  250. * Either there is a lot of contention on the AIL or we
  251. * are stuck due to operations in progress. "Stuck" in this
  252. * case is defined as >90% of the items we tried to push
  253. * were stuck.
  254. *
  255. * Backoff a bit more to allow some I/O to complete before
  256. * continuing from where we were.
  257. */
  258. tout += 10;
  259. }
  260. out:
  261. *last_lsn = last_pushed_lsn;
  262. return tout;
  263. } /* xfsaild_push */
  264. /*
  265. * This is to be called when an item is unlocked that may have
  266. * been in the AIL. It will wake up the first member of the AIL
  267. * wait list if this item's unlocking might allow it to progress.
  268. * If the item is in the AIL, then we need to get the AIL lock
  269. * while doing our checking so we don't race with someone going
  270. * to sleep waiting for this event in xfs_trans_push_ail().
  271. */
  272. void
  273. xfs_trans_unlocked_item(
  274. xfs_mount_t *mp,
  275. xfs_log_item_t *lip)
  276. {
  277. xfs_log_item_t *min_lip;
  278. /*
  279. * If we're forcibly shutting down, we may have
  280. * unlocked log items arbitrarily. The last thing
  281. * we want to do is to move the tail of the log
  282. * over some potentially valid data.
  283. */
  284. if (!(lip->li_flags & XFS_LI_IN_AIL) ||
  285. XFS_FORCED_SHUTDOWN(mp)) {
  286. return;
  287. }
  288. /*
  289. * This is the one case where we can call into xfs_ail_min()
  290. * without holding the AIL lock because we only care about the
  291. * case where we are at the tail of the AIL. If the object isn't
  292. * at the tail, it doesn't matter what result we get back. This
  293. * is slightly racy because since we were just unlocked, we could
  294. * go to sleep between the call to xfs_ail_min and the call to
  295. * xfs_log_move_tail, have someone else lock us, commit to us disk,
  296. * move us out of the tail of the AIL, and then we wake up. However,
  297. * the call to xfs_log_move_tail() doesn't do anything if there's
  298. * not enough free space to wake people up so we're safe calling it.
  299. */
  300. min_lip = xfs_ail_min(&mp->m_ail.xa_ail);
  301. if (min_lip == lip)
  302. xfs_log_move_tail(mp, 1);
  303. } /* xfs_trans_unlocked_item */
  304. /*
  305. * Update the position of the item in the AIL with the new
  306. * lsn. If it is not yet in the AIL, add it. Otherwise, move
  307. * it to its new position by removing it and re-adding it.
  308. *
  309. * Wakeup anyone with an lsn less than the item's lsn. If the item
  310. * we move in the AIL is the minimum one, update the tail lsn in the
  311. * log manager.
  312. *
  313. * Increment the AIL's generation count to indicate that the tree
  314. * has changed.
  315. *
  316. * This function must be called with the AIL lock held. The lock
  317. * is dropped before returning.
  318. */
  319. void
  320. xfs_trans_update_ail(
  321. xfs_mount_t *mp,
  322. xfs_log_item_t *lip,
  323. xfs_lsn_t lsn) __releases(mp->m_ail_lock)
  324. {
  325. xfs_ail_entry_t *ailp;
  326. xfs_log_item_t *dlip=NULL;
  327. xfs_log_item_t *mlip; /* ptr to minimum lip */
  328. ailp = &(mp->m_ail.xa_ail);
  329. mlip = xfs_ail_min(ailp);
  330. if (lip->li_flags & XFS_LI_IN_AIL) {
  331. dlip = xfs_ail_delete(ailp, lip);
  332. ASSERT(dlip == lip);
  333. } else {
  334. lip->li_flags |= XFS_LI_IN_AIL;
  335. }
  336. lip->li_lsn = lsn;
  337. xfs_ail_insert(ailp, lip);
  338. mp->m_ail.xa_gen++;
  339. if (mlip == dlip) {
  340. mlip = xfs_ail_min(&(mp->m_ail.xa_ail));
  341. spin_unlock(&mp->m_ail_lock);
  342. xfs_log_move_tail(mp, mlip->li_lsn);
  343. } else {
  344. spin_unlock(&mp->m_ail_lock);
  345. }
  346. } /* xfs_trans_update_ail */
  347. /*
  348. * Delete the given item from the AIL. It must already be in
  349. * the AIL.
  350. *
  351. * Wakeup anyone with an lsn less than item's lsn. If the item
  352. * we delete in the AIL is the minimum one, update the tail lsn in the
  353. * log manager.
  354. *
  355. * Clear the IN_AIL flag from the item, reset its lsn to 0, and
  356. * bump the AIL's generation count to indicate that the tree
  357. * has changed.
  358. *
  359. * This function must be called with the AIL lock held. The lock
  360. * is dropped before returning.
  361. */
  362. void
  363. xfs_trans_delete_ail(
  364. xfs_mount_t *mp,
  365. xfs_log_item_t *lip) __releases(mp->m_ail_lock)
  366. {
  367. xfs_ail_entry_t *ailp;
  368. xfs_log_item_t *dlip;
  369. xfs_log_item_t *mlip;
  370. if (lip->li_flags & XFS_LI_IN_AIL) {
  371. ailp = &(mp->m_ail.xa_ail);
  372. mlip = xfs_ail_min(ailp);
  373. dlip = xfs_ail_delete(ailp, lip);
  374. ASSERT(dlip == lip);
  375. lip->li_flags &= ~XFS_LI_IN_AIL;
  376. lip->li_lsn = 0;
  377. mp->m_ail.xa_gen++;
  378. if (mlip == dlip) {
  379. mlip = xfs_ail_min(&(mp->m_ail.xa_ail));
  380. spin_unlock(&mp->m_ail_lock);
  381. xfs_log_move_tail(mp, (mlip ? mlip->li_lsn : 0));
  382. } else {
  383. spin_unlock(&mp->m_ail_lock);
  384. }
  385. }
  386. else {
  387. /*
  388. * If the file system is not being shutdown, we are in
  389. * serious trouble if we get to this stage.
  390. */
  391. if (XFS_FORCED_SHUTDOWN(mp))
  392. spin_unlock(&mp->m_ail_lock);
  393. else {
  394. xfs_cmn_err(XFS_PTAG_AILDELETE, CE_ALERT, mp,
  395. "%s: attempting to delete a log item that is not in the AIL",
  396. __FUNCTION__);
  397. spin_unlock(&mp->m_ail_lock);
  398. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  399. }
  400. }
  401. }
  402. /*
  403. * Return the item in the AIL with the smallest lsn.
  404. * Return the current tree generation number for use
  405. * in calls to xfs_trans_next_ail().
  406. */
  407. xfs_log_item_t *
  408. xfs_trans_first_ail(
  409. xfs_mount_t *mp,
  410. int *gen)
  411. {
  412. xfs_log_item_t *lip;
  413. lip = xfs_ail_min(&(mp->m_ail.xa_ail));
  414. *gen = (int)mp->m_ail.xa_gen;
  415. return lip;
  416. }
  417. /*
  418. * If the generation count of the tree has not changed since the
  419. * caller last took something from the AIL, then return the elmt
  420. * in the tree which follows the one given. If the count has changed,
  421. * then return the minimum elmt of the AIL and bump the restarts counter
  422. * if one is given.
  423. */
  424. xfs_log_item_t *
  425. xfs_trans_next_ail(
  426. xfs_mount_t *mp,
  427. xfs_log_item_t *lip,
  428. int *gen,
  429. int *restarts)
  430. {
  431. xfs_log_item_t *nlip;
  432. ASSERT(mp && lip && gen);
  433. if (mp->m_ail.xa_gen == *gen) {
  434. nlip = xfs_ail_next(&(mp->m_ail.xa_ail), lip);
  435. } else {
  436. nlip = xfs_ail_min(&(mp->m_ail).xa_ail);
  437. *gen = (int)mp->m_ail.xa_gen;
  438. if (restarts != NULL) {
  439. XFS_STATS_INC(xs_push_ail_restarts);
  440. (*restarts)++;
  441. }
  442. }
  443. return (nlip);
  444. }
  445. /*
  446. * The active item list (AIL) is a doubly linked list of log
  447. * items sorted by ascending lsn. The base of the list is
  448. * a forw/back pointer pair embedded in the xfs mount structure.
  449. * The base is initialized with both pointers pointing to the
  450. * base. This case always needs to be distinguished, because
  451. * the base has no lsn to look at. We almost always insert
  452. * at the end of the list, so on inserts we search from the
  453. * end of the list to find where the new item belongs.
  454. */
  455. /*
  456. * Initialize the doubly linked list to point only to itself.
  457. */
  458. int
  459. xfs_trans_ail_init(
  460. xfs_mount_t *mp)
  461. {
  462. mp->m_ail.xa_ail.ail_forw = (xfs_log_item_t*)&mp->m_ail.xa_ail;
  463. mp->m_ail.xa_ail.ail_back = (xfs_log_item_t*)&mp->m_ail.xa_ail;
  464. return xfsaild_start(mp);
  465. }
  466. void
  467. xfs_trans_ail_destroy(
  468. xfs_mount_t *mp)
  469. {
  470. xfsaild_stop(mp);
  471. }
  472. /*
  473. * Insert the given log item into the AIL.
  474. * We almost always insert at the end of the list, so on inserts
  475. * we search from the end of the list to find where the
  476. * new item belongs.
  477. */
  478. STATIC void
  479. xfs_ail_insert(
  480. xfs_ail_entry_t *base,
  481. xfs_log_item_t *lip)
  482. /* ARGSUSED */
  483. {
  484. xfs_log_item_t *next_lip;
  485. /*
  486. * If the list is empty, just insert the item.
  487. */
  488. if (base->ail_back == (xfs_log_item_t*)base) {
  489. base->ail_forw = lip;
  490. base->ail_back = lip;
  491. lip->li_ail.ail_forw = (xfs_log_item_t*)base;
  492. lip->li_ail.ail_back = (xfs_log_item_t*)base;
  493. return;
  494. }
  495. next_lip = base->ail_back;
  496. while ((next_lip != (xfs_log_item_t*)base) &&
  497. (XFS_LSN_CMP(next_lip->li_lsn, lip->li_lsn) > 0)) {
  498. next_lip = next_lip->li_ail.ail_back;
  499. }
  500. ASSERT((next_lip == (xfs_log_item_t*)base) ||
  501. (XFS_LSN_CMP(next_lip->li_lsn, lip->li_lsn) <= 0));
  502. lip->li_ail.ail_forw = next_lip->li_ail.ail_forw;
  503. lip->li_ail.ail_back = next_lip;
  504. next_lip->li_ail.ail_forw = lip;
  505. lip->li_ail.ail_forw->li_ail.ail_back = lip;
  506. xfs_ail_check(base, lip);
  507. return;
  508. }
  509. /*
  510. * Delete the given item from the AIL. Return a pointer to the item.
  511. */
  512. /*ARGSUSED*/
  513. STATIC xfs_log_item_t *
  514. xfs_ail_delete(
  515. xfs_ail_entry_t *base,
  516. xfs_log_item_t *lip)
  517. /* ARGSUSED */
  518. {
  519. xfs_ail_check(base, lip);
  520. lip->li_ail.ail_forw->li_ail.ail_back = lip->li_ail.ail_back;
  521. lip->li_ail.ail_back->li_ail.ail_forw = lip->li_ail.ail_forw;
  522. lip->li_ail.ail_forw = NULL;
  523. lip->li_ail.ail_back = NULL;
  524. return lip;
  525. }
  526. /*
  527. * Return a pointer to the first item in the AIL.
  528. * If the AIL is empty, then return NULL.
  529. */
  530. STATIC xfs_log_item_t *
  531. xfs_ail_min(
  532. xfs_ail_entry_t *base)
  533. /* ARGSUSED */
  534. {
  535. register xfs_log_item_t *forw = base->ail_forw;
  536. if (forw == (xfs_log_item_t*)base) {
  537. return NULL;
  538. }
  539. return forw;
  540. }
  541. /*
  542. * Return a pointer to the item which follows
  543. * the given item in the AIL. If the given item
  544. * is the last item in the list, then return NULL.
  545. */
  546. STATIC xfs_log_item_t *
  547. xfs_ail_next(
  548. xfs_ail_entry_t *base,
  549. xfs_log_item_t *lip)
  550. /* ARGSUSED */
  551. {
  552. if (lip->li_ail.ail_forw == (xfs_log_item_t*)base) {
  553. return NULL;
  554. }
  555. return lip->li_ail.ail_forw;
  556. }
  557. #ifdef DEBUG
  558. /*
  559. * Check that the list is sorted as it should be.
  560. */
  561. STATIC void
  562. xfs_ail_check(
  563. xfs_ail_entry_t *base,
  564. xfs_log_item_t *lip)
  565. {
  566. xfs_log_item_t *prev_lip;
  567. prev_lip = base->ail_forw;
  568. if (prev_lip == (xfs_log_item_t*)base) {
  569. /*
  570. * Make sure the pointers are correct when the list
  571. * is empty.
  572. */
  573. ASSERT(base->ail_back == (xfs_log_item_t*)base);
  574. return;
  575. }
  576. /*
  577. * Check the next and previous entries are valid.
  578. */
  579. ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0);
  580. prev_lip = lip->li_ail.ail_back;
  581. if (prev_lip != (xfs_log_item_t*)base) {
  582. ASSERT(prev_lip->li_ail.ail_forw == lip);
  583. ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0);
  584. }
  585. prev_lip = lip->li_ail.ail_forw;
  586. if (prev_lip != (xfs_log_item_t*)base) {
  587. ASSERT(prev_lip->li_ail.ail_back == lip);
  588. ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) >= 0);
  589. }
  590. #ifdef XFS_TRANS_DEBUG
  591. /*
  592. * Walk the list checking forward and backward pointers,
  593. * lsn ordering, and that every entry has the XFS_LI_IN_AIL
  594. * flag set. This is really expensive, so only do it when
  595. * specifically debugging the transaction subsystem.
  596. */
  597. prev_lip = (xfs_log_item_t*)base;
  598. while (lip != (xfs_log_item_t*)base) {
  599. if (prev_lip != (xfs_log_item_t*)base) {
  600. ASSERT(prev_lip->li_ail.ail_forw == lip);
  601. ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0);
  602. }
  603. ASSERT(lip->li_ail.ail_back == prev_lip);
  604. ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0);
  605. prev_lip = lip;
  606. lip = lip->li_ail.ail_forw;
  607. }
  608. ASSERT(lip == (xfs_log_item_t*)base);
  609. ASSERT(base->ail_back == prev_lip);
  610. #endif /* XFS_TRANS_DEBUG */
  611. }
  612. #endif /* DEBUG */