commit.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /*
  2. * linux/fs/jbd2/commit.c
  3. *
  4. * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
  5. *
  6. * Copyright 1998 Red Hat corp --- 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. * Journal commit routines for the generic filesystem journaling code;
  13. * part of the ext2fs journaling system.
  14. */
  15. #include <linux/time.h>
  16. #include <linux/fs.h>
  17. #include <linux/jbd2.h>
  18. #include <linux/errno.h>
  19. #include <linux/slab.h>
  20. #include <linux/mm.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/crc32.h>
  24. #include <linux/writeback.h>
  25. #include <linux/backing-dev.h>
  26. #include <linux/bio.h>
  27. #include <linux/blkdev.h>
  28. #include <linux/bitops.h>
  29. #include <trace/events/jbd2.h>
  30. /*
  31. * Default IO end handler for temporary BJ_IO buffer_heads.
  32. */
  33. static void journal_end_buffer_io_sync(struct buffer_head *bh, int uptodate)
  34. {
  35. BUFFER_TRACE(bh, "");
  36. if (uptodate)
  37. set_buffer_uptodate(bh);
  38. else
  39. clear_buffer_uptodate(bh);
  40. unlock_buffer(bh);
  41. }
  42. /*
  43. * When an ext4 file is truncated, it is possible that some pages are not
  44. * successfully freed, because they are attached to a committing transaction.
  45. * After the transaction commits, these pages are left on the LRU, with no
  46. * ->mapping, and with attached buffers. These pages are trivially reclaimable
  47. * by the VM, but their apparent absence upsets the VM accounting, and it makes
  48. * the numbers in /proc/meminfo look odd.
  49. *
  50. * So here, we have a buffer which has just come off the forget list. Look to
  51. * see if we can strip all buffers from the backing page.
  52. *
  53. * Called under lock_journal(), and possibly under journal_datalist_lock. The
  54. * caller provided us with a ref against the buffer, and we drop that here.
  55. */
  56. static void release_buffer_page(struct buffer_head *bh)
  57. {
  58. struct page *page;
  59. if (buffer_dirty(bh))
  60. goto nope;
  61. if (atomic_read(&bh->b_count) != 1)
  62. goto nope;
  63. page = bh->b_page;
  64. if (!page)
  65. goto nope;
  66. if (page->mapping)
  67. goto nope;
  68. /* OK, it's a truncated page */
  69. if (!trylock_page(page))
  70. goto nope;
  71. page_cache_get(page);
  72. __brelse(bh);
  73. try_to_free_buffers(page);
  74. unlock_page(page);
  75. page_cache_release(page);
  76. return;
  77. nope:
  78. __brelse(bh);
  79. }
  80. static void jbd2_commit_block_csum_set(journal_t *j,
  81. struct journal_head *descriptor)
  82. {
  83. struct commit_header *h;
  84. __u32 csum;
  85. if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
  86. return;
  87. h = (struct commit_header *)(jh2bh(descriptor)->b_data);
  88. h->h_chksum_type = 0;
  89. h->h_chksum_size = 0;
  90. h->h_chksum[0] = 0;
  91. csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data,
  92. j->j_blocksize);
  93. h->h_chksum[0] = cpu_to_be32(csum);
  94. }
  95. /*
  96. * Done it all: now submit the commit record. We should have
  97. * cleaned up our previous buffers by now, so if we are in abort
  98. * mode we can now just skip the rest of the journal write
  99. * entirely.
  100. *
  101. * Returns 1 if the journal needs to be aborted or 0 on success
  102. */
  103. static int journal_submit_commit_record(journal_t *journal,
  104. transaction_t *commit_transaction,
  105. struct buffer_head **cbh,
  106. __u32 crc32_sum)
  107. {
  108. struct journal_head *descriptor;
  109. struct commit_header *tmp;
  110. struct buffer_head *bh;
  111. int ret;
  112. struct timespec now = current_kernel_time();
  113. *cbh = NULL;
  114. if (is_journal_aborted(journal))
  115. return 0;
  116. descriptor = jbd2_journal_get_descriptor_buffer(journal);
  117. if (!descriptor)
  118. return 1;
  119. bh = jh2bh(descriptor);
  120. tmp = (struct commit_header *)bh->b_data;
  121. tmp->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
  122. tmp->h_blocktype = cpu_to_be32(JBD2_COMMIT_BLOCK);
  123. tmp->h_sequence = cpu_to_be32(commit_transaction->t_tid);
  124. tmp->h_commit_sec = cpu_to_be64(now.tv_sec);
  125. tmp->h_commit_nsec = cpu_to_be32(now.tv_nsec);
  126. if (JBD2_HAS_COMPAT_FEATURE(journal,
  127. JBD2_FEATURE_COMPAT_CHECKSUM)) {
  128. tmp->h_chksum_type = JBD2_CRC32_CHKSUM;
  129. tmp->h_chksum_size = JBD2_CRC32_CHKSUM_SIZE;
  130. tmp->h_chksum[0] = cpu_to_be32(crc32_sum);
  131. }
  132. jbd2_commit_block_csum_set(journal, descriptor);
  133. JBUFFER_TRACE(descriptor, "submit commit block");
  134. lock_buffer(bh);
  135. clear_buffer_dirty(bh);
  136. set_buffer_uptodate(bh);
  137. bh->b_end_io = journal_end_buffer_io_sync;
  138. if (journal->j_flags & JBD2_BARRIER &&
  139. !JBD2_HAS_INCOMPAT_FEATURE(journal,
  140. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT))
  141. ret = submit_bh(WRITE_SYNC | WRITE_FLUSH_FUA, bh);
  142. else
  143. ret = submit_bh(WRITE_SYNC, bh);
  144. *cbh = bh;
  145. return ret;
  146. }
  147. /*
  148. * This function along with journal_submit_commit_record
  149. * allows to write the commit record asynchronously.
  150. */
  151. static int journal_wait_on_commit_record(journal_t *journal,
  152. struct buffer_head *bh)
  153. {
  154. int ret = 0;
  155. clear_buffer_dirty(bh);
  156. wait_on_buffer(bh);
  157. if (unlikely(!buffer_uptodate(bh)))
  158. ret = -EIO;
  159. put_bh(bh); /* One for getblk() */
  160. jbd2_journal_put_journal_head(bh2jh(bh));
  161. return ret;
  162. }
  163. /*
  164. * write the filemap data using writepage() address_space_operations.
  165. * We don't do block allocation here even for delalloc. We don't
  166. * use writepages() because with dealyed allocation we may be doing
  167. * block allocation in writepages().
  168. */
  169. static int journal_submit_inode_data_buffers(struct address_space *mapping)
  170. {
  171. int ret;
  172. struct writeback_control wbc = {
  173. .sync_mode = WB_SYNC_ALL,
  174. .nr_to_write = mapping->nrpages * 2,
  175. .range_start = 0,
  176. .range_end = i_size_read(mapping->host),
  177. };
  178. ret = generic_writepages(mapping, &wbc);
  179. return ret;
  180. }
  181. /*
  182. * Submit all the data buffers of inode associated with the transaction to
  183. * disk.
  184. *
  185. * We are in a committing transaction. Therefore no new inode can be added to
  186. * our inode list. We use JI_COMMIT_RUNNING flag to protect inode we currently
  187. * operate on from being released while we write out pages.
  188. */
  189. static int journal_submit_data_buffers(journal_t *journal,
  190. transaction_t *commit_transaction)
  191. {
  192. struct jbd2_inode *jinode;
  193. int err, ret = 0;
  194. struct address_space *mapping;
  195. spin_lock(&journal->j_list_lock);
  196. list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
  197. mapping = jinode->i_vfs_inode->i_mapping;
  198. set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
  199. spin_unlock(&journal->j_list_lock);
  200. /*
  201. * submit the inode data buffers. We use writepage
  202. * instead of writepages. Because writepages can do
  203. * block allocation with delalloc. We need to write
  204. * only allocated blocks here.
  205. */
  206. trace_jbd2_submit_inode_data(jinode->i_vfs_inode);
  207. err = journal_submit_inode_data_buffers(mapping);
  208. if (!ret)
  209. ret = err;
  210. spin_lock(&journal->j_list_lock);
  211. J_ASSERT(jinode->i_transaction == commit_transaction);
  212. clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
  213. smp_mb__after_clear_bit();
  214. wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
  215. }
  216. spin_unlock(&journal->j_list_lock);
  217. return ret;
  218. }
  219. /*
  220. * Wait for data submitted for writeout, refile inodes to proper
  221. * transaction if needed.
  222. *
  223. */
  224. static int journal_finish_inode_data_buffers(journal_t *journal,
  225. transaction_t *commit_transaction)
  226. {
  227. struct jbd2_inode *jinode, *next_i;
  228. int err, ret = 0;
  229. /* For locking, see the comment in journal_submit_data_buffers() */
  230. spin_lock(&journal->j_list_lock);
  231. list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
  232. set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
  233. spin_unlock(&journal->j_list_lock);
  234. err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
  235. if (err) {
  236. /*
  237. * Because AS_EIO is cleared by
  238. * filemap_fdatawait_range(), set it again so
  239. * that user process can get -EIO from fsync().
  240. */
  241. set_bit(AS_EIO,
  242. &jinode->i_vfs_inode->i_mapping->flags);
  243. if (!ret)
  244. ret = err;
  245. }
  246. spin_lock(&journal->j_list_lock);
  247. clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
  248. smp_mb__after_clear_bit();
  249. wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
  250. }
  251. /* Now refile inode to proper lists */
  252. list_for_each_entry_safe(jinode, next_i,
  253. &commit_transaction->t_inode_list, i_list) {
  254. list_del(&jinode->i_list);
  255. if (jinode->i_next_transaction) {
  256. jinode->i_transaction = jinode->i_next_transaction;
  257. jinode->i_next_transaction = NULL;
  258. list_add(&jinode->i_list,
  259. &jinode->i_transaction->t_inode_list);
  260. } else {
  261. jinode->i_transaction = NULL;
  262. }
  263. }
  264. spin_unlock(&journal->j_list_lock);
  265. return ret;
  266. }
  267. static __u32 jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
  268. {
  269. struct page *page = bh->b_page;
  270. char *addr;
  271. __u32 checksum;
  272. addr = kmap_atomic(page);
  273. checksum = crc32_be(crc32_sum,
  274. (void *)(addr + offset_in_page(bh->b_data)), bh->b_size);
  275. kunmap_atomic(addr);
  276. return checksum;
  277. }
  278. static void write_tag_block(int tag_bytes, journal_block_tag_t *tag,
  279. unsigned long long block)
  280. {
  281. tag->t_blocknr = cpu_to_be32(block & (u32)~0);
  282. if (tag_bytes > JBD2_TAG_SIZE32)
  283. tag->t_blocknr_high = cpu_to_be32((block >> 31) >> 1);
  284. }
  285. static void jbd2_descr_block_csum_set(journal_t *j,
  286. struct journal_head *descriptor)
  287. {
  288. struct jbd2_journal_block_tail *tail;
  289. __u32 csum;
  290. if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
  291. return;
  292. tail = (struct jbd2_journal_block_tail *)
  293. (jh2bh(descriptor)->b_data + j->j_blocksize -
  294. sizeof(struct jbd2_journal_block_tail));
  295. tail->t_checksum = 0;
  296. csum = jbd2_chksum(j, j->j_csum_seed, jh2bh(descriptor)->b_data,
  297. j->j_blocksize);
  298. tail->t_checksum = cpu_to_be32(csum);
  299. }
  300. static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
  301. struct buffer_head *bh, __u32 sequence)
  302. {
  303. struct page *page = bh->b_page;
  304. __u8 *addr;
  305. __u32 csum;
  306. if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
  307. return;
  308. sequence = cpu_to_be32(sequence);
  309. addr = kmap_atomic(page);
  310. csum = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
  311. sizeof(sequence));
  312. csum = jbd2_chksum(j, csum, addr + offset_in_page(bh->b_data),
  313. bh->b_size);
  314. kunmap_atomic(addr);
  315. tag->t_checksum = cpu_to_be32(csum);
  316. }
  317. /*
  318. * jbd2_journal_commit_transaction
  319. *
  320. * The primary function for committing a transaction to the log. This
  321. * function is called by the journal thread to begin a complete commit.
  322. */
  323. void jbd2_journal_commit_transaction(journal_t *journal)
  324. {
  325. struct transaction_stats_s stats;
  326. transaction_t *commit_transaction;
  327. struct journal_head *jh, *new_jh, *descriptor;
  328. struct buffer_head **wbuf = journal->j_wbuf;
  329. int bufs;
  330. int flags;
  331. int err;
  332. unsigned long long blocknr;
  333. ktime_t start_time;
  334. u64 commit_time;
  335. char *tagp = NULL;
  336. journal_header_t *header;
  337. journal_block_tag_t *tag = NULL;
  338. int space_left = 0;
  339. int first_tag = 0;
  340. int tag_flag;
  341. int i, to_free = 0;
  342. int tag_bytes = journal_tag_bytes(journal);
  343. struct buffer_head *cbh = NULL; /* For transactional checksums */
  344. __u32 crc32_sum = ~0;
  345. struct blk_plug plug;
  346. /* Tail of the journal */
  347. unsigned long first_block;
  348. tid_t first_tid;
  349. int update_tail;
  350. int csum_size = 0;
  351. if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
  352. csum_size = sizeof(struct jbd2_journal_block_tail);
  353. /*
  354. * First job: lock down the current transaction and wait for
  355. * all outstanding updates to complete.
  356. */
  357. /* Do we need to erase the effects of a prior jbd2_journal_flush? */
  358. if (journal->j_flags & JBD2_FLUSHED) {
  359. jbd_debug(3, "super block updated\n");
  360. mutex_lock(&journal->j_checkpoint_mutex);
  361. /*
  362. * We hold j_checkpoint_mutex so tail cannot change under us.
  363. * We don't need any special data guarantees for writing sb
  364. * since journal is empty and it is ok for write to be
  365. * flushed only with transaction commit.
  366. */
  367. jbd2_journal_update_sb_log_tail(journal,
  368. journal->j_tail_sequence,
  369. journal->j_tail,
  370. WRITE_SYNC);
  371. mutex_unlock(&journal->j_checkpoint_mutex);
  372. } else {
  373. jbd_debug(3, "superblock not updated\n");
  374. }
  375. J_ASSERT(journal->j_running_transaction != NULL);
  376. J_ASSERT(journal->j_committing_transaction == NULL);
  377. commit_transaction = journal->j_running_transaction;
  378. J_ASSERT(commit_transaction->t_state == T_RUNNING);
  379. trace_jbd2_start_commit(journal, commit_transaction);
  380. jbd_debug(1, "JBD2: starting commit of transaction %d\n",
  381. commit_transaction->t_tid);
  382. write_lock(&journal->j_state_lock);
  383. commit_transaction->t_state = T_LOCKED;
  384. trace_jbd2_commit_locking(journal, commit_transaction);
  385. stats.run.rs_wait = commit_transaction->t_max_wait;
  386. stats.run.rs_request_delay = 0;
  387. stats.run.rs_locked = jiffies;
  388. if (commit_transaction->t_requested)
  389. stats.run.rs_request_delay =
  390. jbd2_time_diff(commit_transaction->t_requested,
  391. stats.run.rs_locked);
  392. stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
  393. stats.run.rs_locked);
  394. spin_lock(&commit_transaction->t_handle_lock);
  395. while (atomic_read(&commit_transaction->t_updates)) {
  396. DEFINE_WAIT(wait);
  397. prepare_to_wait(&journal->j_wait_updates, &wait,
  398. TASK_UNINTERRUPTIBLE);
  399. if (atomic_read(&commit_transaction->t_updates)) {
  400. spin_unlock(&commit_transaction->t_handle_lock);
  401. write_unlock(&journal->j_state_lock);
  402. schedule();
  403. write_lock(&journal->j_state_lock);
  404. spin_lock(&commit_transaction->t_handle_lock);
  405. }
  406. finish_wait(&journal->j_wait_updates, &wait);
  407. }
  408. spin_unlock(&commit_transaction->t_handle_lock);
  409. J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
  410. journal->j_max_transaction_buffers);
  411. /*
  412. * First thing we are allowed to do is to discard any remaining
  413. * BJ_Reserved buffers. Note, it is _not_ permissible to assume
  414. * that there are no such buffers: if a large filesystem
  415. * operation like a truncate needs to split itself over multiple
  416. * transactions, then it may try to do a jbd2_journal_restart() while
  417. * there are still BJ_Reserved buffers outstanding. These must
  418. * be released cleanly from the current transaction.
  419. *
  420. * In this case, the filesystem must still reserve write access
  421. * again before modifying the buffer in the new transaction, but
  422. * we do not require it to remember exactly which old buffers it
  423. * has reserved. This is consistent with the existing behaviour
  424. * that multiple jbd2_journal_get_write_access() calls to the same
  425. * buffer are perfectly permissible.
  426. */
  427. while (commit_transaction->t_reserved_list) {
  428. jh = commit_transaction->t_reserved_list;
  429. JBUFFER_TRACE(jh, "reserved, unused: refile");
  430. /*
  431. * A jbd2_journal_get_undo_access()+jbd2_journal_release_buffer() may
  432. * leave undo-committed data.
  433. */
  434. if (jh->b_committed_data) {
  435. struct buffer_head *bh = jh2bh(jh);
  436. jbd_lock_bh_state(bh);
  437. jbd2_free(jh->b_committed_data, bh->b_size);
  438. jh->b_committed_data = NULL;
  439. jbd_unlock_bh_state(bh);
  440. }
  441. jbd2_journal_refile_buffer(journal, jh);
  442. }
  443. /*
  444. * Now try to drop any written-back buffers from the journal's
  445. * checkpoint lists. We do this *before* commit because it potentially
  446. * frees some memory
  447. */
  448. spin_lock(&journal->j_list_lock);
  449. __jbd2_journal_clean_checkpoint_list(journal);
  450. spin_unlock(&journal->j_list_lock);
  451. jbd_debug(3, "JBD2: commit phase 1\n");
  452. /*
  453. * Clear revoked flag to reflect there is no revoked buffers
  454. * in the next transaction which is going to be started.
  455. */
  456. jbd2_clear_buffer_revoked_flags(journal);
  457. /*
  458. * Switch to a new revoke table.
  459. */
  460. jbd2_journal_switch_revoke_table(journal);
  461. trace_jbd2_commit_flushing(journal, commit_transaction);
  462. stats.run.rs_flushing = jiffies;
  463. stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked,
  464. stats.run.rs_flushing);
  465. commit_transaction->t_state = T_FLUSH;
  466. journal->j_committing_transaction = commit_transaction;
  467. journal->j_running_transaction = NULL;
  468. start_time = ktime_get();
  469. commit_transaction->t_log_start = journal->j_head;
  470. wake_up(&journal->j_wait_transaction_locked);
  471. write_unlock(&journal->j_state_lock);
  472. jbd_debug(3, "JBD2: commit phase 2\n");
  473. /*
  474. * Now start flushing things to disk, in the order they appear
  475. * on the transaction lists. Data blocks go first.
  476. */
  477. err = journal_submit_data_buffers(journal, commit_transaction);
  478. if (err)
  479. jbd2_journal_abort(journal, err);
  480. blk_start_plug(&plug);
  481. jbd2_journal_write_revoke_records(journal, commit_transaction,
  482. WRITE_SYNC);
  483. blk_finish_plug(&plug);
  484. jbd_debug(3, "JBD2: commit phase 2\n");
  485. /*
  486. * Way to go: we have now written out all of the data for a
  487. * transaction! Now comes the tricky part: we need to write out
  488. * metadata. Loop over the transaction's entire buffer list:
  489. */
  490. write_lock(&journal->j_state_lock);
  491. commit_transaction->t_state = T_COMMIT;
  492. write_unlock(&journal->j_state_lock);
  493. trace_jbd2_commit_logging(journal, commit_transaction);
  494. stats.run.rs_logging = jiffies;
  495. stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing,
  496. stats.run.rs_logging);
  497. stats.run.rs_blocks =
  498. atomic_read(&commit_transaction->t_outstanding_credits);
  499. stats.run.rs_blocks_logged = 0;
  500. J_ASSERT(commit_transaction->t_nr_buffers <=
  501. atomic_read(&commit_transaction->t_outstanding_credits));
  502. err = 0;
  503. descriptor = NULL;
  504. bufs = 0;
  505. blk_start_plug(&plug);
  506. while (commit_transaction->t_buffers) {
  507. /* Find the next buffer to be journaled... */
  508. jh = commit_transaction->t_buffers;
  509. /* If we're in abort mode, we just un-journal the buffer and
  510. release it. */
  511. if (is_journal_aborted(journal)) {
  512. clear_buffer_jbddirty(jh2bh(jh));
  513. JBUFFER_TRACE(jh, "journal is aborting: refile");
  514. jbd2_buffer_abort_trigger(jh,
  515. jh->b_frozen_data ?
  516. jh->b_frozen_triggers :
  517. jh->b_triggers);
  518. jbd2_journal_refile_buffer(journal, jh);
  519. /* If that was the last one, we need to clean up
  520. * any descriptor buffers which may have been
  521. * already allocated, even if we are now
  522. * aborting. */
  523. if (!commit_transaction->t_buffers)
  524. goto start_journal_io;
  525. continue;
  526. }
  527. /* Make sure we have a descriptor block in which to
  528. record the metadata buffer. */
  529. if (!descriptor) {
  530. struct buffer_head *bh;
  531. J_ASSERT (bufs == 0);
  532. jbd_debug(4, "JBD2: get descriptor\n");
  533. descriptor = jbd2_journal_get_descriptor_buffer(journal);
  534. if (!descriptor) {
  535. jbd2_journal_abort(journal, -EIO);
  536. continue;
  537. }
  538. bh = jh2bh(descriptor);
  539. jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
  540. (unsigned long long)bh->b_blocknr, bh->b_data);
  541. header = (journal_header_t *)&bh->b_data[0];
  542. header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
  543. header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
  544. header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
  545. tagp = &bh->b_data[sizeof(journal_header_t)];
  546. space_left = bh->b_size - sizeof(journal_header_t);
  547. first_tag = 1;
  548. set_buffer_jwrite(bh);
  549. set_buffer_dirty(bh);
  550. wbuf[bufs++] = bh;
  551. /* Record it so that we can wait for IO
  552. completion later */
  553. BUFFER_TRACE(bh, "ph3: file as descriptor");
  554. jbd2_journal_file_buffer(descriptor, commit_transaction,
  555. BJ_LogCtl);
  556. }
  557. /* Where is the buffer to be written? */
  558. err = jbd2_journal_next_log_block(journal, &blocknr);
  559. /* If the block mapping failed, just abandon the buffer
  560. and repeat this loop: we'll fall into the
  561. refile-on-abort condition above. */
  562. if (err) {
  563. jbd2_journal_abort(journal, err);
  564. continue;
  565. }
  566. /*
  567. * start_this_handle() uses t_outstanding_credits to determine
  568. * the free space in the log, but this counter is changed
  569. * by jbd2_journal_next_log_block() also.
  570. */
  571. atomic_dec(&commit_transaction->t_outstanding_credits);
  572. /* Bump b_count to prevent truncate from stumbling over
  573. the shadowed buffer! @@@ This can go if we ever get
  574. rid of the BJ_IO/BJ_Shadow pairing of buffers. */
  575. atomic_inc(&jh2bh(jh)->b_count);
  576. /* Make a temporary IO buffer with which to write it out
  577. (this will requeue both the metadata buffer and the
  578. temporary IO buffer). new_bh goes on BJ_IO*/
  579. set_bit(BH_JWrite, &jh2bh(jh)->b_state);
  580. /*
  581. * akpm: jbd2_journal_write_metadata_buffer() sets
  582. * new_bh->b_transaction to commit_transaction.
  583. * We need to clean this up before we release new_bh
  584. * (which is of type BJ_IO)
  585. */
  586. JBUFFER_TRACE(jh, "ph3: write metadata");
  587. flags = jbd2_journal_write_metadata_buffer(commit_transaction,
  588. jh, &new_jh, blocknr);
  589. if (flags < 0) {
  590. jbd2_journal_abort(journal, flags);
  591. continue;
  592. }
  593. set_bit(BH_JWrite, &jh2bh(new_jh)->b_state);
  594. wbuf[bufs++] = jh2bh(new_jh);
  595. /* Record the new block's tag in the current descriptor
  596. buffer */
  597. tag_flag = 0;
  598. if (flags & 1)
  599. tag_flag |= JBD2_FLAG_ESCAPE;
  600. if (!first_tag)
  601. tag_flag |= JBD2_FLAG_SAME_UUID;
  602. tag = (journal_block_tag_t *) tagp;
  603. write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
  604. tag->t_flags = cpu_to_be16(tag_flag);
  605. jbd2_block_tag_csum_set(journal, tag, jh2bh(new_jh),
  606. commit_transaction->t_tid);
  607. tagp += tag_bytes;
  608. space_left -= tag_bytes;
  609. if (first_tag) {
  610. memcpy (tagp, journal->j_uuid, 16);
  611. tagp += 16;
  612. space_left -= 16;
  613. first_tag = 0;
  614. }
  615. /* If there's no more to do, or if the descriptor is full,
  616. let the IO rip! */
  617. if (bufs == journal->j_wbufsize ||
  618. commit_transaction->t_buffers == NULL ||
  619. space_left < tag_bytes + 16 + csum_size) {
  620. jbd_debug(4, "JBD2: Submit %d IOs\n", bufs);
  621. /* Write an end-of-descriptor marker before
  622. submitting the IOs. "tag" still points to
  623. the last tag we set up. */
  624. tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
  625. jbd2_descr_block_csum_set(journal, descriptor);
  626. start_journal_io:
  627. for (i = 0; i < bufs; i++) {
  628. struct buffer_head *bh = wbuf[i];
  629. /*
  630. * Compute checksum.
  631. */
  632. if (JBD2_HAS_COMPAT_FEATURE(journal,
  633. JBD2_FEATURE_COMPAT_CHECKSUM)) {
  634. crc32_sum =
  635. jbd2_checksum_data(crc32_sum, bh);
  636. }
  637. lock_buffer(bh);
  638. clear_buffer_dirty(bh);
  639. set_buffer_uptodate(bh);
  640. bh->b_end_io = journal_end_buffer_io_sync;
  641. submit_bh(WRITE_SYNC, bh);
  642. }
  643. cond_resched();
  644. stats.run.rs_blocks_logged += bufs;
  645. /* Force a new descriptor to be generated next
  646. time round the loop. */
  647. descriptor = NULL;
  648. bufs = 0;
  649. }
  650. }
  651. err = journal_finish_inode_data_buffers(journal, commit_transaction);
  652. if (err) {
  653. printk(KERN_WARNING
  654. "JBD2: Detected IO errors while flushing file data "
  655. "on %s\n", journal->j_devname);
  656. if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
  657. jbd2_journal_abort(journal, err);
  658. err = 0;
  659. }
  660. /*
  661. * Get current oldest transaction in the log before we issue flush
  662. * to the filesystem device. After the flush we can be sure that
  663. * blocks of all older transactions are checkpointed to persistent
  664. * storage and we will be safe to update journal start in the
  665. * superblock with the numbers we get here.
  666. */
  667. update_tail =
  668. jbd2_journal_get_log_tail(journal, &first_tid, &first_block);
  669. write_lock(&journal->j_state_lock);
  670. if (update_tail) {
  671. long freed = first_block - journal->j_tail;
  672. if (first_block < journal->j_tail)
  673. freed += journal->j_last - journal->j_first;
  674. /* Update tail only if we free significant amount of space */
  675. if (freed < journal->j_maxlen / 4)
  676. update_tail = 0;
  677. }
  678. J_ASSERT(commit_transaction->t_state == T_COMMIT);
  679. commit_transaction->t_state = T_COMMIT_DFLUSH;
  680. write_unlock(&journal->j_state_lock);
  681. /*
  682. * If the journal is not located on the file system device,
  683. * then we must flush the file system device before we issue
  684. * the commit record
  685. */
  686. if (commit_transaction->t_need_data_flush &&
  687. (journal->j_fs_dev != journal->j_dev) &&
  688. (journal->j_flags & JBD2_BARRIER))
  689. blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
  690. /* Done it all: now write the commit record asynchronously. */
  691. if (JBD2_HAS_INCOMPAT_FEATURE(journal,
  692. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
  693. err = journal_submit_commit_record(journal, commit_transaction,
  694. &cbh, crc32_sum);
  695. if (err)
  696. __jbd2_journal_abort_hard(journal);
  697. }
  698. blk_finish_plug(&plug);
  699. /* Lo and behold: we have just managed to send a transaction to
  700. the log. Before we can commit it, wait for the IO so far to
  701. complete. Control buffers being written are on the
  702. transaction's t_log_list queue, and metadata buffers are on
  703. the t_iobuf_list queue.
  704. Wait for the buffers in reverse order. That way we are
  705. less likely to be woken up until all IOs have completed, and
  706. so we incur less scheduling load.
  707. */
  708. jbd_debug(3, "JBD2: commit phase 3\n");
  709. /*
  710. * akpm: these are BJ_IO, and j_list_lock is not needed.
  711. * See __journal_try_to_free_buffer.
  712. */
  713. wait_for_iobuf:
  714. while (commit_transaction->t_iobuf_list != NULL) {
  715. struct buffer_head *bh;
  716. jh = commit_transaction->t_iobuf_list->b_tprev;
  717. bh = jh2bh(jh);
  718. if (buffer_locked(bh)) {
  719. wait_on_buffer(bh);
  720. goto wait_for_iobuf;
  721. }
  722. if (cond_resched())
  723. goto wait_for_iobuf;
  724. if (unlikely(!buffer_uptodate(bh)))
  725. err = -EIO;
  726. clear_buffer_jwrite(bh);
  727. JBUFFER_TRACE(jh, "ph4: unfile after journal write");
  728. jbd2_journal_unfile_buffer(journal, jh);
  729. /*
  730. * ->t_iobuf_list should contain only dummy buffer_heads
  731. * which were created by jbd2_journal_write_metadata_buffer().
  732. */
  733. BUFFER_TRACE(bh, "dumping temporary bh");
  734. jbd2_journal_put_journal_head(jh);
  735. __brelse(bh);
  736. J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0);
  737. free_buffer_head(bh);
  738. /* We also have to unlock and free the corresponding
  739. shadowed buffer */
  740. jh = commit_transaction->t_shadow_list->b_tprev;
  741. bh = jh2bh(jh);
  742. clear_bit(BH_JWrite, &bh->b_state);
  743. J_ASSERT_BH(bh, buffer_jbddirty(bh));
  744. /* The metadata is now released for reuse, but we need
  745. to remember it against this transaction so that when
  746. we finally commit, we can do any checkpointing
  747. required. */
  748. JBUFFER_TRACE(jh, "file as BJ_Forget");
  749. jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
  750. /*
  751. * Wake up any transactions which were waiting for this IO to
  752. * complete. The barrier must be here so that changes by
  753. * jbd2_journal_file_buffer() take effect before wake_up_bit()
  754. * does the waitqueue check.
  755. */
  756. smp_mb();
  757. wake_up_bit(&bh->b_state, BH_Unshadow);
  758. JBUFFER_TRACE(jh, "brelse shadowed buffer");
  759. __brelse(bh);
  760. }
  761. J_ASSERT (commit_transaction->t_shadow_list == NULL);
  762. jbd_debug(3, "JBD2: commit phase 4\n");
  763. /* Here we wait for the revoke record and descriptor record buffers */
  764. wait_for_ctlbuf:
  765. while (commit_transaction->t_log_list != NULL) {
  766. struct buffer_head *bh;
  767. jh = commit_transaction->t_log_list->b_tprev;
  768. bh = jh2bh(jh);
  769. if (buffer_locked(bh)) {
  770. wait_on_buffer(bh);
  771. goto wait_for_ctlbuf;
  772. }
  773. if (cond_resched())
  774. goto wait_for_ctlbuf;
  775. if (unlikely(!buffer_uptodate(bh)))
  776. err = -EIO;
  777. BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile");
  778. clear_buffer_jwrite(bh);
  779. jbd2_journal_unfile_buffer(journal, jh);
  780. jbd2_journal_put_journal_head(jh);
  781. __brelse(bh); /* One for getblk */
  782. /* AKPM: bforget here */
  783. }
  784. if (err)
  785. jbd2_journal_abort(journal, err);
  786. jbd_debug(3, "JBD2: commit phase 5\n");
  787. write_lock(&journal->j_state_lock);
  788. J_ASSERT(commit_transaction->t_state == T_COMMIT_DFLUSH);
  789. commit_transaction->t_state = T_COMMIT_JFLUSH;
  790. write_unlock(&journal->j_state_lock);
  791. if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
  792. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
  793. err = journal_submit_commit_record(journal, commit_transaction,
  794. &cbh, crc32_sum);
  795. if (err)
  796. __jbd2_journal_abort_hard(journal);
  797. }
  798. if (cbh)
  799. err = journal_wait_on_commit_record(journal, cbh);
  800. if (JBD2_HAS_INCOMPAT_FEATURE(journal,
  801. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
  802. journal->j_flags & JBD2_BARRIER) {
  803. blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL);
  804. }
  805. if (err)
  806. jbd2_journal_abort(journal, err);
  807. /*
  808. * Now disk caches for filesystem device are flushed so we are safe to
  809. * erase checkpointed transactions from the log by updating journal
  810. * superblock.
  811. */
  812. if (update_tail)
  813. jbd2_update_log_tail(journal, first_tid, first_block);
  814. /* End of a transaction! Finally, we can do checkpoint
  815. processing: any buffers committed as a result of this
  816. transaction can be removed from any checkpoint list it was on
  817. before. */
  818. jbd_debug(3, "JBD2: commit phase 6\n");
  819. J_ASSERT(list_empty(&commit_transaction->t_inode_list));
  820. J_ASSERT(commit_transaction->t_buffers == NULL);
  821. J_ASSERT(commit_transaction->t_checkpoint_list == NULL);
  822. J_ASSERT(commit_transaction->t_iobuf_list == NULL);
  823. J_ASSERT(commit_transaction->t_shadow_list == NULL);
  824. J_ASSERT(commit_transaction->t_log_list == NULL);
  825. restart_loop:
  826. /*
  827. * As there are other places (journal_unmap_buffer()) adding buffers
  828. * to this list we have to be careful and hold the j_list_lock.
  829. */
  830. spin_lock(&journal->j_list_lock);
  831. while (commit_transaction->t_forget) {
  832. transaction_t *cp_transaction;
  833. struct buffer_head *bh;
  834. int try_to_free = 0;
  835. jh = commit_transaction->t_forget;
  836. spin_unlock(&journal->j_list_lock);
  837. bh = jh2bh(jh);
  838. /*
  839. * Get a reference so that bh cannot be freed before we are
  840. * done with it.
  841. */
  842. get_bh(bh);
  843. jbd_lock_bh_state(bh);
  844. J_ASSERT_JH(jh, jh->b_transaction == commit_transaction);
  845. /*
  846. * If there is undo-protected committed data against
  847. * this buffer, then we can remove it now. If it is a
  848. * buffer needing such protection, the old frozen_data
  849. * field now points to a committed version of the
  850. * buffer, so rotate that field to the new committed
  851. * data.
  852. *
  853. * Otherwise, we can just throw away the frozen data now.
  854. *
  855. * We also know that the frozen data has already fired
  856. * its triggers if they exist, so we can clear that too.
  857. */
  858. if (jh->b_committed_data) {
  859. jbd2_free(jh->b_committed_data, bh->b_size);
  860. jh->b_committed_data = NULL;
  861. if (jh->b_frozen_data) {
  862. jh->b_committed_data = jh->b_frozen_data;
  863. jh->b_frozen_data = NULL;
  864. jh->b_frozen_triggers = NULL;
  865. }
  866. } else if (jh->b_frozen_data) {
  867. jbd2_free(jh->b_frozen_data, bh->b_size);
  868. jh->b_frozen_data = NULL;
  869. jh->b_frozen_triggers = NULL;
  870. }
  871. spin_lock(&journal->j_list_lock);
  872. cp_transaction = jh->b_cp_transaction;
  873. if (cp_transaction) {
  874. JBUFFER_TRACE(jh, "remove from old cp transaction");
  875. cp_transaction->t_chp_stats.cs_dropped++;
  876. __jbd2_journal_remove_checkpoint(jh);
  877. }
  878. /* Only re-checkpoint the buffer_head if it is marked
  879. * dirty. If the buffer was added to the BJ_Forget list
  880. * by jbd2_journal_forget, it may no longer be dirty and
  881. * there's no point in keeping a checkpoint record for
  882. * it. */
  883. /*
  884. * A buffer which has been freed while still being journaled by
  885. * a previous transaction.
  886. */
  887. if (buffer_freed(bh)) {
  888. /*
  889. * If the running transaction is the one containing
  890. * "add to orphan" operation (b_next_transaction !=
  891. * NULL), we have to wait for that transaction to
  892. * commit before we can really get rid of the buffer.
  893. * So just clear b_modified to not confuse transaction
  894. * credit accounting and refile the buffer to
  895. * BJ_Forget of the running transaction. If the just
  896. * committed transaction contains "add to orphan"
  897. * operation, we can completely invalidate the buffer
  898. * now. We are rather through in that since the
  899. * buffer may be still accessible when blocksize <
  900. * pagesize and it is attached to the last partial
  901. * page.
  902. */
  903. jh->b_modified = 0;
  904. if (!jh->b_next_transaction) {
  905. clear_buffer_freed(bh);
  906. clear_buffer_jbddirty(bh);
  907. clear_buffer_mapped(bh);
  908. clear_buffer_new(bh);
  909. clear_buffer_req(bh);
  910. bh->b_bdev = NULL;
  911. }
  912. }
  913. if (buffer_jbddirty(bh)) {
  914. JBUFFER_TRACE(jh, "add to new checkpointing trans");
  915. __jbd2_journal_insert_checkpoint(jh, commit_transaction);
  916. if (is_journal_aborted(journal))
  917. clear_buffer_jbddirty(bh);
  918. } else {
  919. J_ASSERT_BH(bh, !buffer_dirty(bh));
  920. /*
  921. * The buffer on BJ_Forget list and not jbddirty means
  922. * it has been freed by this transaction and hence it
  923. * could not have been reallocated until this
  924. * transaction has committed. *BUT* it could be
  925. * reallocated once we have written all the data to
  926. * disk and before we process the buffer on BJ_Forget
  927. * list.
  928. */
  929. if (!jh->b_next_transaction)
  930. try_to_free = 1;
  931. }
  932. JBUFFER_TRACE(jh, "refile or unfile buffer");
  933. __jbd2_journal_refile_buffer(jh);
  934. jbd_unlock_bh_state(bh);
  935. if (try_to_free)
  936. release_buffer_page(bh); /* Drops bh reference */
  937. else
  938. __brelse(bh);
  939. cond_resched_lock(&journal->j_list_lock);
  940. }
  941. spin_unlock(&journal->j_list_lock);
  942. /*
  943. * This is a bit sleazy. We use j_list_lock to protect transition
  944. * of a transaction into T_FINISHED state and calling
  945. * __jbd2_journal_drop_transaction(). Otherwise we could race with
  946. * other checkpointing code processing the transaction...
  947. */
  948. write_lock(&journal->j_state_lock);
  949. spin_lock(&journal->j_list_lock);
  950. /*
  951. * Now recheck if some buffers did not get attached to the transaction
  952. * while the lock was dropped...
  953. */
  954. if (commit_transaction->t_forget) {
  955. spin_unlock(&journal->j_list_lock);
  956. write_unlock(&journal->j_state_lock);
  957. goto restart_loop;
  958. }
  959. /* Done with this transaction! */
  960. jbd_debug(3, "JBD2: commit phase 7\n");
  961. J_ASSERT(commit_transaction->t_state == T_COMMIT_JFLUSH);
  962. commit_transaction->t_start = jiffies;
  963. stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging,
  964. commit_transaction->t_start);
  965. /*
  966. * File the transaction statistics
  967. */
  968. stats.ts_tid = commit_transaction->t_tid;
  969. stats.run.rs_handle_count =
  970. atomic_read(&commit_transaction->t_handle_count);
  971. trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
  972. commit_transaction->t_tid, &stats.run);
  973. /*
  974. * Calculate overall stats
  975. */
  976. spin_lock(&journal->j_history_lock);
  977. journal->j_stats.ts_tid++;
  978. if (commit_transaction->t_requested)
  979. journal->j_stats.ts_requested++;
  980. journal->j_stats.run.rs_wait += stats.run.rs_wait;
  981. journal->j_stats.run.rs_request_delay += stats.run.rs_request_delay;
  982. journal->j_stats.run.rs_running += stats.run.rs_running;
  983. journal->j_stats.run.rs_locked += stats.run.rs_locked;
  984. journal->j_stats.run.rs_flushing += stats.run.rs_flushing;
  985. journal->j_stats.run.rs_logging += stats.run.rs_logging;
  986. journal->j_stats.run.rs_handle_count += stats.run.rs_handle_count;
  987. journal->j_stats.run.rs_blocks += stats.run.rs_blocks;
  988. journal->j_stats.run.rs_blocks_logged += stats.run.rs_blocks_logged;
  989. spin_unlock(&journal->j_history_lock);
  990. commit_transaction->t_state = T_FINISHED;
  991. J_ASSERT(commit_transaction == journal->j_committing_transaction);
  992. journal->j_commit_sequence = commit_transaction->t_tid;
  993. journal->j_committing_transaction = NULL;
  994. commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time));
  995. /*
  996. * weight the commit time higher than the average time so we don't
  997. * react too strongly to vast changes in the commit time
  998. */
  999. if (likely(journal->j_average_commit_time))
  1000. journal->j_average_commit_time = (commit_time +
  1001. journal->j_average_commit_time*3) / 4;
  1002. else
  1003. journal->j_average_commit_time = commit_time;
  1004. write_unlock(&journal->j_state_lock);
  1005. if (commit_transaction->t_checkpoint_list == NULL &&
  1006. commit_transaction->t_checkpoint_io_list == NULL) {
  1007. __jbd2_journal_drop_transaction(journal, commit_transaction);
  1008. to_free = 1;
  1009. } else {
  1010. if (journal->j_checkpoint_transactions == NULL) {
  1011. journal->j_checkpoint_transactions = commit_transaction;
  1012. commit_transaction->t_cpnext = commit_transaction;
  1013. commit_transaction->t_cpprev = commit_transaction;
  1014. } else {
  1015. commit_transaction->t_cpnext =
  1016. journal->j_checkpoint_transactions;
  1017. commit_transaction->t_cpprev =
  1018. commit_transaction->t_cpnext->t_cpprev;
  1019. commit_transaction->t_cpnext->t_cpprev =
  1020. commit_transaction;
  1021. commit_transaction->t_cpprev->t_cpnext =
  1022. commit_transaction;
  1023. }
  1024. }
  1025. spin_unlock(&journal->j_list_lock);
  1026. if (journal->j_commit_callback)
  1027. journal->j_commit_callback(journal, commit_transaction);
  1028. trace_jbd2_end_commit(journal, commit_transaction);
  1029. jbd_debug(1, "JBD2: commit %d complete, head %d\n",
  1030. journal->j_commit_sequence, journal->j_tail_sequence);
  1031. if (to_free)
  1032. jbd2_journal_free_transaction(commit_transaction);
  1033. wake_up(&journal->j_wait_done_commit);
  1034. }