checkpoint.c 19 KB

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