aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2/commit.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /fs/jbd2/commit.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'fs/jbd2/commit.c')
-rw-r--r--fs/jbd2/commit.c169
1 files changed, 75 insertions, 94 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 7c068c189d80..eef6979821a4 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -26,7 +26,9 @@
26#include <linux/backing-dev.h> 26#include <linux/backing-dev.h>
27#include <linux/bio.h> 27#include <linux/bio.h>
28#include <linux/blkdev.h> 28#include <linux/blkdev.h>
29#include <linux/bitops.h>
29#include <trace/events/jbd2.h> 30#include <trace/events/jbd2.h>
31#include <asm/system.h>
30 32
31/* 33/*
32 * Default IO end handler for temporary BJ_IO buffer_heads. 34 * Default IO end handler for temporary BJ_IO buffer_heads.
@@ -103,6 +105,8 @@ static int journal_submit_commit_record(journal_t *journal,
103 int ret; 105 int ret;
104 struct timespec now = current_kernel_time(); 106 struct timespec now = current_kernel_time();
105 107
108 *cbh = NULL;
109
106 if (is_journal_aborted(journal)) 110 if (is_journal_aborted(journal))
107 return 0; 111 return 0;
108 112
@@ -134,25 +138,11 @@ static int journal_submit_commit_record(journal_t *journal,
134 138
135 if (journal->j_flags & JBD2_BARRIER && 139 if (journal->j_flags & JBD2_BARRIER &&
136 !JBD2_HAS_INCOMPAT_FEATURE(journal, 140 !JBD2_HAS_INCOMPAT_FEATURE(journal,
137 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { 141 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT))
138 ret = submit_bh(WRITE_SYNC_PLUG | WRITE_BARRIER, bh); 142 ret = submit_bh(WRITE_SYNC | WRITE_FLUSH_FUA, bh);
139 if (ret == -EOPNOTSUPP) { 143 else
140 printk(KERN_WARNING 144 ret = submit_bh(WRITE_SYNC, bh);
141 "JBD2: Disabling barriers on %s, "
142 "not supported by device\n", journal->j_devname);
143 write_lock(&journal->j_state_lock);
144 journal->j_flags &= ~JBD2_BARRIER;
145 write_unlock(&journal->j_state_lock);
146 145
147 /* And try again, without the barrier */
148 lock_buffer(bh);
149 set_buffer_uptodate(bh);
150 clear_buffer_dirty(bh);
151 ret = submit_bh(WRITE_SYNC_PLUG, bh);
152 }
153 } else {
154 ret = submit_bh(WRITE_SYNC_PLUG, bh);
155 }
156 *cbh = bh; 146 *cbh = bh;
157 return ret; 147 return ret;
158} 148}
@@ -166,29 +156,8 @@ static int journal_wait_on_commit_record(journal_t *journal,
166{ 156{
167 int ret = 0; 157 int ret = 0;
168 158
169retry:
170 clear_buffer_dirty(bh); 159 clear_buffer_dirty(bh);
171 wait_on_buffer(bh); 160 wait_on_buffer(bh);
172 if (buffer_eopnotsupp(bh) && (journal->j_flags & JBD2_BARRIER)) {
173 printk(KERN_WARNING
174 "JBD2: %s: disabling barries on %s - not supported "
175 "by device\n", __func__, journal->j_devname);
176 write_lock(&journal->j_state_lock);
177 journal->j_flags &= ~JBD2_BARRIER;
178 write_unlock(&journal->j_state_lock);
179
180 lock_buffer(bh);
181 clear_buffer_dirty(bh);
182 set_buffer_uptodate(bh);
183 bh->b_end_io = journal_end_buffer_io_sync;
184
185 ret = submit_bh(WRITE_SYNC_PLUG, bh);
186 if (ret) {
187 unlock_buffer(bh);
188 return ret;
189 }
190 goto retry;
191 }
192 161
193 if (unlikely(!buffer_uptodate(bh))) 162 if (unlikely(!buffer_uptodate(bh)))
194 ret = -EIO; 163 ret = -EIO;
@@ -236,7 +205,7 @@ static int journal_submit_data_buffers(journal_t *journal,
236 spin_lock(&journal->j_list_lock); 205 spin_lock(&journal->j_list_lock);
237 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { 206 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
238 mapping = jinode->i_vfs_inode->i_mapping; 207 mapping = jinode->i_vfs_inode->i_mapping;
239 jinode->i_flags |= JI_COMMIT_RUNNING; 208 set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
240 spin_unlock(&journal->j_list_lock); 209 spin_unlock(&journal->j_list_lock);
241 /* 210 /*
242 * submit the inode data buffers. We use writepage 211 * submit the inode data buffers. We use writepage
@@ -250,8 +219,8 @@ static int journal_submit_data_buffers(journal_t *journal,
250 ret = err; 219 ret = err;
251 spin_lock(&journal->j_list_lock); 220 spin_lock(&journal->j_list_lock);
252 J_ASSERT(jinode->i_transaction == commit_transaction); 221 J_ASSERT(jinode->i_transaction == commit_transaction);
253 commit_transaction->t_flushed_data_blocks = 1; 222 clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
254 jinode->i_flags &= ~JI_COMMIT_RUNNING; 223 smp_mb__after_clear_bit();
255 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); 224 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
256 } 225 }
257 spin_unlock(&journal->j_list_lock); 226 spin_unlock(&journal->j_list_lock);
@@ -272,7 +241,7 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
272 /* For locking, see the comment in journal_submit_data_buffers() */ 241 /* For locking, see the comment in journal_submit_data_buffers() */
273 spin_lock(&journal->j_list_lock); 242 spin_lock(&journal->j_list_lock);
274 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { 243 list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
275 jinode->i_flags |= JI_COMMIT_RUNNING; 244 set_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
276 spin_unlock(&journal->j_list_lock); 245 spin_unlock(&journal->j_list_lock);
277 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping); 246 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
278 if (err) { 247 if (err) {
@@ -288,7 +257,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
288 ret = err; 257 ret = err;
289 } 258 }
290 spin_lock(&journal->j_list_lock); 259 spin_lock(&journal->j_list_lock);
291 jinode->i_flags &= ~JI_COMMIT_RUNNING; 260 clear_bit(__JI_COMMIT_RUNNING, &jinode->i_flags);
261 smp_mb__after_clear_bit();
292 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); 262 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
293 } 263 }
294 264
@@ -360,19 +330,13 @@ void jbd2_journal_commit_transaction(journal_t *journal)
360 int tag_bytes = journal_tag_bytes(journal); 330 int tag_bytes = journal_tag_bytes(journal);
361 struct buffer_head *cbh = NULL; /* For transactional checksums */ 331 struct buffer_head *cbh = NULL; /* For transactional checksums */
362 __u32 crc32_sum = ~0; 332 __u32 crc32_sum = ~0;
363 int write_op = WRITE; 333 struct blk_plug plug;
364 334
365 /* 335 /*
366 * First job: lock down the current transaction and wait for 336 * First job: lock down the current transaction and wait for
367 * all outstanding updates to complete. 337 * all outstanding updates to complete.
368 */ 338 */
369 339
370#ifdef COMMIT_STATS
371 spin_lock(&journal->j_list_lock);
372 summarise_journal_usage(journal);
373 spin_unlock(&journal->j_list_lock);
374#endif
375
376 /* Do we need to erase the effects of a prior jbd2_journal_flush? */ 340 /* Do we need to erase the effects of a prior jbd2_journal_flush? */
377 if (journal->j_flags & JBD2_FLUSHED) { 341 if (journal->j_flags & JBD2_FLUSHED) {
378 jbd_debug(3, "super block updated\n"); 342 jbd_debug(3, "super block updated\n");
@@ -394,13 +358,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
394 write_lock(&journal->j_state_lock); 358 write_lock(&journal->j_state_lock);
395 commit_transaction->t_state = T_LOCKED; 359 commit_transaction->t_state = T_LOCKED;
396 360
397 /*
398 * Use plugged writes here, since we want to submit several before
399 * we unplug the device. We don't do explicit unplugging in here,
400 * instead we rely on sync_buffer() doing the unplug for us.
401 */
402 if (commit_transaction->t_synchronous_commit)
403 write_op = WRITE_SYNC_PLUG;
404 trace_jbd2_commit_locking(journal, commit_transaction); 361 trace_jbd2_commit_locking(journal, commit_transaction);
405 stats.run.rs_wait = commit_transaction->t_max_wait; 362 stats.run.rs_wait = commit_transaction->t_max_wait;
406 stats.run.rs_locked = jiffies; 363 stats.run.rs_locked = jiffies;
@@ -441,7 +398,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
441 * we do not require it to remember exactly which old buffers it 398 * we do not require it to remember exactly which old buffers it
442 * has reserved. This is consistent with the existing behaviour 399 * has reserved. This is consistent with the existing behaviour
443 * that multiple jbd2_journal_get_write_access() calls to the same 400 * that multiple jbd2_journal_get_write_access() calls to the same
444 * buffer are perfectly permissable. 401 * buffer are perfectly permissible.
445 */ 402 */
446 while (commit_transaction->t_reserved_list) { 403 while (commit_transaction->t_reserved_list) {
447 jh = commit_transaction->t_reserved_list; 404 jh = commit_transaction->t_reserved_list;
@@ -500,8 +457,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
500 if (err) 457 if (err)
501 jbd2_journal_abort(journal, err); 458 jbd2_journal_abort(journal, err);
502 459
460 blk_start_plug(&plug);
503 jbd2_journal_write_revoke_records(journal, commit_transaction, 461 jbd2_journal_write_revoke_records(journal, commit_transaction,
504 write_op); 462 WRITE_SYNC);
463 blk_finish_plug(&plug);
505 464
506 jbd_debug(3, "JBD: commit phase 2\n"); 465 jbd_debug(3, "JBD: commit phase 2\n");
507 466
@@ -528,6 +487,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
528 err = 0; 487 err = 0;
529 descriptor = NULL; 488 descriptor = NULL;
530 bufs = 0; 489 bufs = 0;
490 blk_start_plug(&plug);
531 while (commit_transaction->t_buffers) { 491 while (commit_transaction->t_buffers) {
532 492
533 /* Find the next buffer to be journaled... */ 493 /* Find the next buffer to be journaled... */
@@ -689,7 +649,7 @@ start_journal_io:
689 clear_buffer_dirty(bh); 649 clear_buffer_dirty(bh);
690 set_buffer_uptodate(bh); 650 set_buffer_uptodate(bh);
691 bh->b_end_io = journal_end_buffer_io_sync; 651 bh->b_end_io = journal_end_buffer_io_sync;
692 submit_bh(write_op, bh); 652 submit_bh(WRITE_SYNC, bh);
693 } 653 }
694 cond_resched(); 654 cond_resched();
695 stats.run.rs_blocks_logged += bufs; 655 stats.run.rs_blocks_logged += bufs;
@@ -701,16 +661,29 @@ start_journal_io:
701 } 661 }
702 } 662 }
703 663
664 err = journal_finish_inode_data_buffers(journal, commit_transaction);
665 if (err) {
666 printk(KERN_WARNING
667 "JBD2: Detected IO errors while flushing file data "
668 "on %s\n", journal->j_devname);
669 if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
670 jbd2_journal_abort(journal, err);
671 err = 0;
672 }
673
674 write_lock(&journal->j_state_lock);
675 J_ASSERT(commit_transaction->t_state == T_COMMIT);
676 commit_transaction->t_state = T_COMMIT_DFLUSH;
677 write_unlock(&journal->j_state_lock);
704 /* 678 /*
705 * If the journal is not located on the file system device, 679 * If the journal is not located on the file system device,
706 * then we must flush the file system device before we issue 680 * then we must flush the file system device before we issue
707 * the commit record 681 * the commit record
708 */ 682 */
709 if (commit_transaction->t_flushed_data_blocks && 683 if (commit_transaction->t_need_data_flush &&
710 (journal->j_fs_dev != journal->j_dev) && 684 (journal->j_fs_dev != journal->j_dev) &&
711 (journal->j_flags & JBD2_BARRIER)) 685 (journal->j_flags & JBD2_BARRIER))
712 blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL, 686 blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
713 BLKDEV_IFL_WAIT);
714 687
715 /* Done it all: now write the commit record asynchronously. */ 688 /* Done it all: now write the commit record asynchronously. */
716 if (JBD2_HAS_INCOMPAT_FEATURE(journal, 689 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
@@ -719,20 +692,9 @@ start_journal_io:
719 &cbh, crc32_sum); 692 &cbh, crc32_sum);
720 if (err) 693 if (err)
721 __jbd2_journal_abort_hard(journal); 694 __jbd2_journal_abort_hard(journal);
722 if (journal->j_flags & JBD2_BARRIER)
723 blkdev_issue_flush(journal->j_dev, GFP_KERNEL, NULL,
724 BLKDEV_IFL_WAIT);
725 } 695 }
726 696
727 err = journal_finish_inode_data_buffers(journal, commit_transaction); 697 blk_finish_plug(&plug);
728 if (err) {
729 printk(KERN_WARNING
730 "JBD2: Detected IO errors while flushing file data "
731 "on %s\n", journal->j_devname);
732 if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
733 jbd2_journal_abort(journal, err);
734 err = 0;
735 }
736 698
737 /* Lo and behold: we have just managed to send a transaction to 699 /* Lo and behold: we have just managed to send a transaction to
738 the log. Before we can commit it, wait for the IO so far to 700 the log. Before we can commit it, wait for the IO so far to
@@ -795,8 +757,13 @@ wait_for_iobuf:
795 required. */ 757 required. */
796 JBUFFER_TRACE(jh, "file as BJ_Forget"); 758 JBUFFER_TRACE(jh, "file as BJ_Forget");
797 jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget); 759 jbd2_journal_file_buffer(jh, commit_transaction, BJ_Forget);
798 /* Wake up any transactions which were waiting for this 760 /*
799 IO to complete */ 761 * Wake up any transactions which were waiting for this IO to
762 * complete. The barrier must be here so that changes by
763 * jbd2_journal_file_buffer() take effect before wake_up_bit()
764 * does the waitqueue check.
765 */
766 smp_mb();
800 wake_up_bit(&bh->b_state, BH_Unshadow); 767 wake_up_bit(&bh->b_state, BH_Unshadow);
801 JBUFFER_TRACE(jh, "brelse shadowed buffer"); 768 JBUFFER_TRACE(jh, "brelse shadowed buffer");
802 __brelse(bh); 769 __brelse(bh);
@@ -835,6 +802,10 @@ wait_for_iobuf:
835 jbd2_journal_abort(journal, err); 802 jbd2_journal_abort(journal, err);
836 803
837 jbd_debug(3, "JBD: commit phase 5\n"); 804 jbd_debug(3, "JBD: commit phase 5\n");
805 write_lock(&journal->j_state_lock);
806 J_ASSERT(commit_transaction->t_state == T_COMMIT_DFLUSH);
807 commit_transaction->t_state = T_COMMIT_JFLUSH;
808 write_unlock(&journal->j_state_lock);
838 809
839 if (!JBD2_HAS_INCOMPAT_FEATURE(journal, 810 if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
840 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { 811 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
@@ -843,8 +814,13 @@ wait_for_iobuf:
843 if (err) 814 if (err)
844 __jbd2_journal_abort_hard(journal); 815 __jbd2_journal_abort_hard(journal);
845 } 816 }
846 if (!err && !is_journal_aborted(journal)) 817 if (cbh)
847 err = journal_wait_on_commit_record(journal, cbh); 818 err = journal_wait_on_commit_record(journal, cbh);
819 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
820 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
821 journal->j_flags & JBD2_BARRIER) {
822 blkdev_issue_flush(journal->j_dev, GFP_KERNEL, NULL);
823 }
848 824
849 if (err) 825 if (err)
850 jbd2_journal_abort(journal, err); 826 jbd2_journal_abort(journal, err);
@@ -872,10 +848,16 @@ restart_loop:
872 while (commit_transaction->t_forget) { 848 while (commit_transaction->t_forget) {
873 transaction_t *cp_transaction; 849 transaction_t *cp_transaction;
874 struct buffer_head *bh; 850 struct buffer_head *bh;
851 int try_to_free = 0;
875 852
876 jh = commit_transaction->t_forget; 853 jh = commit_transaction->t_forget;
877 spin_unlock(&journal->j_list_lock); 854 spin_unlock(&journal->j_list_lock);
878 bh = jh2bh(jh); 855 bh = jh2bh(jh);
856 /*
857 * Get a reference so that bh cannot be freed before we are
858 * done with it.
859 */
860 get_bh(bh);
879 jbd_lock_bh_state(bh); 861 jbd_lock_bh_state(bh);
880 J_ASSERT_JH(jh, jh->b_transaction == commit_transaction); 862 J_ASSERT_JH(jh, jh->b_transaction == commit_transaction);
881 863
@@ -938,28 +920,27 @@ restart_loop:
938 __jbd2_journal_insert_checkpoint(jh, commit_transaction); 920 __jbd2_journal_insert_checkpoint(jh, commit_transaction);
939 if (is_journal_aborted(journal)) 921 if (is_journal_aborted(journal))
940 clear_buffer_jbddirty(bh); 922 clear_buffer_jbddirty(bh);
941 JBUFFER_TRACE(jh, "refile for checkpoint writeback");
942 __jbd2_journal_refile_buffer(jh);
943 jbd_unlock_bh_state(bh);
944 } else { 923 } else {
945 J_ASSERT_BH(bh, !buffer_dirty(bh)); 924 J_ASSERT_BH(bh, !buffer_dirty(bh));
946 /* The buffer on BJ_Forget list and not jbddirty means 925 /*
926 * The buffer on BJ_Forget list and not jbddirty means
947 * it has been freed by this transaction and hence it 927 * it has been freed by this transaction and hence it
948 * could not have been reallocated until this 928 * could not have been reallocated until this
949 * transaction has committed. *BUT* it could be 929 * transaction has committed. *BUT* it could be
950 * reallocated once we have written all the data to 930 * reallocated once we have written all the data to
951 * disk and before we process the buffer on BJ_Forget 931 * disk and before we process the buffer on BJ_Forget
952 * list. */ 932 * list.
953 JBUFFER_TRACE(jh, "refile or unfile freed buffer"); 933 */
954 __jbd2_journal_refile_buffer(jh); 934 if (!jh->b_next_transaction)
955 if (!jh->b_transaction) { 935 try_to_free = 1;
956 jbd_unlock_bh_state(bh);
957 /* needs a brelse */
958 jbd2_journal_remove_journal_head(bh);
959 release_buffer_page(bh);
960 } else
961 jbd_unlock_bh_state(bh);
962 } 936 }
937 JBUFFER_TRACE(jh, "refile or unfile buffer");
938 __jbd2_journal_refile_buffer(jh);
939 jbd_unlock_bh_state(bh);
940 if (try_to_free)
941 release_buffer_page(bh); /* Drops bh reference */
942 else
943 __brelse(bh);
963 cond_resched_lock(&journal->j_list_lock); 944 cond_resched_lock(&journal->j_list_lock);
964 } 945 }
965 spin_unlock(&journal->j_list_lock); 946 spin_unlock(&journal->j_list_lock);
@@ -985,7 +966,7 @@ restart_loop:
985 966
986 jbd_debug(3, "JBD: commit phase 7\n"); 967 jbd_debug(3, "JBD: commit phase 7\n");
987 968
988 J_ASSERT(commit_transaction->t_state == T_COMMIT); 969 J_ASSERT(commit_transaction->t_state == T_COMMIT_JFLUSH);
989 970
990 commit_transaction->t_start = jiffies; 971 commit_transaction->t_start = jiffies;
991 stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging, 972 stats.run.rs_logging = jbd2_time_diff(stats.run.rs_logging,