checkpoint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * linux/fs/jbd2/checkpoint.c
  3. *
  4. * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
  5. *
  6. * Copyright 1999 Red Hat Software --- All Rights Reserved
  7. *
  8. * This file is part of the Linux kernel and is made available under
  9. * the terms of the GNU General Public License, version 2, or at your
  10. * option, any later version, incorporated herein by reference.
  11. *
  12. * Checkpoint routines for the generic filesystem journaling code.
  13. * Part of the ext2fs journaling system.
  14. *
  15. * Checkpointing is the process of ensuring that a section of the log is
  16. * committed fully to disk, so that that portion of the log can be
  17. * reused.
  18. */
  19. #include <linux/time.h>
  20. #include <linux/fs.h>
  21. #include <linux/jbd2.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. #include <linux/blkdev.h>
  25. #include <trace/events/jbd2.h>
  26. /*
  27. * Unlink a buffer from a transaction checkpoint list.
  28. *
  29. * Called with j_list_lock held.
  30. */
  31. static inline void __buffer_unlink_first(struct journal_head *jh)
  32. {
  33. transaction_t *transaction = jh->b_cp_transaction;
  34. jh->b_cpnext->b_cpprev = jh->b_cpprev;
  35. jh->b_cpprev->b_cpnext = jh->b_cpnext;
  36. if (transaction->t_checkpoint_list == jh) {
  37. transaction->t_checkpoint_list = jh->b_cpnext;
  38. if (transaction->t_checkpoint_list == jh)
  39. transaction->t_checkpoint_list = NULL;
  40. }
  41. }
  42. /*
  43. * Unlink a buffer from a transaction checkpoint(io) list.
  44. *
  45. * Called with j_list_lock held.
  46. */
  47. static inline void __buffer_unlink(struct journal_head *jh)
  48. {
  49. transaction_t *transaction = jh->b_cp_transaction;
  50. __buffer_unlink_first(jh);
  51. if (transaction->t_checkpoint_io_list == jh) {
  52. transaction->t_checkpoint_io_list = jh->b_cpnext;
  53. if (transaction->t_checkpoint_io_list == jh)
  54. transaction->t_checkpoint_io_list = NULL;
  55. }
  56. }
  57. /*
  58. * Move a buffer from the checkpoint list to the checkpoint io list
  59. *
  60. * Called with j_list_lock held
  61. */
  62. static inline void __buffer_relink_io(struct journal_head *jh)
  63. {
  64. transaction_t *transaction = jh->b_cp_transaction;
  65. __buffer_unlink_first(jh);
  66. if (!transaction->t_checkpoint_io_list) {
  67. jh->b_cpnext = jh->b_cpprev = jh;
  68. } else {
  69. jh->b_cpnext = transaction->t_checkpoint_io_list;
  70. jh->b_cpprev = transaction->t_checkpoint_io_list->b_cpprev;
  71. jh->b_cpprev->b_cpnext = jh;
  72. jh->b_cpnext->b_cpprev = jh;
  73. }
  74. transaction->t_checkpoint_io_list = jh;
  75. }
  76. /*
  77. * Try to release a checkpointed buffer from its transaction.
  78. * Returns 1 if we released it and 2 if we also released the
  79. * whole transaction.
  80. *
  81. * Requires j_list_lock
  82. */
  83. static int __try_to_free_cp_buf(struct journal_head *jh)
  84. {
  85. int ret = 0;
  86. struct buffer_head *bh = jh2bh(jh);
  87. if (jh->b_transaction == NULL && !buffer_locked(bh) &&
  88. !buffer_dirty(bh) && !buffer_write_io_error(bh)) {
  89. JBUFFER_TRACE(jh, "remove from checkpoint list");
  90. ret = __jbd2_journal_remove_checkpoint(jh) + 1;
  91. }
  92. return ret;
  93. }
  94. /*
  95. * __jbd2_log_wait_for_space: wait until there is space in the journal.
  96. *
  97. * Called under j-state_lock *only*. It will be unlocked if we have to wait
  98. * for a checkpoint to free up some space in the log.
  99. */
  100. void __jbd2_log_wait_for_space(journal_t *journal)
  101. {
  102. int nblocks, space_left;
  103. /* assert_spin_locked(&journal->j_state_lock); */
  104. nblocks = jbd2_space_needed(journal);
  105. while (jbd2_log_space_left(journal) < nblocks) {
  106. write_unlock(&journal->j_state_lock);
  107. mutex_lock(&journal->j_checkpoint_mutex);
  108. /*
  109. * Test again, another process may have checkpointed while we
  110. * were waiting for the checkpoint lock. If there are no
  111. * transactions ready to be checkpointed, try to recover
  112. * journal space by calling cleanup_journal_tail(), and if
  113. * that doesn't work, by waiting for the currently committing
  114. * transaction to complete. If there is absolutely no way
  115. * to make progress, this is either a BUG or corrupted
  116. * filesystem, so abort the journal and leave a stack
  117. * trace for forensic evidence.
  118. */
  119. write_lock(&journal->j_state_lock);
  120. if (journal->j_flags & JBD2_ABORT) {
  121. mutex_unlock(&journal->j_checkpoint_mutex);
  122. return;
  123. }
  124. spin_lock(&journal->j_list_lock);
  125. nblocks = jbd2_space_needed(journal);
  126. space_left = jbd2_log_space_left(journal);
  127. if (space_left < nblocks) {
  128. int chkpt = journal->j_checkpoint_transactions != NULL;
  129. tid_t tid = 0;
  130. if (journal->j_committing_transaction)
  131. tid = journal->j_committing_transaction->t_tid;
  132. spin_unlock(&journal->j_list_lock);
  133. write_unlock(&journal->j_state_lock);
  134. if (chkpt) {
  135. jbd2_log_do_checkpoint(journal);
  136. } else if (jbd2_cleanup_journal_tail(journal) == 0) {
  137. /* We were able to recover space; yay! */
  138. ;
  139. } else if (tid) {
  140. /*
  141. * jbd2_journal_commit_transaction() may want
  142. * to take the checkpoint_mutex if JBD2_FLUSHED
  143. * is set. So we need to temporarily drop it.
  144. */
  145. mutex_unlock(&journal->j_checkpoint_mutex);
  146. jbd2_log_wait_commit(journal, tid);
  147. write_lock(&journal->j_state_lock);
  148. continue;
  149. } else {
  150. printk(KERN_ERR "%s: needed %d blocks and "
  151. "only had %d space available\n",
  152. __func__, nblocks, space_left);
  153. printk(KERN_ERR "%s: no way to get more "
  154. "journal space in %s\n", __func__,
  155. journal->j_devname);
  156. WARN_ON(1);
  157. jbd2_journal_abort(journal, 0);
  158. }
  159. write_lock(&journal->j_state_lock);
  160. } else {
  161. spin_unlock(&journal->j_list_lock);
  162. }
  163. mutex_unlock(&journal->j_checkpoint_mutex);
  164. }
  165. }
  166. static void
  167. __flush_batch(journal_t *journal, int *batch_count)
  168. {
  169. int i;
  170. struct blk_plug plug;
  171. blk_start_plug(&plug);
  172. for (i = 0; i < *batch_count; i++)
  173. write_dirty_buffer(journal->j_chkpt_bhs[i], WRITE_SYNC);
  174. blk_finish_plug(&plug);
  175. for (i = 0; i < *batch_count; i++) {
  176. struct buffer_head *bh = journal->j_chkpt_bhs[i];
  177. BUFFER_TRACE(bh, "brelse");
  178. __brelse(bh);
  179. }
  180. *batch_count = 0;
  181. }
  182. /*
  183. * Perform an actual checkpoint. We take the first transaction on the
  184. * list of transactions to be checkpointed and send all its buffers
  185. * to disk. We submit larger chunks of data at once.
  186. *
  187. * The journal should be locked before calling this function.
  188. * Called with j_checkpoint_mutex held.
  189. */
  190. int jbd2_log_do_checkpoint(journal_t *journal)
  191. {
  192. struct journal_head *jh;
  193. struct buffer_head *bh;
  194. transaction_t *transaction;
  195. tid_t this_tid;
  196. int result, batch_count = 0;
  197. jbd_debug(1, "Start checkpoint\n");
  198. /*
  199. * First thing: if there are any transactions in the log which
  200. * don't need checkpointing, just eliminate them from the
  201. * journal straight away.
  202. */
  203. result = jbd2_cleanup_journal_tail(journal);
  204. trace_jbd2_checkpoint(journal, result);
  205. jbd_debug(1, "cleanup_journal_tail returned %d\n", result);
  206. if (result <= 0)
  207. return result;
  208. /*
  209. * OK, we need to start writing disk blocks. Take one transaction
  210. * and write it.
  211. */
  212. result = 0;
  213. spin_lock(&journal->j_list_lock);
  214. if (!journal->j_checkpoint_transactions)
  215. goto out;
  216. transaction = journal->j_checkpoint_transactions;
  217. if (transaction->t_chp_stats.cs_chp_time == 0)
  218. transaction->t_chp_stats.cs_chp_time = jiffies;
  219. this_tid = transaction->t_tid;
  220. restart:
  221. /*
  222. * If someone cleaned up this transaction while we slept, we're
  223. * done (maybe it's a new transaction, but it fell at the same
  224. * address).
  225. */
  226. if (journal->j_checkpoint_transactions != transaction ||
  227. transaction->t_tid != this_tid)
  228. goto out;
  229. /* checkpoint all of the transaction's buffers */
  230. while (transaction->t_checkpoint_list) {
  231. jh = transaction->t_checkpoint_list;
  232. bh = jh2bh(jh);
  233. if (buffer_locked(bh)) {
  234. get_bh(bh);
  235. spin_unlock(&journal->j_list_lock);
  236. wait_on_buffer(bh);
  237. /* the journal_head may have gone by now */
  238. BUFFER_TRACE(bh, "brelse");
  239. __brelse(bh);
  240. goto retry;
  241. }
  242. if (jh->b_transaction != NULL) {
  243. transaction_t *t = jh->b_transaction;
  244. tid_t tid = t->t_tid;
  245. transaction->t_chp_stats.cs_forced_to_close++;
  246. spin_unlock(&journal->j_list_lock);
  247. if (unlikely(journal->j_flags & JBD2_UNMOUNT))
  248. /*
  249. * The journal thread is dead; so
  250. * starting and waiting for a commit
  251. * to finish will cause us to wait for
  252. * a _very_ long time.
  253. */
  254. printk(KERN_ERR
  255. "JBD2: %s: Waiting for Godot: block %llu\n",
  256. journal->j_devname, (unsigned long long) bh->b_blocknr);
  257. jbd2_log_start_commit(journal, tid);
  258. jbd2_log_wait_commit(journal, tid);
  259. goto retry;
  260. }
  261. if (!buffer_dirty(bh)) {
  262. if (unlikely(buffer_write_io_error(bh)) && !result)
  263. result = -EIO;
  264. BUFFER_TRACE(bh, "remove from checkpoint");
  265. if (__jbd2_journal_remove_checkpoint(jh))
  266. /* The transaction was released; we're done */
  267. goto out;
  268. continue;
  269. }
  270. /*
  271. * Important: we are about to write the buffer, and
  272. * possibly block, while still holding the journal
  273. * lock. We cannot afford to let the transaction
  274. * logic start messing around with this buffer before
  275. * we write it to disk, as that would break
  276. * recoverability.
  277. */
  278. BUFFER_TRACE(bh, "queue");
  279. get_bh(bh);
  280. J_ASSERT_BH(bh, !buffer_jwrite(bh));
  281. journal->j_chkpt_bhs[batch_count++] = bh;
  282. __buffer_relink_io(jh);
  283. transaction->t_chp_stats.cs_written++;
  284. if ((batch_count == JBD2_NR_BATCH) ||
  285. need_resched() ||
  286. spin_needbreak(&journal->j_list_lock))
  287. goto unlock_and_flush;
  288. }
  289. if (batch_count) {
  290. unlock_and_flush:
  291. spin_unlock(&journal->j_list_lock);
  292. retry:
  293. if (batch_count)
  294. __flush_batch(journal, &batch_count);
  295. spin_lock(&journal->j_list_lock);
  296. goto restart;
  297. }
  298. /*
  299. * Now we issued all of the transaction's buffers, let's deal
  300. * with the buffers that are out for I/O.
  301. */
  302. restart2:
  303. /* Did somebody clean up the transaction in the meanwhile? */
  304. if (journal->j_checkpoint_transactions != transaction ||
  305. transaction->t_tid != this_tid)
  306. goto out;
  307. while (transaction->t_checkpoint_io_list) {
  308. jh = transaction->t_checkpoint_io_list;
  309. bh = jh2bh(jh);
  310. if (buffer_locked(bh)) {
  311. get_bh(bh);
  312. spin_unlock(&journal->j_list_lock);
  313. wait_on_buffer(bh);
  314. /* the journal_head may have gone by now */
  315. BUFFER_TRACE(bh, "brelse");
  316. __brelse(bh);
  317. spin_lock(&journal->j_list_lock);
  318. goto restart2;
  319. }
  320. if (unlikely(buffer_write_io_error(bh)) && !result)
  321. result = -EIO;
  322. /*
  323. * Now in whatever state the buffer currently is, we
  324. * know that it has been written out and so we can
  325. * drop it from the list
  326. */
  327. if (__jbd2_journal_remove_checkpoint(jh))
  328. break;
  329. }
  330. out:
  331. spin_unlock(&journal->j_list_lock);
  332. if (result < 0)
  333. jbd2_journal_abort(journal, result);
  334. else
  335. result = jbd2_cleanup_journal_tail(journal);
  336. return (result < 0) ? result : 0;
  337. }
  338. /*
  339. * Check the list of checkpoint transactions for the journal to see if
  340. * we have already got rid of any since the last update of the log tail
  341. * in the journal superblock. If so, we can instantly roll the
  342. * superblock forward to remove those transactions from the log.
  343. *
  344. * Return <0 on error, 0 on success, 1 if there was nothing to clean up.
  345. *
  346. * Called with the journal lock held.
  347. *
  348. * This is the only part of the journaling code which really needs to be
  349. * aware of transaction aborts. Checkpointing involves writing to the
  350. * main filesystem area rather than to the journal, so it can proceed
  351. * even in abort state, but we must not update the super block if
  352. * checkpointing may have failed. Otherwise, we would lose some metadata
  353. * buffers which should be written-back to the filesystem.
  354. */
  355. int jbd2_cleanup_journal_tail(journal_t *journal)
  356. {
  357. tid_t first_tid;
  358. unsigned long blocknr;
  359. if (is_journal_aborted(journal))
  360. return -EIO;
  361. if (!jbd2_journal_get_log_tail(journal, &first_tid, &blocknr))
  362. return 1;
  363. J_ASSERT(blocknr != 0);
  364. /*
  365. * We need to make sure that any blocks that were recently written out
  366. * --- perhaps by jbd2_log_do_checkpoint() --- are flushed out before
  367. * we drop the transactions from the journal. It's unlikely this will
  368. * be necessary, especially with an appropriately sized journal, but we
  369. * need this to guarantee correctness. Fortunately
  370. * jbd2_cleanup_journal_tail() doesn't get called all that often.
  371. */
  372. if (journal->j_flags & JBD2_BARRIER)
  373. blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
  374. return __jbd2_update_log_tail(journal, first_tid, blocknr);
  375. }
  376. /* Checkpoint list management */
  377. /*
  378. * journal_clean_one_cp_list
  379. *
  380. * Find all the written-back checkpoint buffers in the given list and
  381. * release them. If 'destroy' is set, clean all buffers unconditionally.
  382. *
  383. * Called with j_list_lock held.
  384. * Returns 1 if we freed the transaction, 0 otherwise.
  385. */
  386. static int journal_clean_one_cp_list(struct journal_head *jh, bool destroy)
  387. {
  388. struct journal_head *last_jh;
  389. struct journal_head *next_jh = jh;
  390. int ret;
  391. if (!jh)
  392. return 0;
  393. last_jh = jh->b_cpprev;
  394. do {
  395. jh = next_jh;
  396. next_jh = jh->b_cpnext;
  397. if (!destroy)
  398. ret = __try_to_free_cp_buf(jh);
  399. else
  400. ret = __jbd2_journal_remove_checkpoint(jh) + 1;
  401. if (!ret)
  402. return 0;
  403. if (ret == 2)
  404. return 1;
  405. /*
  406. * This function only frees up some memory
  407. * if possible so we dont have an obligation
  408. * to finish processing. Bail out if preemption
  409. * requested:
  410. */
  411. if (need_resched())
  412. return 0;
  413. } while (jh != last_jh);
  414. return 0;
  415. }
  416. /*
  417. * journal_clean_checkpoint_list
  418. *
  419. * Find all the written-back checkpoint buffers in the journal and release them.
  420. * If 'destroy' is set, release all buffers unconditionally.
  421. *
  422. * Called with j_list_lock held.
  423. */
  424. void __jbd2_journal_clean_checkpoint_list(journal_t *journal, bool destroy)
  425. {
  426. transaction_t *transaction, *last_transaction, *next_transaction;
  427. int ret;
  428. transaction = journal->j_checkpoint_transactions;
  429. if (!transaction)
  430. return;
  431. last_transaction = transaction->t_cpprev;
  432. next_transaction = transaction;
  433. do {
  434. transaction = next_transaction;
  435. next_transaction = transaction->t_cpnext;
  436. ret = journal_clean_one_cp_list(transaction->t_checkpoint_list,
  437. destroy);
  438. /*
  439. * This function only frees up some memory if possible so we
  440. * dont have an obligation to finish processing. Bail out if
  441. * preemption requested:
  442. */
  443. if (need_resched())
  444. return;
  445. if (ret)
  446. continue;
  447. /*
  448. * It is essential that we are as careful as in the case of
  449. * t_checkpoint_list with removing the buffer from the list as
  450. * we can possibly see not yet submitted buffers on io_list
  451. */
  452. ret = journal_clean_one_cp_list(transaction->
  453. t_checkpoint_io_list, destroy);
  454. if (need_resched())
  455. return;
  456. /*
  457. * Stop scanning if we couldn't free the transaction. This
  458. * avoids pointless scanning of transactions which still
  459. * weren't checkpointed.
  460. */
  461. if (!ret)
  462. return;
  463. } while (transaction != last_transaction);
  464. }
  465. /*
  466. * Remove buffers from all checkpoint lists as journal is aborted and we just
  467. * need to free memory
  468. */
  469. void jbd2_journal_destroy_checkpoint(journal_t *journal)
  470. {
  471. /*
  472. * We loop because __jbd2_journal_clean_checkpoint_list() may abort
  473. * early due to a need of rescheduling.
  474. */
  475. while (1) {
  476. spin_lock(&journal->j_list_lock);
  477. if (!journal->j_checkpoint_transactions) {
  478. spin_unlock(&journal->j_list_lock);
  479. break;
  480. }
  481. __jbd2_journal_clean_checkpoint_list(journal, true);
  482. spin_unlock(&journal->j_list_lock);
  483. cond_resched();
  484. }
  485. }
  486. /*
  487. * journal_remove_checkpoint: called after a buffer has been committed
  488. * to disk (either by being write-back flushed to disk, or being
  489. * committed to the log).
  490. *
  491. * We cannot safely clean a transaction out of the log until all of the
  492. * buffer updates committed in that transaction have safely been stored
  493. * elsewhere on disk. To achieve this, all of the buffers in a
  494. * transaction need to be maintained on the transaction's checkpoint
  495. * lists until they have been rewritten, at which point this function is
  496. * called to remove the buffer from the existing transaction's
  497. * checkpoint lists.
  498. *
  499. * The function returns 1 if it frees the transaction, 0 otherwise.
  500. * The function can free jh and bh.
  501. *
  502. * This function is called with j_list_lock held.
  503. */
  504. int __jbd2_journal_remove_checkpoint(struct journal_head *jh)
  505. {
  506. struct transaction_chp_stats_s *stats;
  507. transaction_t *transaction;
  508. journal_t *journal;
  509. int ret = 0;
  510. JBUFFER_TRACE(jh, "entry");
  511. if ((transaction = jh->b_cp_transaction) == NULL) {
  512. JBUFFER_TRACE(jh, "not on transaction");
  513. goto out;
  514. }
  515. journal = transaction->t_journal;
  516. JBUFFER_TRACE(jh, "removing from transaction");
  517. __buffer_unlink(jh);
  518. jh->b_cp_transaction = NULL;
  519. jbd2_journal_put_journal_head(jh);
  520. if (transaction->t_checkpoint_list != NULL ||
  521. transaction->t_checkpoint_io_list != NULL)
  522. goto out;
  523. /*
  524. * There is one special case to worry about: if we have just pulled the
  525. * buffer off a running or committing transaction's checkpoing list,
  526. * then even if the checkpoint list is empty, the transaction obviously
  527. * cannot be dropped!
  528. *
  529. * The locking here around t_state is a bit sleazy.
  530. * See the comment at the end of jbd2_journal_commit_transaction().
  531. */
  532. if (transaction->t_state != T_FINISHED)
  533. goto out;
  534. /* OK, that was the last buffer for the transaction: we can now
  535. safely remove this transaction from the log */
  536. stats = &transaction->t_chp_stats;
  537. if (stats->cs_chp_time)
  538. stats->cs_chp_time = jbd2_time_diff(stats->cs_chp_time,
  539. jiffies);
  540. trace_jbd2_checkpoint_stats(journal->j_fs_dev->bd_dev,
  541. transaction->t_tid, stats);
  542. __jbd2_journal_drop_transaction(journal, transaction);
  543. jbd2_journal_free_transaction(transaction);
  544. ret = 1;
  545. out:
  546. return ret;
  547. }
  548. /*
  549. * journal_insert_checkpoint: put a committed buffer onto a checkpoint
  550. * list so that we know when it is safe to clean the transaction out of
  551. * the log.
  552. *
  553. * Called with the journal locked.
  554. * Called with j_list_lock held.
  555. */
  556. void __jbd2_journal_insert_checkpoint(struct journal_head *jh,
  557. transaction_t *transaction)
  558. {
  559. JBUFFER_TRACE(jh, "entry");
  560. J_ASSERT_JH(jh, buffer_dirty(jh2bh(jh)) || buffer_jbddirty(jh2bh(jh)));
  561. J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
  562. /* Get reference for checkpointing transaction */
  563. jbd2_journal_grab_journal_head(jh2bh(jh));
  564. jh->b_cp_transaction = transaction;
  565. if (!transaction->t_checkpoint_list) {
  566. jh->b_cpnext = jh->b_cpprev = jh;
  567. } else {
  568. jh->b_cpnext = transaction->t_checkpoint_list;
  569. jh->b_cpprev = transaction->t_checkpoint_list->b_cpprev;
  570. jh->b_cpprev->b_cpnext = jh;
  571. jh->b_cpnext->b_cpprev = jh;
  572. }
  573. transaction->t_checkpoint_list = jh;
  574. }
  575. /*
  576. * We've finished with this transaction structure: adios...
  577. *
  578. * The transaction must have no links except for the checkpoint by this
  579. * point.
  580. *
  581. * Called with the journal locked.
  582. * Called with j_list_lock held.
  583. */
  584. void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transaction)
  585. {
  586. assert_spin_locked(&journal->j_list_lock);
  587. if (transaction->t_cpnext) {
  588. transaction->t_cpnext->t_cpprev = transaction->t_cpprev;
  589. transaction->t_cpprev->t_cpnext = transaction->t_cpnext;
  590. if (journal->j_checkpoint_transactions == transaction)
  591. journal->j_checkpoint_transactions =
  592. transaction->t_cpnext;
  593. if (journal->j_checkpoint_transactions == transaction)
  594. journal->j_checkpoint_transactions = NULL;
  595. }
  596. J_ASSERT(transaction->t_state == T_FINISHED);
  597. J_ASSERT(transaction->t_buffers == NULL);
  598. J_ASSERT(transaction->t_forget == NULL);
  599. J_ASSERT(transaction->t_shadow_list == NULL);
  600. J_ASSERT(transaction->t_checkpoint_list == NULL);
  601. J_ASSERT(transaction->t_checkpoint_io_list == NULL);
  602. J_ASSERT(atomic_read(&transaction->t_updates) == 0);
  603. J_ASSERT(journal->j_committing_transaction != transaction);
  604. J_ASSERT(journal->j_running_transaction != transaction);
  605. trace_jbd2_drop_transaction(journal, transaction);
  606. jbd_debug(1, "Dropping transaction %d, all done\n", transaction->t_tid);
  607. }