checkpoint.c 20 KB

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