commit.c 37 KB

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