checkpoint.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * linux/fs/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/jbd.h>
  22. #include <linux/errno.h>
  23. #include <linux/slab.h>
  24. /*
  25. * Unlink a buffer from a transaction checkpoint list.
  26. *
  27. * Called with j_list_lock held.
  28. */
  29. static inline void __buffer_unlink_first(struct journal_head *jh)
  30. {
  31. transaction_t *transaction = jh->b_cp_transaction;
  32. jh->b_cpnext->b_cpprev = jh->b_cpprev;
  33. jh->b_cpprev->b_cpnext = jh->b_cpnext;
  34. if (transaction->t_checkpoint_list == jh) {
  35. transaction->t_checkpoint_list = jh->b_cpnext;
  36. if (transaction->t_checkpoint_list == jh)
  37. transaction->t_checkpoint_list = NULL;
  38. }
  39. }
  40. /*
  41. * Unlink a buffer from a transaction checkpoint(io) list.
  42. *
  43. * Called with j_list_lock held.
  44. */
  45. static inline void __buffer_unlink(struct journal_head *jh)
  46. {
  47. transaction_t *transaction = jh->b_cp_transaction;
  48. __buffer_unlink_first(jh);
  49. if (transaction->t_checkpoint_io_list == jh) {
  50. transaction->t_checkpoint_io_list = jh->b_cpnext;
  51. if (transaction->t_checkpoint_io_list == jh)
  52. transaction->t_checkpoint_io_list = NULL;
  53. }
  54. }
  55. /*
  56. * Move a buffer from the checkpoint list to the checkpoint io list
  57. *
  58. * Called with j_list_lock held
  59. */
  60. static inline void __buffer_relink_io(struct journal_head *jh)
  61. {
  62. transaction_t *transaction = jh->b_cp_transaction;
  63. __buffer_unlink_first(jh);
  64. if (!transaction->t_checkpoint_io_list) {
  65. jh->b_cpnext = jh->b_cpprev = jh;
  66. } else {
  67. jh->b_cpnext = transaction->t_checkpoint_io_list;
  68. jh->b_cpprev = transaction->t_checkpoint_io_list->b_cpprev;
  69. jh->b_cpprev->b_cpnext = jh;
  70. jh->b_cpnext->b_cpprev = jh;
  71. }
  72. transaction->t_checkpoint_io_list = jh;
  73. }
  74. /*
  75. * Try to release a checkpointed buffer from its transaction.
  76. * Returns 1 if we released it and 2 if we also released the
  77. * whole transaction.
  78. *
  79. * Requires j_list_lock
  80. * Called under jbd_lock_bh_state(jh2bh(jh)), and drops it
  81. */
  82. static int __try_to_free_cp_buf(struct journal_head *jh)
  83. {
  84. int ret = 0;
  85. struct buffer_head *bh = jh2bh(jh);
  86. if (jh->b_jlist == BJ_None && !buffer_locked(bh) && !buffer_dirty(bh)) {
  87. JBUFFER_TRACE(jh, "remove from checkpoint list");
  88. ret = __journal_remove_checkpoint(jh) + 1;
  89. jbd_unlock_bh_state(bh);
  90. journal_remove_journal_head(bh);
  91. BUFFER_TRACE(bh, "release");
  92. __brelse(bh);
  93. } else {
  94. jbd_unlock_bh_state(bh);
  95. }
  96. return ret;
  97. }
  98. /*
  99. * __log_wait_for_space: wait until there is space in the journal.
  100. *
  101. * Called under j-state_lock *only*. It will be unlocked if we have to wait
  102. * for a checkpoint to free up some space in the log.
  103. */
  104. void __log_wait_for_space(journal_t *journal)
  105. {
  106. int nblocks;
  107. assert_spin_locked(&journal->j_state_lock);
  108. nblocks = jbd_space_needed(journal);
  109. while (__log_space_left(journal) < nblocks) {
  110. if (journal->j_flags & JFS_ABORT)
  111. return;
  112. spin_unlock(&journal->j_state_lock);
  113. mutex_lock(&journal->j_checkpoint_mutex);
  114. /*
  115. * Test again, another process may have checkpointed while we
  116. * were waiting for the checkpoint lock
  117. */
  118. spin_lock(&journal->j_state_lock);
  119. nblocks = jbd_space_needed(journal);
  120. if (__log_space_left(journal) < nblocks) {
  121. spin_unlock(&journal->j_state_lock);
  122. log_do_checkpoint(journal);
  123. spin_lock(&journal->j_state_lock);
  124. }
  125. mutex_unlock(&journal->j_checkpoint_mutex);
  126. }
  127. }
  128. /*
  129. * We were unable to perform jbd_trylock_bh_state() inside j_list_lock.
  130. * The caller must restart a list walk. Wait for someone else to run
  131. * jbd_unlock_bh_state().
  132. */
  133. static void jbd_sync_bh(journal_t *journal, struct buffer_head *bh)
  134. {
  135. get_bh(bh);
  136. spin_unlock(&journal->j_list_lock);
  137. jbd_lock_bh_state(bh);
  138. jbd_unlock_bh_state(bh);
  139. put_bh(bh);
  140. }
  141. /*
  142. * Clean up transaction's list of buffers submitted for io.
  143. * We wait for any pending IO to complete and remove any clean
  144. * buffers. Note that we take the buffers in the opposite ordering
  145. * from the one in which they were submitted for IO.
  146. *
  147. * Called with j_list_lock held.
  148. */
  149. static void __wait_cp_io(journal_t *journal, transaction_t *transaction)
  150. {
  151. struct journal_head *jh;
  152. struct buffer_head *bh;
  153. tid_t this_tid;
  154. int released = 0;
  155. this_tid = transaction->t_tid;
  156. restart:
  157. /* Did somebody clean up the transaction in the meanwhile? */
  158. if (journal->j_checkpoint_transactions != transaction ||
  159. transaction->t_tid != this_tid)
  160. return;
  161. while (!released && transaction->t_checkpoint_io_list) {
  162. jh = transaction->t_checkpoint_io_list;
  163. bh = jh2bh(jh);
  164. if (!jbd_trylock_bh_state(bh)) {
  165. jbd_sync_bh(journal, bh);
  166. spin_lock(&journal->j_list_lock);
  167. goto restart;
  168. }
  169. if (buffer_locked(bh)) {
  170. atomic_inc(&bh->b_count);
  171. spin_unlock(&journal->j_list_lock);
  172. jbd_unlock_bh_state(bh);
  173. wait_on_buffer(bh);
  174. /* the journal_head may have gone by now */
  175. BUFFER_TRACE(bh, "brelse");
  176. __brelse(bh);
  177. spin_lock(&journal->j_list_lock);
  178. goto restart;
  179. }
  180. /*
  181. * Now in whatever state the buffer currently is, we know that
  182. * it has been written out and so we can drop it from the list
  183. */
  184. released = __journal_remove_checkpoint(jh);
  185. jbd_unlock_bh_state(bh);
  186. journal_remove_journal_head(bh);
  187. __brelse(bh);
  188. }
  189. }
  190. #define NR_BATCH 64
  191. static void
  192. __flush_batch(journal_t *journal, struct buffer_head **bhs, int *batch_count)
  193. {
  194. int i;
  195. ll_rw_block(SWRITE, *batch_count, bhs);
  196. for (i = 0; i < *batch_count; i++) {
  197. struct buffer_head *bh = bhs[i];
  198. clear_buffer_jwrite(bh);
  199. BUFFER_TRACE(bh, "brelse");
  200. __brelse(bh);
  201. }
  202. *batch_count = 0;
  203. }
  204. /*
  205. * Try to flush one buffer from the checkpoint list to disk.
  206. *
  207. * Return 1 if something happened which requires us to abort the current
  208. * scan of the checkpoint list.
  209. *
  210. * Called with j_list_lock held and drops it if 1 is returned
  211. * Called under jbd_lock_bh_state(jh2bh(jh)), and drops it
  212. */
  213. static int __process_buffer(journal_t *journal, struct journal_head *jh,
  214. struct buffer_head **bhs, int *batch_count)
  215. {
  216. struct buffer_head *bh = jh2bh(jh);
  217. int ret = 0;
  218. if (buffer_locked(bh)) {
  219. atomic_inc(&bh->b_count);
  220. spin_unlock(&journal->j_list_lock);
  221. jbd_unlock_bh_state(bh);
  222. wait_on_buffer(bh);
  223. /* the journal_head may have gone by now */
  224. BUFFER_TRACE(bh, "brelse");
  225. __brelse(bh);
  226. ret = 1;
  227. } else if (jh->b_transaction != NULL) {
  228. transaction_t *t = jh->b_transaction;
  229. tid_t tid = t->t_tid;
  230. spin_unlock(&journal->j_list_lock);
  231. jbd_unlock_bh_state(bh);
  232. log_start_commit(journal, tid);
  233. log_wait_commit(journal, tid);
  234. ret = 1;
  235. } else if (!buffer_dirty(bh)) {
  236. J_ASSERT_JH(jh, !buffer_jbddirty(bh));
  237. BUFFER_TRACE(bh, "remove from checkpoint");
  238. __journal_remove_checkpoint(jh);
  239. spin_unlock(&journal->j_list_lock);
  240. jbd_unlock_bh_state(bh);
  241. journal_remove_journal_head(bh);
  242. __brelse(bh);
  243. ret = 1;
  244. } else {
  245. /*
  246. * Important: we are about to write the buffer, and
  247. * possibly block, while still holding the journal lock.
  248. * We cannot afford to let the transaction logic start
  249. * messing around with this buffer before we write it to
  250. * disk, as that would break recoverability.
  251. */
  252. BUFFER_TRACE(bh, "queue");
  253. get_bh(bh);
  254. J_ASSERT_BH(bh, !buffer_jwrite(bh));
  255. set_buffer_jwrite(bh);
  256. bhs[*batch_count] = bh;
  257. __buffer_relink_io(jh);
  258. jbd_unlock_bh_state(bh);
  259. (*batch_count)++;
  260. if (*batch_count == NR_BATCH) {
  261. spin_unlock(&journal->j_list_lock);
  262. __flush_batch(journal, bhs, batch_count);
  263. ret = 1;
  264. }
  265. }
  266. return ret;
  267. }
  268. /*
  269. * Perform an actual checkpoint. We take the first transaction on the
  270. * list of transactions to be checkpointed and send all its buffers
  271. * to disk. We submit larger chunks of data at once.
  272. *
  273. * The journal should be locked before calling this function.
  274. */
  275. int log_do_checkpoint(journal_t *journal)
  276. {
  277. transaction_t *transaction;
  278. tid_t this_tid;
  279. int result;
  280. jbd_debug(1, "Start checkpoint\n");
  281. /*
  282. * First thing: if there are any transactions in the log which
  283. * don't need checkpointing, just eliminate them from the
  284. * journal straight away.
  285. */
  286. result = cleanup_journal_tail(journal);
  287. jbd_debug(1, "cleanup_journal_tail returned %d\n", result);
  288. if (result <= 0)
  289. return result;
  290. /*
  291. * OK, we need to start writing disk blocks. Take one transaction
  292. * and write it.
  293. */
  294. spin_lock(&journal->j_list_lock);
  295. if (!journal->j_checkpoint_transactions)
  296. goto out;
  297. transaction = journal->j_checkpoint_transactions;
  298. this_tid = transaction->t_tid;
  299. restart:
  300. /*
  301. * If someone cleaned up this transaction while we slept, we're
  302. * done (maybe it's a new transaction, but it fell at the same
  303. * address).
  304. */
  305. if (journal->j_checkpoint_transactions == transaction &&
  306. transaction->t_tid == this_tid) {
  307. int batch_count = 0;
  308. struct buffer_head *bhs[NR_BATCH];
  309. struct journal_head *jh;
  310. int retry = 0;
  311. while (!retry && transaction->t_checkpoint_list) {
  312. struct buffer_head *bh;
  313. jh = transaction->t_checkpoint_list;
  314. bh = jh2bh(jh);
  315. if (!jbd_trylock_bh_state(bh)) {
  316. jbd_sync_bh(journal, bh);
  317. retry = 1;
  318. break;
  319. }
  320. retry = __process_buffer(journal, jh, bhs,&batch_count);
  321. if (!retry && lock_need_resched(&journal->j_list_lock)){
  322. spin_unlock(&journal->j_list_lock);
  323. retry = 1;
  324. break;
  325. }
  326. }
  327. if (batch_count) {
  328. if (!retry) {
  329. spin_unlock(&journal->j_list_lock);
  330. retry = 1;
  331. }
  332. __flush_batch(journal, bhs, &batch_count);
  333. }
  334. if (retry) {
  335. spin_lock(&journal->j_list_lock);
  336. goto restart;
  337. }
  338. /*
  339. * Now we have cleaned up the first transaction's checkpoint
  340. * list. Let's clean up the second one
  341. */
  342. __wait_cp_io(journal, transaction);
  343. }
  344. out:
  345. spin_unlock(&journal->j_list_lock);
  346. result = cleanup_journal_tail(journal);
  347. if (result < 0)
  348. return result;
  349. return 0;
  350. }
  351. /*
  352. * Check the list of checkpoint transactions for the journal to see if
  353. * we have already got rid of any since the last update of the log tail
  354. * in the journal superblock. If so, we can instantly roll the
  355. * superblock forward to remove those transactions from the log.
  356. *
  357. * Return <0 on error, 0 on success, 1 if there was nothing to clean up.
  358. *
  359. * Called with the journal lock held.
  360. *
  361. * This is the only part of the journaling code which really needs to be
  362. * aware of transaction aborts. Checkpointing involves writing to the
  363. * main filesystem area rather than to the journal, so it can proceed
  364. * even in abort state, but we must not update the journal superblock if
  365. * we have an abort error outstanding.
  366. */
  367. int cleanup_journal_tail(journal_t *journal)
  368. {
  369. transaction_t * transaction;
  370. tid_t first_tid;
  371. unsigned long blocknr, freed;
  372. /* OK, work out the oldest transaction remaining in the log, and
  373. * the log block it starts at.
  374. *
  375. * If the log is now empty, we need to work out which is the
  376. * next transaction ID we will write, and where it will
  377. * start. */
  378. spin_lock(&journal->j_state_lock);
  379. spin_lock(&journal->j_list_lock);
  380. transaction = journal->j_checkpoint_transactions;
  381. if (transaction) {
  382. first_tid = transaction->t_tid;
  383. blocknr = transaction->t_log_start;
  384. } else if ((transaction = journal->j_committing_transaction) != NULL) {
  385. first_tid = transaction->t_tid;
  386. blocknr = transaction->t_log_start;
  387. } else if ((transaction = journal->j_running_transaction) != NULL) {
  388. first_tid = transaction->t_tid;
  389. blocknr = journal->j_head;
  390. } else {
  391. first_tid = journal->j_transaction_sequence;
  392. blocknr = journal->j_head;
  393. }
  394. spin_unlock(&journal->j_list_lock);
  395. J_ASSERT(blocknr != 0);
  396. /* If the oldest pinned transaction is at the tail of the log
  397. already then there's not much we can do right now. */
  398. if (journal->j_tail_sequence == first_tid) {
  399. spin_unlock(&journal->j_state_lock);
  400. return 1;
  401. }
  402. /* OK, update the superblock to recover the freed space.
  403. * Physical blocks come first: have we wrapped beyond the end of
  404. * the log? */
  405. freed = blocknr - journal->j_tail;
  406. if (blocknr < journal->j_tail)
  407. freed = freed + journal->j_last - journal->j_first;
  408. jbd_debug(1,
  409. "Cleaning journal tail from %d to %d (offset %lu), "
  410. "freeing %lu\n",
  411. journal->j_tail_sequence, first_tid, blocknr, freed);
  412. journal->j_free += freed;
  413. journal->j_tail_sequence = first_tid;
  414. journal->j_tail = blocknr;
  415. spin_unlock(&journal->j_state_lock);
  416. if (!(journal->j_flags & JFS_ABORT))
  417. journal_update_superblock(journal, 1);
  418. return 0;
  419. }
  420. /* Checkpoint list management */
  421. /*
  422. * journal_clean_one_cp_list
  423. *
  424. * Find all the written-back checkpoint buffers in the given list and release them.
  425. *
  426. * Called with the journal locked.
  427. * Called with j_list_lock held.
  428. * Returns number of bufers reaped (for debug)
  429. */
  430. static int journal_clean_one_cp_list(struct journal_head *jh, int *released)
  431. {
  432. struct journal_head *last_jh;
  433. struct journal_head *next_jh = jh;
  434. int ret, freed = 0;
  435. *released = 0;
  436. if (!jh)
  437. return 0;
  438. last_jh = jh->b_cpprev;
  439. do {
  440. jh = next_jh;
  441. next_jh = jh->b_cpnext;
  442. /* Use trylock because of the ranking */
  443. if (jbd_trylock_bh_state(jh2bh(jh))) {
  444. ret = __try_to_free_cp_buf(jh);
  445. if (ret) {
  446. freed++;
  447. if (ret == 2) {
  448. *released = 1;
  449. return freed;
  450. }
  451. }
  452. }
  453. /*
  454. * This function only frees up some memory
  455. * if possible so we dont have an obligation
  456. * to finish processing. Bail out if preemption
  457. * requested:
  458. */
  459. if (need_resched())
  460. return freed;
  461. } while (jh != last_jh);
  462. return freed;
  463. }
  464. /*
  465. * journal_clean_checkpoint_list
  466. *
  467. * Find all the written-back checkpoint buffers in the journal and release them.
  468. *
  469. * Called with the journal locked.
  470. * Called with j_list_lock held.
  471. * Returns number of buffers reaped (for debug)
  472. */
  473. int __journal_clean_checkpoint_list(journal_t *journal)
  474. {
  475. transaction_t *transaction, *last_transaction, *next_transaction;
  476. int ret = 0;
  477. int released;
  478. transaction = journal->j_checkpoint_transactions;
  479. if (!transaction)
  480. goto out;
  481. last_transaction = transaction->t_cpprev;
  482. next_transaction = transaction;
  483. do {
  484. transaction = next_transaction;
  485. next_transaction = transaction->t_cpnext;
  486. ret += journal_clean_one_cp_list(transaction->
  487. t_checkpoint_list, &released);
  488. /*
  489. * This function only frees up some memory if possible so we
  490. * dont have an obligation to finish processing. Bail out if
  491. * preemption requested:
  492. */
  493. if (need_resched())
  494. goto out;
  495. if (released)
  496. continue;
  497. /*
  498. * It is essential that we are as careful as in the case of
  499. * t_checkpoint_list with removing the buffer from the list as
  500. * we can possibly see not yet submitted buffers on io_list
  501. */
  502. ret += journal_clean_one_cp_list(transaction->
  503. t_checkpoint_io_list, &released);
  504. if (need_resched())
  505. goto out;
  506. } while (transaction != last_transaction);
  507. out:
  508. return ret;
  509. }
  510. /*
  511. * journal_remove_checkpoint: called after a buffer has been committed
  512. * to disk (either by being write-back flushed to disk, or being
  513. * committed to the log).
  514. *
  515. * We cannot safely clean a transaction out of the log until all of the
  516. * buffer updates committed in that transaction have safely been stored
  517. * elsewhere on disk. To achieve this, all of the buffers in a
  518. * transaction need to be maintained on the transaction's checkpoint
  519. * lists until they have been rewritten, at which point this function is
  520. * called to remove the buffer from the existing transaction's
  521. * checkpoint lists.
  522. *
  523. * The function returns 1 if it frees the transaction, 0 otherwise.
  524. *
  525. * This function is called with the journal locked.
  526. * This function is called with j_list_lock held.
  527. * This function is called with jbd_lock_bh_state(jh2bh(jh))
  528. */
  529. int __journal_remove_checkpoint(struct journal_head *jh)
  530. {
  531. transaction_t *transaction;
  532. journal_t *journal;
  533. int ret = 0;
  534. JBUFFER_TRACE(jh, "entry");
  535. if ((transaction = jh->b_cp_transaction) == NULL) {
  536. JBUFFER_TRACE(jh, "not on transaction");
  537. goto out;
  538. }
  539. journal = transaction->t_journal;
  540. __buffer_unlink(jh);
  541. jh->b_cp_transaction = NULL;
  542. if (transaction->t_checkpoint_list != NULL ||
  543. transaction->t_checkpoint_io_list != NULL)
  544. goto out;
  545. JBUFFER_TRACE(jh, "transaction has no more buffers");
  546. /*
  547. * There is one special case to worry about: if we have just pulled the
  548. * buffer off a committing transaction's forget list, then even if the
  549. * checkpoint list is empty, the transaction obviously cannot be
  550. * dropped!
  551. *
  552. * The locking here around j_committing_transaction is a bit sleazy.
  553. * See the comment at the end of journal_commit_transaction().
  554. */
  555. if (transaction == journal->j_committing_transaction) {
  556. JBUFFER_TRACE(jh, "belongs to committing transaction");
  557. goto out;
  558. }
  559. /* OK, that was the last buffer for the transaction: we can now
  560. safely remove this transaction from the log */
  561. __journal_drop_transaction(journal, transaction);
  562. /* Just in case anybody was waiting for more transactions to be
  563. checkpointed... */
  564. wake_up(&journal->j_wait_logspace);
  565. ret = 1;
  566. out:
  567. JBUFFER_TRACE(jh, "exit");
  568. return ret;
  569. }
  570. /*
  571. * journal_insert_checkpoint: put a committed buffer onto a checkpoint
  572. * list so that we know when it is safe to clean the transaction out of
  573. * the log.
  574. *
  575. * Called with the journal locked.
  576. * Called with j_list_lock held.
  577. */
  578. void __journal_insert_checkpoint(struct journal_head *jh,
  579. transaction_t *transaction)
  580. {
  581. JBUFFER_TRACE(jh, "entry");
  582. J_ASSERT_JH(jh, buffer_dirty(jh2bh(jh)) || buffer_jbddirty(jh2bh(jh)));
  583. J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
  584. jh->b_cp_transaction = transaction;
  585. if (!transaction->t_checkpoint_list) {
  586. jh->b_cpnext = jh->b_cpprev = jh;
  587. } else {
  588. jh->b_cpnext = transaction->t_checkpoint_list;
  589. jh->b_cpprev = transaction->t_checkpoint_list->b_cpprev;
  590. jh->b_cpprev->b_cpnext = jh;
  591. jh->b_cpnext->b_cpprev = jh;
  592. }
  593. transaction->t_checkpoint_list = jh;
  594. }
  595. /*
  596. * We've finished with this transaction structure: adios...
  597. *
  598. * The transaction must have no links except for the checkpoint by this
  599. * point.
  600. *
  601. * Called with the journal locked.
  602. * Called with j_list_lock held.
  603. */
  604. void __journal_drop_transaction(journal_t *journal, transaction_t *transaction)
  605. {
  606. assert_spin_locked(&journal->j_list_lock);
  607. if (transaction->t_cpnext) {
  608. transaction->t_cpnext->t_cpprev = transaction->t_cpprev;
  609. transaction->t_cpprev->t_cpnext = transaction->t_cpnext;
  610. if (journal->j_checkpoint_transactions == transaction)
  611. journal->j_checkpoint_transactions =
  612. transaction->t_cpnext;
  613. if (journal->j_checkpoint_transactions == transaction)
  614. journal->j_checkpoint_transactions = NULL;
  615. }
  616. J_ASSERT(transaction->t_state == T_FINISHED);
  617. J_ASSERT(transaction->t_buffers == NULL);
  618. J_ASSERT(transaction->t_sync_datalist == NULL);
  619. J_ASSERT(transaction->t_forget == NULL);
  620. J_ASSERT(transaction->t_iobuf_list == NULL);
  621. J_ASSERT(transaction->t_shadow_list == NULL);
  622. J_ASSERT(transaction->t_log_list == NULL);
  623. J_ASSERT(transaction->t_checkpoint_list == NULL);
  624. J_ASSERT(transaction->t_checkpoint_io_list == NULL);
  625. J_ASSERT(transaction->t_updates == 0);
  626. J_ASSERT(journal->j_committing_transaction != transaction);
  627. J_ASSERT(journal->j_running_transaction != transaction);
  628. jbd_debug(1, "Dropping transaction %d, all done\n", transaction->t_tid);
  629. kfree(transaction);
  630. }