checkpoint.c 19 KB

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