commit.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  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 csum32;
  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. csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
  311. sizeof(sequence));
  312. csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
  313. bh->b_size);
  314. kunmap_atomic(addr);
  315. /* We only have space to store the lower 16 bits of the crc32c. */
  316. tag->t_checksum = cpu_to_be16(csum32);
  317. }
  318. /*
  319. * jbd2_journal_commit_transaction
  320. *
  321. * The primary function for committing a transaction to the log. This
  322. * function is called by the journal thread to begin a complete commit.
  323. */
  324. void jbd2_journal_commit_transaction(journal_t *journal)
  325. {
  326. struct transaction_stats_s stats;
  327. transaction_t *commit_transaction;
  328. struct journal_head *jh, *new_jh, *descriptor;
  329. struct buffer_head **wbuf = journal->j_wbuf;
  330. int bufs;
  331. int flags;
  332. int err;
  333. unsigned long long blocknr;
  334. ktime_t start_time;
  335. u64 commit_time;
  336. char *tagp = NULL;
  337. journal_header_t *header;
  338. journal_block_tag_t *tag = NULL;
  339. int space_left = 0;
  340. int first_tag = 0;
  341. int tag_flag;
  342. int i;
  343. int tag_bytes = journal_tag_bytes(journal);
  344. struct buffer_head *cbh = NULL; /* For transactional checksums */
  345. __u32 crc32_sum = ~0;
  346. struct blk_plug plug;
  347. /* Tail of the journal */
  348. unsigned long first_block;
  349. tid_t first_tid;
  350. int update_tail;
  351. int csum_size = 0;
  352. if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_CSUM_V2))
  353. csum_size = sizeof(struct jbd2_journal_block_tail);
  354. /*
  355. * First job: lock down the current transaction and wait for
  356. * all outstanding updates to complete.
  357. */
  358. /* Do we need to erase the effects of a prior jbd2_journal_flush? */
  359. if (journal->j_flags & JBD2_FLUSHED) {
  360. jbd_debug(3, "super block updated\n");
  361. mutex_lock(&journal->j_checkpoint_mutex);
  362. /*
  363. * We hold j_checkpoint_mutex so tail cannot change under us.
  364. * We don't need any special data guarantees for writing sb
  365. * since journal is empty and it is ok for write to be
  366. * flushed only with transaction commit.
  367. */
  368. jbd2_journal_update_sb_log_tail(journal,
  369. journal->j_tail_sequence,
  370. journal->j_tail,
  371. WRITE_SYNC);
  372. mutex_unlock(&journal->j_checkpoint_mutex);
  373. } else {
  374. jbd_debug(3, "superblock not updated\n");
  375. }
  376. J_ASSERT(journal->j_running_transaction != NULL);
  377. J_ASSERT(journal->j_committing_transaction == NULL);
  378. commit_transaction = journal->j_running_transaction;
  379. J_ASSERT(commit_transaction->t_state == T_RUNNING);
  380. trace_jbd2_start_commit(journal, commit_transaction);
  381. jbd_debug(1, "JBD2: starting commit of transaction %d\n",
  382. commit_transaction->t_tid);
  383. write_lock(&journal->j_state_lock);
  384. commit_transaction->t_state = T_LOCKED;
  385. trace_jbd2_commit_locking(journal, commit_transaction);
  386. stats.run.rs_wait = commit_transaction->t_max_wait;
  387. stats.run.rs_request_delay = 0;
  388. stats.run.rs_locked = jiffies;
  389. if (commit_transaction->t_requested)
  390. stats.run.rs_request_delay =
  391. jbd2_time_diff(commit_transaction->t_requested,
  392. stats.run.rs_locked);
  393. stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
  394. stats.run.rs_locked);
  395. spin_lock(&commit_transaction->t_handle_lock);
  396. while (atomic_read(&commit_transaction->t_updates)) {
  397. DEFINE_WAIT(wait);
  398. prepare_to_wait(&journal->j_wait_updates, &wait,
  399. TASK_UNINTERRUPTIBLE);
  400. if (atomic_read(&commit_transaction->t_updates)) {
  401. spin_unlock(&commit_transaction->t_handle_lock);
  402. write_unlock(&journal->j_state_lock);
  403. schedule();
  404. write_lock(&journal->j_state_lock);
  405. spin_lock(&commit_transaction->t_handle_lock);
  406. }
  407. finish_wait(&journal->j_wait_updates, &wait);
  408. }
  409. spin_unlock(&commit_transaction->t_handle_lock);
  410. J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
  411. journal->j_max_transaction_buffers);
  412. /*
  413. * First thing we are allowed to do is to discard any remaining
  414. * BJ_Reserved buffers. Note, it is _not_ permissible to assume
  415. * that there are no such buffers: if a large filesystem
  416. * operation like a truncate needs to split itself over multiple
  417. * transactions, then it may try to do a jbd2_journal_restart() while
  418. * there are still BJ_Reserved buffers outstanding. These must
  419. * be released cleanly from the current transaction.
  420. *
  421. * In this case, the filesystem must still reserve write access
  422. * again before modifying the buffer in the new transaction, but
  423. * we do not require it to remember exactly which old buffers it
  424. * has reserved. This is consistent with the existing behaviour
  425. * that multiple jbd2_journal_get_write_access() calls to the same
  426. * buffer are perfectly permissible.
  427. */
  428. while (commit_transaction->t_reserved_list) {
  429. jh = commit_transaction->t_reserved_list;
  430. JBUFFER_TRACE(jh, "reserved, unused: refile");
  431. /*
  432. * A jbd2_journal_get_undo_access()+jbd2_journal_release_buffer() may
  433. * leave undo-committed data.
  434. */
  435. if (jh->b_committed_data) {
  436. struct buffer_head *bh = jh2bh(jh);
  437. jbd_lock_bh_state(bh);
  438. jbd2_free(jh->b_committed_data, bh->b_size);
  439. jh->b_committed_data = NULL;
  440. jbd_unlock_bh_state(bh);
  441. }
  442. jbd2_journal_refile_buffer(journal, jh);
  443. }
  444. /*
  445. * Now try to drop any written-back buffers from the journal's
  446. * checkpoint lists. We do this *before* commit because it potentially
  447. * frees some memory
  448. */
  449. spin_lock(&journal->j_list_lock);
  450. __jbd2_journal_clean_checkpoint_list(journal);
  451. spin_unlock(&journal->j_list_lock);
  452. jbd_debug(3, "JBD2: commit phase 1\n");
  453. /*
  454. * Clear revoked flag to reflect there is no revoked buffers
  455. * in the next transaction which is going to be started.
  456. */
  457. jbd2_clear_buffer_revoked_flags(journal);
  458. /*
  459. * Switch to a new revoke table.
  460. */
  461. jbd2_journal_switch_revoke_table(journal);
  462. trace_jbd2_commit_flushing(journal, commit_transaction);
  463. stats.run.rs_flushing = jiffies;
  464. stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked,
  465. stats.run.rs_flushing);
  466. commit_transaction->t_state = T_FLUSH;
  467. journal->j_committing_transaction = commit_transaction;
  468. journal->j_running_transaction = NULL;
  469. start_time = ktime_get();
  470. commit_transaction->t_log_start = journal->j_head;
  471. wake_up(&journal->j_wait_transaction_locked);
  472. write_unlock(&journal->j_state_lock);
  473. jbd_debug(3, "JBD2: commit phase 2\n");
  474. /*
  475. * Now start flushing things to disk, in the order they appear
  476. * on the transaction lists. Data blocks go first.
  477. */
  478. err = journal_submit_data_buffers(journal, commit_transaction);
  479. if (err)
  480. jbd2_journal_abort(journal, err);
  481. blk_start_plug(&plug);
  482. jbd2_journal_write_revoke_records(journal, commit_transaction,
  483. WRITE_SYNC);
  484. blk_finish_plug(&plug);
  485. jbd_debug(3, "JBD2: commit phase 2\n");
  486. /*
  487. * Way to go: we have now written out all of the data for a
  488. * transaction! Now comes the tricky part: we need to write out
  489. * metadata. Loop over the transaction's entire buffer list:
  490. */
  491. write_lock(&journal->j_state_lock);
  492. commit_transaction->t_state = T_COMMIT;
  493. write_unlock(&journal->j_state_lock);
  494. trace_jbd2_commit_logging(journal, commit_transaction);
  495. stats.run.rs_logging = jiffies;
  496. stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing,
  497. stats.run.rs_logging);
  498. stats.run.rs_blocks =
  499. atomic_read(&commit_transaction->t_outstanding_credits);
  500. stats.run.rs_blocks_logged = 0;
  501. J_ASSERT(commit_transaction->t_nr_buffers <=
  502. atomic_read(&commit_transaction->t_outstanding_credits));
  503. err = 0;
  504. descriptor = NULL;
  505. bufs = 0;
  506. blk_start_plug(&plug);
  507. while (commit_transaction->t_buffers) {
  508. /* Find the next buffer to be journaled... */
  509. jh = commit_transaction->t_buffers;
  510. /* If we're in abort mode, we just un-journal the buffer and
  511. release it. */
  512. if (is_journal_aborted(journal)) {
  513. clear_buffer_jbddirty(jh2bh(jh));
  514. JBUFFER_TRACE(jh, "journal is aborting: refile");
  515. jbd2_buffer_abort_trigger(jh,
  516. jh->b_frozen_data ?
  517. jh->b_frozen_triggers :
  518. jh->b_triggers);
  519. jbd2_journal_refile_buffer(journal, jh);
  520. /* If that was the last one, we need to clean up
  521. * any descriptor buffers which may have been
  522. * already allocated, even if we are now
  523. * aborting. */
  524. if (!commit_transaction->t_buffers)
  525. goto start_journal_io;
  526. continue;
  527. }
  528. /* Make sure we have a descriptor block in which to
  529. record the metadata buffer. */
  530. if (!descriptor) {
  531. struct buffer_head *bh;
  532. J_ASSERT (bufs == 0);
  533. jbd_debug(4, "JBD2: get descriptor\n");
  534. descriptor = jbd2_journal_get_descriptor_buffer(journal);
  535. if (!descriptor) {
  536. jbd2_journal_abort(journal, -EIO);
  537. continue;
  538. }
  539. bh = jh2bh(descriptor);
  540. jbd_debug(4, "JBD2: got buffer %llu (%p)\n",
  541. (unsigned long long)bh->b_blocknr, bh->b_data);
  542. header = (journal_header_t *)&bh->b_data[0];
  543. header->h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
  544. header->h_blocktype = cpu_to_be32(JBD2_DESCRIPTOR_BLOCK);
  545. header->h_sequence = cpu_to_be32(commit_transaction->t_tid);
  546. tagp = &bh->b_data[sizeof(journal_header_t)];
  547. space_left = bh->b_size - sizeof(journal_header_t);
  548. first_tag = 1;
  549. set_buffer_jwrite(bh);
  550. set_buffer_dirty(bh);
  551. wbuf[bufs++] = bh;
  552. /* Record it so that we can wait for IO
  553. completion later */
  554. BUFFER_TRACE(bh, "ph3: file as descriptor");
  555. jbd2_journal_file_buffer(descriptor, commit_transaction,
  556. BJ_LogCtl);
  557. }
  558. /* Where is the buffer to be written? */
  559. err = jbd2_journal_next_log_block(journal, &blocknr);
  560. /* If the block mapping failed, just abandon the buffer
  561. and repeat this loop: we'll fall into the
  562. refile-on-abort condition above. */
  563. if (err) {
  564. jbd2_journal_abort(journal, err);
  565. continue;
  566. }
  567. /*
  568. * start_this_handle() uses t_outstanding_credits to determine
  569. * the free space in the log, but this counter is changed
  570. * by jbd2_journal_next_log_block() also.
  571. */
  572. atomic_dec(&commit_transaction->t_outstanding_credits);
  573. /* Bump b_count to prevent truncate from stumbling over
  574. the shadowed buffer! @@@ This can go if we ever get
  575. rid of the BJ_IO/BJ_Shadow pairing of buffers. */
  576. atomic_inc(&jh2bh(jh)->b_count);
  577. /* Make a temporary IO buffer with which to write it out
  578. (this will requeue both the metadata buffer and the
  579. temporary IO buffer). new_bh goes on BJ_IO*/
  580. set_bit(BH_JWrite, &jh2bh(jh)->b_state);
  581. /*
  582. * akpm: jbd2_journal_write_metadata_buffer() sets
  583. * new_bh->b_transaction to commit_transaction.
  584. * We need to clean this up before we release new_bh
  585. * (which is of type BJ_IO)
  586. */
  587. JBUFFER_TRACE(jh, "ph3: write metadata");
  588. flags = jbd2_journal_write_metadata_buffer(commit_transaction,
  589. jh, &new_jh, blocknr);
  590. if (flags < 0) {
  591. jbd2_journal_abort(journal, flags);
  592. continue;
  593. }
  594. set_bit(BH_JWrite, &jh2bh(new_jh)->b_state);
  595. wbuf[bufs++] = jh2bh(new_jh);
  596. /* Record the new block's tag in the current descriptor
  597. buffer */
  598. tag_flag = 0;
  599. if (flags & 1)
  600. tag_flag |= JBD2_FLAG_ESCAPE;
  601. if (!first_tag)
  602. tag_flag |= JBD2_FLAG_SAME_UUID;
  603. tag = (journal_block_tag_t *) tagp;
  604. write_tag_block(tag_bytes, tag, jh2bh(jh)->b_blocknr);
  605. tag->t_flags = cpu_to_be16(tag_flag);
  606. jbd2_block_tag_csum_set(journal, tag, jh2bh(new_jh),
  607. commit_transaction->t_tid);
  608. tagp += tag_bytes;
  609. space_left -= tag_bytes;
  610. if (first_tag) {
  611. memcpy (tagp, journal->j_uuid, 16);
  612. tagp += 16;
  613. space_left -= 16;
  614. first_tag = 0;
  615. }
  616. /* If there's no more to do, or if the descriptor is full,
  617. let the IO rip! */
  618. if (bufs == journal->j_wbufsize ||
  619. commit_transaction->t_buffers == NULL ||
  620. space_left < tag_bytes + 16 + csum_size) {
  621. jbd_debug(4, "JBD2: Submit %d IOs\n", bufs);
  622. /* Write an end-of-descriptor marker before
  623. submitting the IOs. "tag" still points to
  624. the last tag we set up. */
  625. tag->t_flags |= cpu_to_be16(JBD2_FLAG_LAST_TAG);
  626. jbd2_descr_block_csum_set(journal, descriptor);
  627. start_journal_io:
  628. for (i = 0; i < bufs; i++) {
  629. struct buffer_head *bh = wbuf[i];
  630. /*
  631. * Compute checksum.
  632. */
  633. if (JBD2_HAS_COMPAT_FEATURE(journal,
  634. JBD2_FEATURE_COMPAT_CHECKSUM)) {
  635. crc32_sum =
  636. jbd2_checksum_data(crc32_sum, bh);
  637. }
  638. lock_buffer(bh);
  639. clear_buffer_dirty(bh);
  640. set_buffer_uptodate(bh);
  641. bh->b_end_io = journal_end_buffer_io_sync;
  642. submit_bh(WRITE_SYNC, bh);
  643. }
  644. cond_resched();
  645. stats.run.rs_blocks_logged += bufs;
  646. /* Force a new descriptor to be generated next
  647. time round the loop. */
  648. descriptor = NULL;
  649. bufs = 0;
  650. }
  651. }
  652. err = journal_finish_inode_data_buffers(journal, commit_transaction);
  653. if (err) {
  654. printk(KERN_WARNING
  655. "JBD2: Detected IO errors while flushing file data "
  656. "on %s\n", journal->j_devname);
  657. if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
  658. jbd2_journal_abort(journal, err);
  659. err = 0;
  660. }
  661. /*
  662. * Get current oldest transaction in the log before we issue flush
  663. * to the filesystem device. After the flush we can be sure that
  664. * blocks of all older transactions are checkpointed to persistent
  665. * storage and we will be safe to update journal start in the
  666. * superblock with the numbers we get here.
  667. */
  668. update_tail =
  669. jbd2_journal_get_log_tail(journal, &first_tid, &first_block);
  670. write_lock(&journal->j_state_lock);
  671. if (update_tail) {
  672. long freed = first_block - journal->j_tail;
  673. if (first_block < journal->j_tail)
  674. freed += journal->j_last - journal->j_first;
  675. /* Update tail only if we free significant amount of space */
  676. if (freed < journal->j_maxlen / 4)
  677. update_tail = 0;
  678. }
  679. J_ASSERT(commit_transaction->t_state == T_COMMIT);
  680. commit_transaction->t_state = T_COMMIT_DFLUSH;
  681. write_unlock(&journal->j_state_lock);
  682. /*
  683. * If the journal is not located on the file system device,
  684. * then we must flush the file system device before we issue
  685. * the commit record
  686. */
  687. if (commit_transaction->t_need_data_flush &&
  688. (journal->j_fs_dev != journal->j_dev) &&
  689. (journal->j_flags & JBD2_BARRIER))
  690. blkdev_issue_flush(journal->j_fs_dev, GFP_NOFS, NULL);
  691. /* Done it all: now write the commit record asynchronously. */
  692. if (JBD2_HAS_INCOMPAT_FEATURE(journal,
  693. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
  694. err = journal_submit_commit_record(journal, commit_transaction,
  695. &cbh, crc32_sum);
  696. if (err)
  697. __jbd2_journal_abort_hard(journal);
  698. }
  699. blk_finish_plug(&plug);
  700. /* Lo and behold: we have just managed to send a transaction to
  701. the log. Before we can commit it, wait for the IO so far to
  702. complete. Control buffers being written are on the
  703. transaction's t_log_list queue, and metadata buffers are on
  704. the t_iobuf_list queue.
  705. Wait for the buffers in reverse order. That way we are
  706. less likely to be woken up until all IOs have completed, and
  707. so we incur less scheduling load.
  708. */
  709. jbd_debug(3, "JBD2: commit phase 3\n");
  710. /*
  711. * akpm: these are BJ_IO, and j_list_lock is not needed.
  712. * See __journal_try_to_free_buffer.
  713. */
  714. wait_for_iobuf:
  715. while (commit_transaction->t_iobuf_list != NULL) {
  716. struct buffer_head *bh;
  717. jh = commit_transaction->t_iobuf_list->b_tprev;
  718. bh = jh2bh(jh);
  719. if (buffer_locked(bh)) {
  720. wait_on_buffer(bh);
  721. goto wait_for_iobuf;
  722. }
  723. if (cond_resched())
  724. goto wait_for_iobuf;
  725. if (unlikely(!buffer_uptodate(bh)))
  726. err = -EIO;
  727. clear_buffer_jwrite(bh);
  728. JBUFFER_TRACE(jh, "ph4: unfile after journal write");
  729. jbd2_journal_unfile_buffer(journal, jh);
  730. /*
  731. * ->t_iobuf_list should contain only dummy buffer_heads
  732. * which were created by jbd2_journal_write_metadata_buffer().
  733. */
  734. BUFFER_TRACE(bh, "dumping temporary bh");
  735. jbd2_journal_put_journal_head(jh);
  736. __brelse(bh);
  737. J_ASSERT_BH(bh, atomic_read(&bh->b_count) == 0);
  738. free_buffer_head(bh);
  739. /* We also have to unlock and free the corresponding
  740. shadowed buffer */
  741. jh = commit_transaction->t_shadow_list->b_tprev;
  742. bh = jh2bh(jh);
  743. clear_bit(BH_JWrite, &bh->b_state);
  744. J_ASSERT_BH(bh, buffer_jbddirty(bh));
  745. /* The metadata is now released for reuse, but we need
  746. to remember it against this transaction so that when
  747. we finally commit, we can do any checkpointing
  748. required. */
  749. JBUFFER_TRACE(jh, "file as BJ_Forget");
  750. jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
  751. /*
  752. * Wake up any transactions which were waiting for this IO to
  753. * complete. The barrier must be here so that changes by
  754. * jbd2_journal_file_buffer() take effect before wake_up_bit()
  755. * does the waitqueue check.
  756. */
  757. smp_mb();
  758. wake_up_bit(&bh->b_state, BH_Unshadow);
  759. JBUFFER_TRACE(jh, "brelse shadowed buffer");
  760. __brelse(bh);
  761. }
  762. J_ASSERT (commit_transaction->t_shadow_list == NULL);
  763. jbd_debug(3, "JBD2: commit phase 4\n");
  764. /* Here we wait for the revoke record and descriptor record buffers */
  765. wait_for_ctlbuf:
  766. while (commit_transaction->t_log_list != NULL) {
  767. struct buffer_head *bh;
  768. jh = commit_transaction->t_log_list->b_tprev;
  769. bh = jh2bh(jh);
  770. if (buffer_locked(bh)) {
  771. wait_on_buffer(bh);
  772. goto wait_for_ctlbuf;
  773. }
  774. if (cond_resched())
  775. goto wait_for_ctlbuf;
  776. if (unlikely(!buffer_uptodate(bh)))
  777. err = -EIO;
  778. BUFFER_TRACE(bh, "ph5: control buffer writeout done: unfile");
  779. clear_buffer_jwrite(bh);
  780. jbd2_journal_unfile_buffer(journal, jh);
  781. jbd2_journal_put_journal_head(jh);
  782. __brelse(bh); /* One for getblk */
  783. /* AKPM: bforget here */
  784. }
  785. if (err)
  786. jbd2_journal_abort(journal, err);
  787. jbd_debug(3, "JBD2: commit phase 5\n");
  788. write_lock(&journal->j_state_lock);
  789. J_ASSERT(commit_transaction->t_state == T_COMMIT_DFLUSH);
  790. commit_transaction->t_state = T_COMMIT_JFLUSH;
  791. write_unlock(&journal->j_state_lock);
  792. if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
  793. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
  794. err = journal_submit_commit_record(journal, commit_transaction,
  795. &cbh, crc32_sum);
  796. if (err)
  797. __jbd2_journal_abort_hard(journal);
  798. }
  799. if (cbh)
  800. err = journal_wait_on_commit_record(journal, cbh);
  801. if (JBD2_HAS_INCOMPAT_FEATURE(journal,
  802. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
  803. journal->j_flags & JBD2_BARRIER) {
  804. blkdev_issue_flush(journal->j_dev, GFP_NOFS, NULL);
  805. }
  806. if (err)
  807. jbd2_journal_abort(journal, err);
  808. /*
  809. * Now disk caches for filesystem device are flushed so we are safe to
  810. * erase checkpointed transactions from the log by updating journal
  811. * superblock.
  812. */
  813. if (update_tail)
  814. jbd2_update_log_tail(journal, first_tid, first_block);
  815. /* End of a transaction! Finally, we can do checkpoint
  816. processing: any buffers committed as a result of this
  817. transaction can be removed from any checkpoint list it was on
  818. before. */
  819. jbd_debug(3, "JBD2: commit phase 6\n");
  820. J_ASSERT(list_empty(&commit_transaction->t_inode_list));
  821. J_ASSERT(commit_transaction->t_buffers == NULL);
  822. J_ASSERT(commit_transaction->t_checkpoint_list == NULL);
  823. J_ASSERT(commit_transaction->t_iobuf_list == NULL);
  824. J_ASSERT(commit_transaction->t_shadow_list == NULL);
  825. J_ASSERT(commit_transaction->t_log_list == NULL);
  826. restart_loop:
  827. /*
  828. * As there are other places (journal_unmap_buffer()) adding buffers
  829. * to this list we have to be careful and hold the j_list_lock.
  830. */
  831. spin_lock(&journal->j_list_lock);
  832. while (commit_transaction->t_forget) {
  833. transaction_t *cp_transaction;
  834. struct buffer_head *bh;
  835. int try_to_free = 0;
  836. jh = commit_transaction->t_forget;
  837. spin_unlock(&journal->j_list_lock);
  838. bh = jh2bh(jh);
  839. /*
  840. * Get a reference so that bh cannot be freed before we are
  841. * done with it.
  842. */
  843. get_bh(bh);
  844. jbd_lock_bh_state(bh);
  845. J_ASSERT_JH(jh, jh->b_transaction == commit_transaction);
  846. /*
  847. * If there is undo-protected committed data against
  848. * this buffer, then we can remove it now. If it is a
  849. * buffer needing such protection, the old frozen_data
  850. * field now points to a committed version of the
  851. * buffer, so rotate that field to the new committed
  852. * data.
  853. *
  854. * Otherwise, we can just throw away the frozen data now.
  855. *
  856. * We also know that the frozen data has already fired
  857. * its triggers if they exist, so we can clear that too.
  858. */
  859. if (jh->b_committed_data) {
  860. jbd2_free(jh->b_committed_data, bh->b_size);
  861. jh->b_committed_data = NULL;
  862. if (jh->b_frozen_data) {
  863. jh->b_committed_data = jh->b_frozen_data;
  864. jh->b_frozen_data = NULL;
  865. jh->b_frozen_triggers = NULL;
  866. }
  867. } else if (jh->b_frozen_data) {
  868. jbd2_free(jh->b_frozen_data, bh->b_size);
  869. jh->b_frozen_data = NULL;
  870. jh->b_frozen_triggers = NULL;
  871. }
  872. spin_lock(&journal->j_list_lock);
  873. cp_transaction = jh->b_cp_transaction;
  874. if (cp_transaction) {
  875. JBUFFER_TRACE(jh, "remove from old cp transaction");
  876. cp_transaction->t_chp_stats.cs_dropped++;
  877. __jbd2_journal_remove_checkpoint(jh);
  878. }
  879. /* Only re-checkpoint the buffer_head if it is marked
  880. * dirty. If the buffer was added to the BJ_Forget list
  881. * by jbd2_journal_forget, it may no longer be dirty and
  882. * there's no point in keeping a checkpoint record for
  883. * it. */
  884. /*
  885. * A buffer which has been freed while still being journaled by
  886. * a previous transaction.
  887. */
  888. if (buffer_freed(bh)) {
  889. /*
  890. * If the running transaction is the one containing
  891. * "add to orphan" operation (b_next_transaction !=
  892. * NULL), we have to wait for that transaction to
  893. * commit before we can really get rid of the buffer.
  894. * So just clear b_modified to not confuse transaction
  895. * credit accounting and refile the buffer to
  896. * BJ_Forget of the running transaction. If the just
  897. * committed transaction contains "add to orphan"
  898. * operation, we can completely invalidate the buffer
  899. * now. We are rather through in that since the
  900. * buffer may be still accessible when blocksize <
  901. * pagesize and it is attached to the last partial
  902. * page.
  903. */
  904. jh->b_modified = 0;
  905. if (!jh->b_next_transaction) {
  906. clear_buffer_freed(bh);
  907. clear_buffer_jbddirty(bh);
  908. clear_buffer_mapped(bh);
  909. clear_buffer_new(bh);
  910. clear_buffer_req(bh);
  911. bh->b_bdev = NULL;
  912. }
  913. }
  914. if (buffer_jbddirty(bh)) {
  915. JBUFFER_TRACE(jh, "add to new checkpointing trans");
  916. __jbd2_journal_insert_checkpoint(jh, commit_transaction);
  917. if (is_journal_aborted(journal))
  918. clear_buffer_jbddirty(bh);
  919. } else {
  920. J_ASSERT_BH(bh, !buffer_dirty(bh));
  921. /*
  922. * The buffer on BJ_Forget list and not jbddirty means
  923. * it has been freed by this transaction and hence it
  924. * could not have been reallocated until this
  925. * transaction has committed. *BUT* it could be
  926. * reallocated once we have written all the data to
  927. * disk and before we process the buffer on BJ_Forget
  928. * list.
  929. */
  930. if (!jh->b_next_transaction)
  931. try_to_free = 1;
  932. }
  933. JBUFFER_TRACE(jh, "refile or unfile buffer");
  934. __jbd2_journal_refile_buffer(jh);
  935. jbd_unlock_bh_state(bh);
  936. if (try_to_free)
  937. release_buffer_page(bh); /* Drops bh reference */
  938. else
  939. __brelse(bh);
  940. cond_resched_lock(&journal->j_list_lock);
  941. }
  942. spin_unlock(&journal->j_list_lock);
  943. /*
  944. * This is a bit sleazy. We use j_list_lock to protect transition
  945. * of a transaction into T_FINISHED state and calling
  946. * __jbd2_journal_drop_transaction(). Otherwise we could race with
  947. * other checkpointing code processing the transaction...
  948. */
  949. write_lock(&journal->j_state_lock);
  950. spin_lock(&journal->j_list_lock);
  951. /*
  952. * Now recheck if some buffers did not get attached to the transaction
  953. * while the lock was dropped...
  954. */
  955. if (commit_transaction->t_forget) {
  956. spin_unlock(&journal->j_list_lock);
  957. write_unlock(&journal->j_state_lock);
  958. goto restart_loop;
  959. }
  960. /* Done with this transaction! */
  961. jbd_debug(3, "JBD2: commit phase 7\n");
  962. J_ASSERT(commit_transaction->t_state == T_COMMIT_JFLUSH);
  963. commit_transaction->t_start = jiffies;
  964. stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging,
  965. commit_transaction->t_start);
  966. /*
  967. * File the transaction statistics
  968. */
  969. stats.ts_tid = commit_transaction->t_tid;
  970. stats.run.rs_handle_count =
  971. atomic_read(&commit_transaction->t_handle_count);
  972. trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
  973. commit_transaction->t_tid, &stats.run);
  974. /*
  975. * Calculate overall stats
  976. */
  977. spin_lock(&journal->j_history_lock);
  978. journal->j_stats.ts_tid++;
  979. if (commit_transaction->t_requested)
  980. journal->j_stats.ts_requested++;
  981. journal->j_stats.run.rs_wait += stats.run.rs_wait;
  982. journal->j_stats.run.rs_request_delay += stats.run.rs_request_delay;
  983. journal->j_stats.run.rs_running += stats.run.rs_running;
  984. journal->j_stats.run.rs_locked += stats.run.rs_locked;
  985. journal->j_stats.run.rs_flushing += stats.run.rs_flushing;
  986. journal->j_stats.run.rs_logging += stats.run.rs_logging;
  987. journal->j_stats.run.rs_handle_count += stats.run.rs_handle_count;
  988. journal->j_stats.run.rs_blocks += stats.run.rs_blocks;
  989. journal->j_stats.run.rs_blocks_logged += stats.run.rs_blocks_logged;
  990. spin_unlock(&journal->j_history_lock);
  991. commit_transaction->t_state = T_COMMIT_CALLBACK;
  992. J_ASSERT(commit_transaction == journal->j_committing_transaction);
  993. journal->j_commit_sequence = commit_transaction->t_tid;
  994. journal->j_committing_transaction = NULL;
  995. commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time));
  996. /*
  997. * weight the commit time higher than the average time so we don't
  998. * react too strongly to vast changes in the commit time
  999. */
  1000. if (likely(journal->j_average_commit_time))
  1001. journal->j_average_commit_time = (commit_time +
  1002. journal->j_average_commit_time*3) / 4;
  1003. else
  1004. journal->j_average_commit_time = commit_time;
  1005. write_unlock(&journal->j_state_lock);
  1006. if (journal->j_checkpoint_transactions == NULL) {
  1007. journal->j_checkpoint_transactions = commit_transaction;
  1008. commit_transaction->t_cpnext = commit_transaction;
  1009. commit_transaction->t_cpprev = commit_transaction;
  1010. } else {
  1011. commit_transaction->t_cpnext =
  1012. journal->j_checkpoint_transactions;
  1013. commit_transaction->t_cpprev =
  1014. commit_transaction->t_cpnext->t_cpprev;
  1015. commit_transaction->t_cpnext->t_cpprev =
  1016. commit_transaction;
  1017. commit_transaction->t_cpprev->t_cpnext =
  1018. commit_transaction;
  1019. }
  1020. spin_unlock(&journal->j_list_lock);
  1021. /* Drop all spin_locks because commit_callback may be block.
  1022. * __journal_remove_checkpoint() can not destroy transaction
  1023. * under us because it is not marked as T_FINISHED yet */
  1024. if (journal->j_commit_callback)
  1025. journal->j_commit_callback(journal, commit_transaction);
  1026. trace_jbd2_end_commit(journal, commit_transaction);
  1027. jbd_debug(1, "JBD2: commit %d complete, head %d\n",
  1028. journal->j_commit_sequence, journal->j_tail_sequence);
  1029. write_lock(&journal->j_state_lock);
  1030. spin_lock(&journal->j_list_lock);
  1031. commit_transaction->t_state = T_FINISHED;
  1032. /* Recheck checkpoint lists after j_list_lock was dropped */
  1033. if (commit_transaction->t_checkpoint_list == NULL &&
  1034. commit_transaction->t_checkpoint_io_list == NULL) {
  1035. __jbd2_journal_drop_transaction(journal, commit_transaction);
  1036. jbd2_journal_free_transaction(commit_transaction);
  1037. }
  1038. spin_unlock(&journal->j_list_lock);
  1039. write_unlock(&journal->j_state_lock);
  1040. wake_up(&journal->j_wait_done_commit);
  1041. }