aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jbd2')
-rw-r--r--fs/jbd2/checkpoint.c18
-rw-r--r--fs/jbd2/commit.c50
-rw-r--r--fs/jbd2/journal.c121
-rw-r--r--fs/jbd2/recovery.c10
-rw-r--r--fs/jbd2/transaction.c233
5 files changed, 236 insertions, 196 deletions
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 076d1cc44f95..1c23a0f4e8a3 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -118,13 +118,13 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
118void __jbd2_log_wait_for_space(journal_t *journal) 118void __jbd2_log_wait_for_space(journal_t *journal)
119{ 119{
120 int nblocks, space_left; 120 int nblocks, space_left;
121 assert_spin_locked(&journal->j_state_lock); 121 /* assert_spin_locked(&journal->j_state_lock); */
122 122
123 nblocks = jbd_space_needed(journal); 123 nblocks = jbd_space_needed(journal);
124 while (__jbd2_log_space_left(journal) < nblocks) { 124 while (__jbd2_log_space_left(journal) < nblocks) {
125 if (journal->j_flags & JBD2_ABORT) 125 if (journal->j_flags & JBD2_ABORT)
126 return; 126 return;
127 spin_unlock(&journal->j_state_lock); 127 write_unlock(&journal->j_state_lock);
128 mutex_lock(&journal->j_checkpoint_mutex); 128 mutex_lock(&journal->j_checkpoint_mutex);
129 129
130 /* 130 /*
@@ -138,7 +138,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
138 * filesystem, so abort the journal and leave a stack 138 * filesystem, so abort the journal and leave a stack
139 * trace for forensic evidence. 139 * trace for forensic evidence.
140 */ 140 */
141 spin_lock(&journal->j_state_lock); 141 write_lock(&journal->j_state_lock);
142 spin_lock(&journal->j_list_lock); 142 spin_lock(&journal->j_list_lock);
143 nblocks = jbd_space_needed(journal); 143 nblocks = jbd_space_needed(journal);
144 space_left = __jbd2_log_space_left(journal); 144 space_left = __jbd2_log_space_left(journal);
@@ -149,7 +149,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
149 if (journal->j_committing_transaction) 149 if (journal->j_committing_transaction)
150 tid = journal->j_committing_transaction->t_tid; 150 tid = journal->j_committing_transaction->t_tid;
151 spin_unlock(&journal->j_list_lock); 151 spin_unlock(&journal->j_list_lock);
152 spin_unlock(&journal->j_state_lock); 152 write_unlock(&journal->j_state_lock);
153 if (chkpt) { 153 if (chkpt) {
154 jbd2_log_do_checkpoint(journal); 154 jbd2_log_do_checkpoint(journal);
155 } else if (jbd2_cleanup_journal_tail(journal) == 0) { 155 } else if (jbd2_cleanup_journal_tail(journal) == 0) {
@@ -167,7 +167,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
167 WARN_ON(1); 167 WARN_ON(1);
168 jbd2_journal_abort(journal, 0); 168 jbd2_journal_abort(journal, 0);
169 } 169 }
170 spin_lock(&journal->j_state_lock); 170 write_lock(&journal->j_state_lock);
171 } else { 171 } else {
172 spin_unlock(&journal->j_list_lock); 172 spin_unlock(&journal->j_list_lock);
173 } 173 }
@@ -474,7 +474,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
474 * next transaction ID we will write, and where it will 474 * next transaction ID we will write, and where it will
475 * start. */ 475 * start. */
476 476
477 spin_lock(&journal->j_state_lock); 477 write_lock(&journal->j_state_lock);
478 spin_lock(&journal->j_list_lock); 478 spin_lock(&journal->j_list_lock);
479 transaction = journal->j_checkpoint_transactions; 479 transaction = journal->j_checkpoint_transactions;
480 if (transaction) { 480 if (transaction) {
@@ -496,7 +496,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
496 /* If the oldest pinned transaction is at the tail of the log 496 /* If the oldest pinned transaction is at the tail of the log
497 already then there's not much we can do right now. */ 497 already then there's not much we can do right now. */
498 if (journal->j_tail_sequence == first_tid) { 498 if (journal->j_tail_sequence == first_tid) {
499 spin_unlock(&journal->j_state_lock); 499 write_unlock(&journal->j_state_lock);
500 return 1; 500 return 1;
501 } 501 }
502 502
@@ -516,7 +516,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
516 journal->j_free += freed; 516 journal->j_free += freed;
517 journal->j_tail_sequence = first_tid; 517 journal->j_tail_sequence = first_tid;
518 journal->j_tail = blocknr; 518 journal->j_tail = blocknr;
519 spin_unlock(&journal->j_state_lock); 519 write_unlock(&journal->j_state_lock);
520 520
521 /* 521 /*
522 * If there is an external journal, we need to make sure that 522 * If there is an external journal, we need to make sure that
@@ -775,7 +775,7 @@ void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transact
775 J_ASSERT(transaction->t_log_list == NULL); 775 J_ASSERT(transaction->t_log_list == NULL);
776 J_ASSERT(transaction->t_checkpoint_list == NULL); 776 J_ASSERT(transaction->t_checkpoint_list == NULL);
777 J_ASSERT(transaction->t_checkpoint_io_list == NULL); 777 J_ASSERT(transaction->t_checkpoint_io_list == NULL);
778 J_ASSERT(transaction->t_updates == 0); 778 J_ASSERT(atomic_read(&transaction->t_updates) == 0);
779 J_ASSERT(journal->j_committing_transaction != transaction); 779 J_ASSERT(journal->j_committing_transaction != transaction);
780 J_ASSERT(journal->j_running_transaction != transaction); 780 J_ASSERT(journal->j_running_transaction != transaction);
781 781
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 75716d3d2be0..f52e5e8049f1 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -150,11 +150,11 @@ static int journal_submit_commit_record(journal_t *journal,
150 */ 150 */
151 if (ret == -EOPNOTSUPP && barrier_done) { 151 if (ret == -EOPNOTSUPP && barrier_done) {
152 printk(KERN_WARNING 152 printk(KERN_WARNING
153 "JBD: barrier-based sync failed on %s - " 153 "JBD2: Disabling barriers on %s, "
154 "disabling barriers\n", journal->j_devname); 154 "not supported by device\n", journal->j_devname);
155 spin_lock(&journal->j_state_lock); 155 write_lock(&journal->j_state_lock);
156 journal->j_flags &= ~JBD2_BARRIER; 156 journal->j_flags &= ~JBD2_BARRIER;
157 spin_unlock(&journal->j_state_lock); 157 write_unlock(&journal->j_state_lock);
158 158
159 /* And try again, without the barrier */ 159 /* And try again, without the barrier */
160 lock_buffer(bh); 160 lock_buffer(bh);
@@ -180,11 +180,11 @@ retry:
180 wait_on_buffer(bh); 180 wait_on_buffer(bh);
181 if (buffer_eopnotsupp(bh) && (journal->j_flags & JBD2_BARRIER)) { 181 if (buffer_eopnotsupp(bh) && (journal->j_flags & JBD2_BARRIER)) {
182 printk(KERN_WARNING 182 printk(KERN_WARNING
183 "JBD2: wait_on_commit_record: sync failed on %s - " 183 "JBD2: %s: disabling barries on %s - not supported "
184 "disabling barriers\n", journal->j_devname); 184 "by device\n", __func__, journal->j_devname);
185 spin_lock(&journal->j_state_lock); 185 write_lock(&journal->j_state_lock);
186 journal->j_flags &= ~JBD2_BARRIER; 186 journal->j_flags &= ~JBD2_BARRIER;
187 spin_unlock(&journal->j_state_lock); 187 write_unlock(&journal->j_state_lock);
188 188
189 lock_buffer(bh); 189 lock_buffer(bh);
190 clear_buffer_dirty(bh); 190 clear_buffer_dirty(bh);
@@ -400,7 +400,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
400 jbd_debug(1, "JBD: starting commit of transaction %d\n", 400 jbd_debug(1, "JBD: starting commit of transaction %d\n",
401 commit_transaction->t_tid); 401 commit_transaction->t_tid);
402 402
403 spin_lock(&journal->j_state_lock); 403 write_lock(&journal->j_state_lock);
404 commit_transaction->t_state = T_LOCKED; 404 commit_transaction->t_state = T_LOCKED;
405 405
406 /* 406 /*
@@ -417,23 +417,23 @@ void jbd2_journal_commit_transaction(journal_t *journal)
417 stats.run.rs_locked); 417 stats.run.rs_locked);
418 418
419 spin_lock(&commit_transaction->t_handle_lock); 419 spin_lock(&commit_transaction->t_handle_lock);
420 while (commit_transaction->t_updates) { 420 while (atomic_read(&commit_transaction->t_updates)) {
421 DEFINE_WAIT(wait); 421 DEFINE_WAIT(wait);
422 422
423 prepare_to_wait(&journal->j_wait_updates, &wait, 423 prepare_to_wait(&journal->j_wait_updates, &wait,
424 TASK_UNINTERRUPTIBLE); 424 TASK_UNINTERRUPTIBLE);
425 if (commit_transaction->t_updates) { 425 if (atomic_read(&commit_transaction->t_updates)) {
426 spin_unlock(&commit_transaction->t_handle_lock); 426 spin_unlock(&commit_transaction->t_handle_lock);
427 spin_unlock(&journal->j_state_lock); 427 write_unlock(&journal->j_state_lock);
428 schedule(); 428 schedule();
429 spin_lock(&journal->j_state_lock); 429 write_lock(&journal->j_state_lock);
430 spin_lock(&commit_transaction->t_handle_lock); 430 spin_lock(&commit_transaction->t_handle_lock);
431 } 431 }
432 finish_wait(&journal->j_wait_updates, &wait); 432 finish_wait(&journal->j_wait_updates, &wait);
433 } 433 }
434 spin_unlock(&commit_transaction->t_handle_lock); 434 spin_unlock(&commit_transaction->t_handle_lock);
435 435
436 J_ASSERT (commit_transaction->t_outstanding_credits <= 436 J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
437 journal->j_max_transaction_buffers); 437 journal->j_max_transaction_buffers);
438 438
439 /* 439 /*
@@ -497,7 +497,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
497 start_time = ktime_get(); 497 start_time = ktime_get();
498 commit_transaction->t_log_start = journal->j_head; 498 commit_transaction->t_log_start = journal->j_head;
499 wake_up(&journal->j_wait_transaction_locked); 499 wake_up(&journal->j_wait_transaction_locked);
500 spin_unlock(&journal->j_state_lock); 500 write_unlock(&journal->j_state_lock);
501 501
502 jbd_debug (3, "JBD: commit phase 2\n"); 502 jbd_debug (3, "JBD: commit phase 2\n");
503 503
@@ -519,19 +519,20 @@ void jbd2_journal_commit_transaction(journal_t *journal)
519 * transaction! Now comes the tricky part: we need to write out 519 * transaction! Now comes the tricky part: we need to write out
520 * metadata. Loop over the transaction's entire buffer list: 520 * metadata. Loop over the transaction's entire buffer list:
521 */ 521 */
522 spin_lock(&journal->j_state_lock); 522 write_lock(&journal->j_state_lock);
523 commit_transaction->t_state = T_COMMIT; 523 commit_transaction->t_state = T_COMMIT;
524 spin_unlock(&journal->j_state_lock); 524 write_unlock(&journal->j_state_lock);
525 525
526 trace_jbd2_commit_logging(journal, commit_transaction); 526 trace_jbd2_commit_logging(journal, commit_transaction);
527 stats.run.rs_logging = jiffies; 527 stats.run.rs_logging = jiffies;
528 stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing, 528 stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing,
529 stats.run.rs_logging); 529 stats.run.rs_logging);
530 stats.run.rs_blocks = commit_transaction->t_outstanding_credits; 530 stats.run.rs_blocks =
531 atomic_read(&commit_transaction->t_outstanding_credits);
531 stats.run.rs_blocks_logged = 0; 532 stats.run.rs_blocks_logged = 0;
532 533
533 J_ASSERT(commit_transaction->t_nr_buffers <= 534 J_ASSERT(commit_transaction->t_nr_buffers <=
534 commit_transaction->t_outstanding_credits); 535 atomic_read(&commit_transaction->t_outstanding_credits));
535 536
536 err = 0; 537 err = 0;
537 descriptor = NULL; 538 descriptor = NULL;
@@ -616,7 +617,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
616 * the free space in the log, but this counter is changed 617 * the free space in the log, but this counter is changed
617 * by jbd2_journal_next_log_block() also. 618 * by jbd2_journal_next_log_block() also.
618 */ 619 */
619 commit_transaction->t_outstanding_credits--; 620 atomic_dec(&commit_transaction->t_outstanding_credits);
620 621
621 /* Bump b_count to prevent truncate from stumbling over 622 /* Bump b_count to prevent truncate from stumbling over
622 the shadowed buffer! @@@ This can go if we ever get 623 the shadowed buffer! @@@ This can go if we ever get
@@ -977,7 +978,7 @@ restart_loop:
977 * __jbd2_journal_drop_transaction(). Otherwise we could race with 978 * __jbd2_journal_drop_transaction(). Otherwise we could race with
978 * other checkpointing code processing the transaction... 979 * other checkpointing code processing the transaction...
979 */ 980 */
980 spin_lock(&journal->j_state_lock); 981 write_lock(&journal->j_state_lock);
981 spin_lock(&journal->j_list_lock); 982 spin_lock(&journal->j_list_lock);
982 /* 983 /*
983 * Now recheck if some buffers did not get attached to the transaction 984 * Now recheck if some buffers did not get attached to the transaction
@@ -985,7 +986,7 @@ restart_loop:
985 */ 986 */
986 if (commit_transaction->t_forget) { 987 if (commit_transaction->t_forget) {
987 spin_unlock(&journal->j_list_lock); 988 spin_unlock(&journal->j_list_lock);
988 spin_unlock(&journal->j_state_lock); 989 write_unlock(&journal->j_state_lock);
989 goto restart_loop; 990 goto restart_loop;
990 } 991 }
991 992
@@ -1003,7 +1004,8 @@ restart_loop:
1003 * File the transaction statistics 1004 * File the transaction statistics
1004 */ 1005 */
1005 stats.ts_tid = commit_transaction->t_tid; 1006 stats.ts_tid = commit_transaction->t_tid;
1006 stats.run.rs_handle_count = commit_transaction->t_handle_count; 1007 stats.run.rs_handle_count =
1008 atomic_read(&commit_transaction->t_handle_count);
1007 trace_jbd2_run_stats(journal->j_fs_dev->bd_dev, 1009 trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
1008 commit_transaction->t_tid, &stats.run); 1010 commit_transaction->t_tid, &stats.run);
1009 1011
@@ -1037,7 +1039,7 @@ restart_loop:
1037 journal->j_average_commit_time*3) / 4; 1039 journal->j_average_commit_time*3) / 4;
1038 else 1040 else
1039 journal->j_average_commit_time = commit_time; 1041 journal->j_average_commit_time = commit_time;
1040 spin_unlock(&journal->j_state_lock); 1042 write_unlock(&journal->j_state_lock);
1041 1043
1042 if (commit_transaction->t_checkpoint_list == NULL && 1044 if (commit_transaction->t_checkpoint_list == NULL &&
1043 commit_transaction->t_checkpoint_io_list == NULL) { 1045 commit_transaction->t_checkpoint_io_list == NULL) {
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 036880895bfc..ad5866aaf0f9 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -41,6 +41,7 @@
41#include <linux/hash.h> 41#include <linux/hash.h>
42#include <linux/log2.h> 42#include <linux/log2.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/backing-dev.h>
44 45
45#define CREATE_TRACE_POINTS 46#define CREATE_TRACE_POINTS
46#include <trace/events/jbd2.h> 47#include <trace/events/jbd2.h>
@@ -48,8 +49,6 @@
48#include <asm/uaccess.h> 49#include <asm/uaccess.h>
49#include <asm/page.h> 50#include <asm/page.h>
50 51
51EXPORT_SYMBOL(jbd2_journal_start);
52EXPORT_SYMBOL(jbd2_journal_restart);
53EXPORT_SYMBOL(jbd2_journal_extend); 52EXPORT_SYMBOL(jbd2_journal_extend);
54EXPORT_SYMBOL(jbd2_journal_stop); 53EXPORT_SYMBOL(jbd2_journal_stop);
55EXPORT_SYMBOL(jbd2_journal_lock_updates); 54EXPORT_SYMBOL(jbd2_journal_lock_updates);
@@ -143,7 +142,7 @@ static int kjournald2(void *arg)
143 /* 142 /*
144 * And now, wait forever for commit wakeup events. 143 * And now, wait forever for commit wakeup events.
145 */ 144 */
146 spin_lock(&journal->j_state_lock); 145 write_lock(&journal->j_state_lock);
147 146
148loop: 147loop:
149 if (journal->j_flags & JBD2_UNMOUNT) 148 if (journal->j_flags & JBD2_UNMOUNT)
@@ -154,10 +153,10 @@ loop:
154 153
155 if (journal->j_commit_sequence != journal->j_commit_request) { 154 if (journal->j_commit_sequence != journal->j_commit_request) {
156 jbd_debug(1, "OK, requests differ\n"); 155 jbd_debug(1, "OK, requests differ\n");
157 spin_unlock(&journal->j_state_lock); 156 write_unlock(&journal->j_state_lock);
158 del_timer_sync(&journal->j_commit_timer); 157 del_timer_sync(&journal->j_commit_timer);
159 jbd2_journal_commit_transaction(journal); 158 jbd2_journal_commit_transaction(journal);
160 spin_lock(&journal->j_state_lock); 159 write_lock(&journal->j_state_lock);
161 goto loop; 160 goto loop;
162 } 161 }
163 162
@@ -169,9 +168,9 @@ loop:
169 * be already stopped. 168 * be already stopped.
170 */ 169 */
171 jbd_debug(1, "Now suspending kjournald2\n"); 170 jbd_debug(1, "Now suspending kjournald2\n");
172 spin_unlock(&journal->j_state_lock); 171 write_unlock(&journal->j_state_lock);
173 refrigerator(); 172 refrigerator();
174 spin_lock(&journal->j_state_lock); 173 write_lock(&journal->j_state_lock);
175 } else { 174 } else {
176 /* 175 /*
177 * We assume on resume that commits are already there, 176 * We assume on resume that commits are already there,
@@ -191,9 +190,9 @@ loop:
191 if (journal->j_flags & JBD2_UNMOUNT) 190 if (journal->j_flags & JBD2_UNMOUNT)
192 should_sleep = 0; 191 should_sleep = 0;
193 if (should_sleep) { 192 if (should_sleep) {
194 spin_unlock(&journal->j_state_lock); 193 write_unlock(&journal->j_state_lock);
195 schedule(); 194 schedule();
196 spin_lock(&journal->j_state_lock); 195 write_lock(&journal->j_state_lock);
197 } 196 }
198 finish_wait(&journal->j_wait_commit, &wait); 197 finish_wait(&journal->j_wait_commit, &wait);
199 } 198 }
@@ -211,7 +210,7 @@ loop:
211 goto loop; 210 goto loop;
212 211
213end_loop: 212end_loop:
214 spin_unlock(&journal->j_state_lock); 213 write_unlock(&journal->j_state_lock);
215 del_timer_sync(&journal->j_commit_timer); 214 del_timer_sync(&journal->j_commit_timer);
216 journal->j_task = NULL; 215 journal->j_task = NULL;
217 wake_up(&journal->j_wait_done_commit); 216 wake_up(&journal->j_wait_done_commit);
@@ -234,16 +233,16 @@ static int jbd2_journal_start_thread(journal_t *journal)
234 233
235static void journal_kill_thread(journal_t *journal) 234static void journal_kill_thread(journal_t *journal)
236{ 235{
237 spin_lock(&journal->j_state_lock); 236 write_lock(&journal->j_state_lock);
238 journal->j_flags |= JBD2_UNMOUNT; 237 journal->j_flags |= JBD2_UNMOUNT;
239 238
240 while (journal->j_task) { 239 while (journal->j_task) {
241 wake_up(&journal->j_wait_commit); 240 wake_up(&journal->j_wait_commit);
242 spin_unlock(&journal->j_state_lock); 241 write_unlock(&journal->j_state_lock);
243 wait_event(journal->j_wait_done_commit, journal->j_task == NULL); 242 wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
244 spin_lock(&journal->j_state_lock); 243 write_lock(&journal->j_state_lock);
245 } 244 }
246 spin_unlock(&journal->j_state_lock); 245 write_unlock(&journal->j_state_lock);
247} 246}
248 247
249/* 248/*
@@ -310,7 +309,17 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
310 */ 309 */
311 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in)); 310 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
312 311
313 new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL); 312retry_alloc:
313 new_bh = alloc_buffer_head(GFP_NOFS);
314 if (!new_bh) {
315 /*
316 * Failure is not an option, but __GFP_NOFAIL is going
317 * away; so we retry ourselves here.
318 */
319 congestion_wait(BLK_RW_ASYNC, HZ/50);
320 goto retry_alloc;
321 }
322
314 /* keep subsequent assertions sane */ 323 /* keep subsequent assertions sane */
315 new_bh->b_state = 0; 324 new_bh->b_state = 0;
316 init_buffer(new_bh, NULL, NULL); 325 init_buffer(new_bh, NULL, NULL);
@@ -442,7 +451,7 @@ int __jbd2_log_space_left(journal_t *journal)
442{ 451{
443 int left = journal->j_free; 452 int left = journal->j_free;
444 453
445 assert_spin_locked(&journal->j_state_lock); 454 /* assert_spin_locked(&journal->j_state_lock); */
446 455
447 /* 456 /*
448 * Be pessimistic here about the number of those free blocks which 457 * Be pessimistic here about the number of those free blocks which
@@ -487,9 +496,9 @@ int jbd2_log_start_commit(journal_t *journal, tid_t tid)
487{ 496{
488 int ret; 497 int ret;
489 498
490 spin_lock(&journal->j_state_lock); 499 write_lock(&journal->j_state_lock);
491 ret = __jbd2_log_start_commit(journal, tid); 500 ret = __jbd2_log_start_commit(journal, tid);
492 spin_unlock(&journal->j_state_lock); 501 write_unlock(&journal->j_state_lock);
493 return ret; 502 return ret;
494} 503}
495 504
@@ -508,7 +517,7 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
508 transaction_t *transaction = NULL; 517 transaction_t *transaction = NULL;
509 tid_t tid; 518 tid_t tid;
510 519
511 spin_lock(&journal->j_state_lock); 520 read_lock(&journal->j_state_lock);
512 if (journal->j_running_transaction && !current->journal_info) { 521 if (journal->j_running_transaction && !current->journal_info) {
513 transaction = journal->j_running_transaction; 522 transaction = journal->j_running_transaction;
514 __jbd2_log_start_commit(journal, transaction->t_tid); 523 __jbd2_log_start_commit(journal, transaction->t_tid);
@@ -516,12 +525,12 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
516 transaction = journal->j_committing_transaction; 525 transaction = journal->j_committing_transaction;
517 526
518 if (!transaction) { 527 if (!transaction) {
519 spin_unlock(&journal->j_state_lock); 528 read_unlock(&journal->j_state_lock);
520 return 0; /* Nothing to retry */ 529 return 0; /* Nothing to retry */
521 } 530 }
522 531
523 tid = transaction->t_tid; 532 tid = transaction->t_tid;
524 spin_unlock(&journal->j_state_lock); 533 read_unlock(&journal->j_state_lock);
525 jbd2_log_wait_commit(journal, tid); 534 jbd2_log_wait_commit(journal, tid);
526 return 1; 535 return 1;
527} 536}
@@ -535,7 +544,7 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
535{ 544{
536 int ret = 0; 545 int ret = 0;
537 546
538 spin_lock(&journal->j_state_lock); 547 write_lock(&journal->j_state_lock);
539 if (journal->j_running_transaction) { 548 if (journal->j_running_transaction) {
540 tid_t tid = journal->j_running_transaction->t_tid; 549 tid_t tid = journal->j_running_transaction->t_tid;
541 550
@@ -554,7 +563,7 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
554 *ptid = journal->j_committing_transaction->t_tid; 563 *ptid = journal->j_committing_transaction->t_tid;
555 ret = 1; 564 ret = 1;
556 } 565 }
557 spin_unlock(&journal->j_state_lock); 566 write_unlock(&journal->j_state_lock);
558 return ret; 567 return ret;
559} 568}
560 569
@@ -566,26 +575,24 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
566{ 575{
567 int err = 0; 576 int err = 0;
568 577
578 read_lock(&journal->j_state_lock);
569#ifdef CONFIG_JBD2_DEBUG 579#ifdef CONFIG_JBD2_DEBUG
570 spin_lock(&journal->j_state_lock);
571 if (!tid_geq(journal->j_commit_request, tid)) { 580 if (!tid_geq(journal->j_commit_request, tid)) {
572 printk(KERN_EMERG 581 printk(KERN_EMERG
573 "%s: error: j_commit_request=%d, tid=%d\n", 582 "%s: error: j_commit_request=%d, tid=%d\n",
574 __func__, journal->j_commit_request, tid); 583 __func__, journal->j_commit_request, tid);
575 } 584 }
576 spin_unlock(&journal->j_state_lock);
577#endif 585#endif
578 spin_lock(&journal->j_state_lock);
579 while (tid_gt(tid, journal->j_commit_sequence)) { 586 while (tid_gt(tid, journal->j_commit_sequence)) {
580 jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n", 587 jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
581 tid, journal->j_commit_sequence); 588 tid, journal->j_commit_sequence);
582 wake_up(&journal->j_wait_commit); 589 wake_up(&journal->j_wait_commit);
583 spin_unlock(&journal->j_state_lock); 590 read_unlock(&journal->j_state_lock);
584 wait_event(journal->j_wait_done_commit, 591 wait_event(journal->j_wait_done_commit,
585 !tid_gt(tid, journal->j_commit_sequence)); 592 !tid_gt(tid, journal->j_commit_sequence));
586 spin_lock(&journal->j_state_lock); 593 read_lock(&journal->j_state_lock);
587 } 594 }
588 spin_unlock(&journal->j_state_lock); 595 read_unlock(&journal->j_state_lock);
589 596
590 if (unlikely(is_journal_aborted(journal))) { 597 if (unlikely(is_journal_aborted(journal))) {
591 printk(KERN_EMERG "journal commit I/O error\n"); 598 printk(KERN_EMERG "journal commit I/O error\n");
@@ -602,7 +609,7 @@ int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
602{ 609{
603 unsigned long blocknr; 610 unsigned long blocknr;
604 611
605 spin_lock(&journal->j_state_lock); 612 write_lock(&journal->j_state_lock);
606 J_ASSERT(journal->j_free > 1); 613 J_ASSERT(journal->j_free > 1);
607 614
608 blocknr = journal->j_head; 615 blocknr = journal->j_head;
@@ -610,7 +617,7 @@ int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
610 journal->j_free--; 617 journal->j_free--;
611 if (journal->j_head == journal->j_last) 618 if (journal->j_head == journal->j_last)
612 journal->j_head = journal->j_first; 619 journal->j_head = journal->j_first;
613 spin_unlock(&journal->j_state_lock); 620 write_unlock(&journal->j_state_lock);
614 return jbd2_journal_bmap(journal, blocknr, retp); 621 return jbd2_journal_bmap(journal, blocknr, retp);
615} 622}
616 623
@@ -830,7 +837,7 @@ static journal_t * journal_init_common (void)
830 mutex_init(&journal->j_checkpoint_mutex); 837 mutex_init(&journal->j_checkpoint_mutex);
831 spin_lock_init(&journal->j_revoke_lock); 838 spin_lock_init(&journal->j_revoke_lock);
832 spin_lock_init(&journal->j_list_lock); 839 spin_lock_init(&journal->j_list_lock);
833 spin_lock_init(&journal->j_state_lock); 840 rwlock_init(&journal->j_state_lock);
834 841
835 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE); 842 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
836 journal->j_min_batch_time = 0; 843 journal->j_min_batch_time = 0;
@@ -1096,14 +1103,14 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
1096 set_buffer_uptodate(bh); 1103 set_buffer_uptodate(bh);
1097 } 1104 }
1098 1105
1099 spin_lock(&journal->j_state_lock); 1106 read_lock(&journal->j_state_lock);
1100 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n", 1107 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
1101 journal->j_tail, journal->j_tail_sequence, journal->j_errno); 1108 journal->j_tail, journal->j_tail_sequence, journal->j_errno);
1102 1109
1103 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); 1110 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
1104 sb->s_start = cpu_to_be32(journal->j_tail); 1111 sb->s_start = cpu_to_be32(journal->j_tail);
1105 sb->s_errno = cpu_to_be32(journal->j_errno); 1112 sb->s_errno = cpu_to_be32(journal->j_errno);
1106 spin_unlock(&journal->j_state_lock); 1113 read_unlock(&journal->j_state_lock);
1107 1114
1108 BUFFER_TRACE(bh, "marking dirty"); 1115 BUFFER_TRACE(bh, "marking dirty");
1109 mark_buffer_dirty(bh); 1116 mark_buffer_dirty(bh);
@@ -1124,12 +1131,12 @@ out:
1124 * any future commit will have to be careful to update the 1131 * any future commit will have to be careful to update the
1125 * superblock again to re-record the true start of the log. */ 1132 * superblock again to re-record the true start of the log. */
1126 1133
1127 spin_lock(&journal->j_state_lock); 1134 write_lock(&journal->j_state_lock);
1128 if (sb->s_start) 1135 if (sb->s_start)
1129 journal->j_flags &= ~JBD2_FLUSHED; 1136 journal->j_flags &= ~JBD2_FLUSHED;
1130 else 1137 else
1131 journal->j_flags |= JBD2_FLUSHED; 1138 journal->j_flags |= JBD2_FLUSHED;
1132 spin_unlock(&journal->j_state_lock); 1139 write_unlock(&journal->j_state_lock);
1133} 1140}
1134 1141
1135/* 1142/*
@@ -1391,13 +1398,9 @@ int jbd2_journal_check_used_features (journal_t *journal, unsigned long compat,
1391int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat, 1398int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat,
1392 unsigned long ro, unsigned long incompat) 1399 unsigned long ro, unsigned long incompat)
1393{ 1400{
1394 journal_superblock_t *sb;
1395
1396 if (!compat && !ro && !incompat) 1401 if (!compat && !ro && !incompat)
1397 return 1; 1402 return 1;
1398 1403
1399 sb = journal->j_superblock;
1400
1401 /* We can support any known requested features iff the 1404 /* We can support any known requested features iff the
1402 * superblock is in version 2. Otherwise we fail to support any 1405 * superblock is in version 2. Otherwise we fail to support any
1403 * extended sb features. */ 1406 * extended sb features. */
@@ -1545,7 +1548,7 @@ int jbd2_journal_flush(journal_t *journal)
1545 transaction_t *transaction = NULL; 1548 transaction_t *transaction = NULL;
1546 unsigned long old_tail; 1549 unsigned long old_tail;
1547 1550
1548 spin_lock(&journal->j_state_lock); 1551 write_lock(&journal->j_state_lock);
1549 1552
1550 /* Force everything buffered to the log... */ 1553 /* Force everything buffered to the log... */
1551 if (journal->j_running_transaction) { 1554 if (journal->j_running_transaction) {
@@ -1558,10 +1561,10 @@ int jbd2_journal_flush(journal_t *journal)
1558 if (transaction) { 1561 if (transaction) {
1559 tid_t tid = transaction->t_tid; 1562 tid_t tid = transaction->t_tid;
1560 1563
1561 spin_unlock(&journal->j_state_lock); 1564 write_unlock(&journal->j_state_lock);
1562 jbd2_log_wait_commit(journal, tid); 1565 jbd2_log_wait_commit(journal, tid);
1563 } else { 1566 } else {
1564 spin_unlock(&journal->j_state_lock); 1567 write_unlock(&journal->j_state_lock);
1565 } 1568 }
1566 1569
1567 /* ...and flush everything in the log out to disk. */ 1570 /* ...and flush everything in the log out to disk. */
@@ -1585,12 +1588,12 @@ int jbd2_journal_flush(journal_t *journal)
1585 * the magic code for a fully-recovered superblock. Any future 1588 * the magic code for a fully-recovered superblock. Any future
1586 * commits of data to the journal will restore the current 1589 * commits of data to the journal will restore the current
1587 * s_start value. */ 1590 * s_start value. */
1588 spin_lock(&journal->j_state_lock); 1591 write_lock(&journal->j_state_lock);
1589 old_tail = journal->j_tail; 1592 old_tail = journal->j_tail;
1590 journal->j_tail = 0; 1593 journal->j_tail = 0;
1591 spin_unlock(&journal->j_state_lock); 1594 write_unlock(&journal->j_state_lock);
1592 jbd2_journal_update_superblock(journal, 1); 1595 jbd2_journal_update_superblock(journal, 1);
1593 spin_lock(&journal->j_state_lock); 1596 write_lock(&journal->j_state_lock);
1594 journal->j_tail = old_tail; 1597 journal->j_tail = old_tail;
1595 1598
1596 J_ASSERT(!journal->j_running_transaction); 1599 J_ASSERT(!journal->j_running_transaction);
@@ -1598,7 +1601,7 @@ int jbd2_journal_flush(journal_t *journal)
1598 J_ASSERT(!journal->j_checkpoint_transactions); 1601 J_ASSERT(!journal->j_checkpoint_transactions);
1599 J_ASSERT(journal->j_head == journal->j_tail); 1602 J_ASSERT(journal->j_head == journal->j_tail);
1600 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence); 1603 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
1601 spin_unlock(&journal->j_state_lock); 1604 write_unlock(&journal->j_state_lock);
1602 return 0; 1605 return 0;
1603} 1606}
1604 1607
@@ -1617,7 +1620,6 @@ int jbd2_journal_flush(journal_t *journal)
1617 1620
1618int jbd2_journal_wipe(journal_t *journal, int write) 1621int jbd2_journal_wipe(journal_t *journal, int write)
1619{ 1622{
1620 journal_superblock_t *sb;
1621 int err = 0; 1623 int err = 0;
1622 1624
1623 J_ASSERT (!(journal->j_flags & JBD2_LOADED)); 1625 J_ASSERT (!(journal->j_flags & JBD2_LOADED));
@@ -1626,8 +1628,6 @@ int jbd2_journal_wipe(journal_t *journal, int write)
1626 if (err) 1628 if (err)
1627 return err; 1629 return err;
1628 1630
1629 sb = journal->j_superblock;
1630
1631 if (!journal->j_tail) 1631 if (!journal->j_tail)
1632 goto no_recovery; 1632 goto no_recovery;
1633 1633
@@ -1665,12 +1665,12 @@ void __jbd2_journal_abort_hard(journal_t *journal)
1665 printk(KERN_ERR "Aborting journal on device %s.\n", 1665 printk(KERN_ERR "Aborting journal on device %s.\n",
1666 journal->j_devname); 1666 journal->j_devname);
1667 1667
1668 spin_lock(&journal->j_state_lock); 1668 write_lock(&journal->j_state_lock);
1669 journal->j_flags |= JBD2_ABORT; 1669 journal->j_flags |= JBD2_ABORT;
1670 transaction = journal->j_running_transaction; 1670 transaction = journal->j_running_transaction;
1671 if (transaction) 1671 if (transaction)
1672 __jbd2_log_start_commit(journal, transaction->t_tid); 1672 __jbd2_log_start_commit(journal, transaction->t_tid);
1673 spin_unlock(&journal->j_state_lock); 1673 write_unlock(&journal->j_state_lock);
1674} 1674}
1675 1675
1676/* Soft abort: record the abort error status in the journal superblock, 1676/* Soft abort: record the abort error status in the journal superblock,
@@ -1755,12 +1755,12 @@ int jbd2_journal_errno(journal_t *journal)
1755{ 1755{
1756 int err; 1756 int err;
1757 1757
1758 spin_lock(&journal->j_state_lock); 1758 read_lock(&journal->j_state_lock);
1759 if (journal->j_flags & JBD2_ABORT) 1759 if (journal->j_flags & JBD2_ABORT)
1760 err = -EROFS; 1760 err = -EROFS;
1761 else 1761 else
1762 err = journal->j_errno; 1762 err = journal->j_errno;
1763 spin_unlock(&journal->j_state_lock); 1763 read_unlock(&journal->j_state_lock);
1764 return err; 1764 return err;
1765} 1765}
1766 1766
@@ -1775,12 +1775,12 @@ int jbd2_journal_clear_err(journal_t *journal)
1775{ 1775{
1776 int err = 0; 1776 int err = 0;
1777 1777
1778 spin_lock(&journal->j_state_lock); 1778 write_lock(&journal->j_state_lock);
1779 if (journal->j_flags & JBD2_ABORT) 1779 if (journal->j_flags & JBD2_ABORT)
1780 err = -EROFS; 1780 err = -EROFS;
1781 else 1781 else
1782 journal->j_errno = 0; 1782 journal->j_errno = 0;
1783 spin_unlock(&journal->j_state_lock); 1783 write_unlock(&journal->j_state_lock);
1784 return err; 1784 return err;
1785} 1785}
1786 1786
@@ -1793,10 +1793,10 @@ int jbd2_journal_clear_err(journal_t *journal)
1793 */ 1793 */
1794void jbd2_journal_ack_err(journal_t *journal) 1794void jbd2_journal_ack_err(journal_t *journal)
1795{ 1795{
1796 spin_lock(&journal->j_state_lock); 1796 write_lock(&journal->j_state_lock);
1797 if (journal->j_errno) 1797 if (journal->j_errno)
1798 journal->j_flags |= JBD2_ACK_ERR; 1798 journal->j_flags |= JBD2_ACK_ERR;
1799 spin_unlock(&journal->j_state_lock); 1799 write_unlock(&journal->j_state_lock);
1800} 1800}
1801 1801
1802int jbd2_journal_blocks_per_page(struct inode *inode) 1802int jbd2_journal_blocks_per_page(struct inode *inode)
@@ -2201,8 +2201,6 @@ void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
2201void jbd2_journal_release_jbd_inode(journal_t *journal, 2201void jbd2_journal_release_jbd_inode(journal_t *journal,
2202 struct jbd2_inode *jinode) 2202 struct jbd2_inode *jinode)
2203{ 2203{
2204 int writeout = 0;
2205
2206 if (!journal) 2204 if (!journal)
2207 return; 2205 return;
2208restart: 2206restart:
@@ -2219,9 +2217,6 @@ restart:
2219 goto restart; 2217 goto restart;
2220 } 2218 }
2221 2219
2222 /* Do we need to wait for data writeback? */
2223 if (journal->j_committing_transaction == jinode->i_transaction)
2224 writeout = 1;
2225 if (jinode->i_transaction) { 2220 if (jinode->i_transaction) {
2226 list_del(&jinode->i_list); 2221 list_del(&jinode->i_list);
2227 jinode->i_transaction = NULL; 2222 jinode->i_transaction = NULL;
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 049281b7cb89..2bc4d5f116f1 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -285,12 +285,10 @@ int jbd2_journal_recover(journal_t *journal)
285int jbd2_journal_skip_recovery(journal_t *journal) 285int jbd2_journal_skip_recovery(journal_t *journal)
286{ 286{
287 int err; 287 int err;
288 journal_superblock_t * sb;
289 288
290 struct recovery_info info; 289 struct recovery_info info;
291 290
292 memset (&info, 0, sizeof(info)); 291 memset (&info, 0, sizeof(info));
293 sb = journal->j_superblock;
294 292
295 err = do_one_pass(journal, &info, PASS_SCAN); 293 err = do_one_pass(journal, &info, PASS_SCAN);
296 294
@@ -299,7 +297,8 @@ int jbd2_journal_skip_recovery(journal_t *journal)
299 ++journal->j_transaction_sequence; 297 ++journal->j_transaction_sequence;
300 } else { 298 } else {
301#ifdef CONFIG_JBD2_DEBUG 299#ifdef CONFIG_JBD2_DEBUG
302 int dropped = info.end_transaction - be32_to_cpu(sb->s_sequence); 300 int dropped = info.end_transaction -
301 be32_to_cpu(journal->j_superblock->s_sequence);
303#endif 302#endif
304 jbd_debug(1, 303 jbd_debug(1,
305 "JBD: ignoring %d transaction%s from the journal.\n", 304 "JBD: ignoring %d transaction%s from the journal.\n",
@@ -365,11 +364,6 @@ static int do_one_pass(journal_t *journal,
365 int tag_bytes = journal_tag_bytes(journal); 364 int tag_bytes = journal_tag_bytes(journal);
366 __u32 crc32_sum = ~0; /* Transactional Checksums */ 365 __u32 crc32_sum = ~0; /* Transactional Checksums */
367 366
368 /* Precompute the maximum metadata descriptors in a descriptor block */
369 int MAX_BLOCKS_PER_DESC;
370 MAX_BLOCKS_PER_DESC = ((journal->j_blocksize-sizeof(journal_header_t))
371 / tag_bytes);
372
373 /* 367 /*
374 * First thing is to establish what we expect to find in the log 368 * First thing is to establish what we expect to find in the log
375 * (in terms of transaction IDs), and where (in terms of log 369 * (in terms of transaction IDs), and where (in terms of log
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index b8e0806681bb..d95cc9d0401d 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -26,6 +26,8 @@
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/highmem.h> 27#include <linux/highmem.h>
28#include <linux/hrtimer.h> 28#include <linux/hrtimer.h>
29#include <linux/backing-dev.h>
30#include <linux/module.h>
29 31
30static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh); 32static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh);
31 33
@@ -53,6 +55,9 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
53 transaction->t_tid = journal->j_transaction_sequence++; 55 transaction->t_tid = journal->j_transaction_sequence++;
54 transaction->t_expires = jiffies + journal->j_commit_interval; 56 transaction->t_expires = jiffies + journal->j_commit_interval;
55 spin_lock_init(&transaction->t_handle_lock); 57 spin_lock_init(&transaction->t_handle_lock);
58 atomic_set(&transaction->t_updates, 0);
59 atomic_set(&transaction->t_outstanding_credits, 0);
60 atomic_set(&transaction->t_handle_count, 0);
56 INIT_LIST_HEAD(&transaction->t_inode_list); 61 INIT_LIST_HEAD(&transaction->t_inode_list);
57 INIT_LIST_HEAD(&transaction->t_private_list); 62 INIT_LIST_HEAD(&transaction->t_private_list);
58 63
@@ -83,65 +88,75 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
83 * transaction's buffer credits. 88 * transaction's buffer credits.
84 */ 89 */
85 90
86static int start_this_handle(journal_t *journal, handle_t *handle) 91static int start_this_handle(journal_t *journal, handle_t *handle,
92 int gfp_mask)
87{ 93{
88 transaction_t *transaction; 94 transaction_t *transaction;
89 int needed; 95 int needed;
90 int nblocks = handle->h_buffer_credits; 96 int nblocks = handle->h_buffer_credits;
91 transaction_t *new_transaction = NULL; 97 transaction_t *new_transaction = NULL;
92 int ret = 0;
93 unsigned long ts = jiffies; 98 unsigned long ts = jiffies;
94 99
95 if (nblocks > journal->j_max_transaction_buffers) { 100 if (nblocks > journal->j_max_transaction_buffers) {
96 printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n", 101 printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n",
97 current->comm, nblocks, 102 current->comm, nblocks,
98 journal->j_max_transaction_buffers); 103 journal->j_max_transaction_buffers);
99 ret = -ENOSPC; 104 return -ENOSPC;
100 goto out;
101 } 105 }
102 106
103alloc_transaction: 107alloc_transaction:
104 if (!journal->j_running_transaction) { 108 if (!journal->j_running_transaction) {
105 new_transaction = kzalloc(sizeof(*new_transaction), 109 new_transaction = kzalloc(sizeof(*new_transaction), gfp_mask);
106 GFP_NOFS|__GFP_NOFAIL);
107 if (!new_transaction) { 110 if (!new_transaction) {
108 ret = -ENOMEM; 111 /*
109 goto out; 112 * If __GFP_FS is not present, then we may be
113 * being called from inside the fs writeback
114 * layer, so we MUST NOT fail. Since
115 * __GFP_NOFAIL is going away, we will arrange
116 * to retry the allocation ourselves.
117 */
118 if ((gfp_mask & __GFP_FS) == 0) {
119 congestion_wait(BLK_RW_ASYNC, HZ/50);
120 goto alloc_transaction;
121 }
122 return -ENOMEM;
110 } 123 }
111 } 124 }
112 125
113 jbd_debug(3, "New handle %p going live.\n", handle); 126 jbd_debug(3, "New handle %p going live.\n", handle);
114 127
115repeat:
116
117 /* 128 /*
118 * We need to hold j_state_lock until t_updates has been incremented, 129 * We need to hold j_state_lock until t_updates has been incremented,
119 * for proper journal barrier handling 130 * for proper journal barrier handling
120 */ 131 */
121 spin_lock(&journal->j_state_lock); 132repeat:
122repeat_locked: 133 read_lock(&journal->j_state_lock);
123 if (is_journal_aborted(journal) || 134 if (is_journal_aborted(journal) ||
124 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { 135 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) {
125 spin_unlock(&journal->j_state_lock); 136 read_unlock(&journal->j_state_lock);
126 ret = -EROFS; 137 kfree(new_transaction);
127 goto out; 138 return -EROFS;
128 } 139 }
129 140
130 /* Wait on the journal's transaction barrier if necessary */ 141 /* Wait on the journal's transaction barrier if necessary */
131 if (journal->j_barrier_count) { 142 if (journal->j_barrier_count) {
132 spin_unlock(&journal->j_state_lock); 143 read_unlock(&journal->j_state_lock);
133 wait_event(journal->j_wait_transaction_locked, 144 wait_event(journal->j_wait_transaction_locked,
134 journal->j_barrier_count == 0); 145 journal->j_barrier_count == 0);
135 goto repeat; 146 goto repeat;
136 } 147 }
137 148
138 if (!journal->j_running_transaction) { 149 if (!journal->j_running_transaction) {
139 if (!new_transaction) { 150 read_unlock(&journal->j_state_lock);
140 spin_unlock(&journal->j_state_lock); 151 if (!new_transaction)
141 goto alloc_transaction; 152 goto alloc_transaction;
153 write_lock(&journal->j_state_lock);
154 if (!journal->j_running_transaction) {
155 jbd2_get_transaction(journal, new_transaction);
156 new_transaction = NULL;
142 } 157 }
143 jbd2_get_transaction(journal, new_transaction); 158 write_unlock(&journal->j_state_lock);
144 new_transaction = NULL; 159 goto repeat;
145 } 160 }
146 161
147 transaction = journal->j_running_transaction; 162 transaction = journal->j_running_transaction;
@@ -155,7 +170,7 @@ repeat_locked:
155 170
156 prepare_to_wait(&journal->j_wait_transaction_locked, 171 prepare_to_wait(&journal->j_wait_transaction_locked,
157 &wait, TASK_UNINTERRUPTIBLE); 172 &wait, TASK_UNINTERRUPTIBLE);
158 spin_unlock(&journal->j_state_lock); 173 read_unlock(&journal->j_state_lock);
159 schedule(); 174 schedule();
160 finish_wait(&journal->j_wait_transaction_locked, &wait); 175 finish_wait(&journal->j_wait_transaction_locked, &wait);
161 goto repeat; 176 goto repeat;
@@ -166,8 +181,8 @@ repeat_locked:
166 * buffers requested by this operation, we need to stall pending a log 181 * buffers requested by this operation, we need to stall pending a log
167 * checkpoint to free some more log space. 182 * checkpoint to free some more log space.
168 */ 183 */
169 spin_lock(&transaction->t_handle_lock); 184 needed = atomic_add_return(nblocks,
170 needed = transaction->t_outstanding_credits + nblocks; 185 &transaction->t_outstanding_credits);
171 186
172 if (needed > journal->j_max_transaction_buffers) { 187 if (needed > journal->j_max_transaction_buffers) {
173 /* 188 /*
@@ -178,11 +193,11 @@ repeat_locked:
178 DEFINE_WAIT(wait); 193 DEFINE_WAIT(wait);
179 194
180 jbd_debug(2, "Handle %p starting new commit...\n", handle); 195 jbd_debug(2, "Handle %p starting new commit...\n", handle);
181 spin_unlock(&transaction->t_handle_lock); 196 atomic_sub(nblocks, &transaction->t_outstanding_credits);
182 prepare_to_wait(&journal->j_wait_transaction_locked, &wait, 197 prepare_to_wait(&journal->j_wait_transaction_locked, &wait,
183 TASK_UNINTERRUPTIBLE); 198 TASK_UNINTERRUPTIBLE);
184 __jbd2_log_start_commit(journal, transaction->t_tid); 199 __jbd2_log_start_commit(journal, transaction->t_tid);
185 spin_unlock(&journal->j_state_lock); 200 read_unlock(&journal->j_state_lock);
186 schedule(); 201 schedule();
187 finish_wait(&journal->j_wait_transaction_locked, &wait); 202 finish_wait(&journal->j_wait_transaction_locked, &wait);
188 goto repeat; 203 goto repeat;
@@ -215,35 +230,48 @@ repeat_locked:
215 */ 230 */
216 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) { 231 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) {
217 jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle); 232 jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle);
218 spin_unlock(&transaction->t_handle_lock); 233 atomic_sub(nblocks, &transaction->t_outstanding_credits);
219 __jbd2_log_wait_for_space(journal); 234 read_unlock(&journal->j_state_lock);
220 goto repeat_locked; 235 write_lock(&journal->j_state_lock);
236 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal))
237 __jbd2_log_wait_for_space(journal);
238 write_unlock(&journal->j_state_lock);
239 goto repeat;
221 } 240 }
222 241
223 /* OK, account for the buffers that this operation expects to 242 /* OK, account for the buffers that this operation expects to
224 * use and add the handle to the running transaction. */ 243 * use and add the handle to the running transaction.
225 244 *
226 if (time_after(transaction->t_start, ts)) { 245 * In order for t_max_wait to be reliable, it must be
246 * protected by a lock. But doing so will mean that
247 * start_this_handle() can not be run in parallel on SMP
248 * systems, which limits our scalability. So we only enable
249 * it when debugging is enabled. We may want to use a
250 * separate flag, eventually, so we can enable this
251 * independently of debugging.
252 */
253#ifdef CONFIG_JBD2_DEBUG
254 if (jbd2_journal_enable_debug &&
255 time_after(transaction->t_start, ts)) {
227 ts = jbd2_time_diff(ts, transaction->t_start); 256 ts = jbd2_time_diff(ts, transaction->t_start);
257 spin_lock(&transaction->t_handle_lock);
228 if (ts > transaction->t_max_wait) 258 if (ts > transaction->t_max_wait)
229 transaction->t_max_wait = ts; 259 transaction->t_max_wait = ts;
260 spin_unlock(&transaction->t_handle_lock);
230 } 261 }
231 262#endif
232 handle->h_transaction = transaction; 263 handle->h_transaction = transaction;
233 transaction->t_outstanding_credits += nblocks; 264 atomic_inc(&transaction->t_updates);
234 transaction->t_updates++; 265 atomic_inc(&transaction->t_handle_count);
235 transaction->t_handle_count++;
236 jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n", 266 jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n",
237 handle, nblocks, transaction->t_outstanding_credits, 267 handle, nblocks,
268 atomic_read(&transaction->t_outstanding_credits),
238 __jbd2_log_space_left(journal)); 269 __jbd2_log_space_left(journal));
239 spin_unlock(&transaction->t_handle_lock); 270 read_unlock(&journal->j_state_lock);
240 spin_unlock(&journal->j_state_lock);
241 271
242 lock_map_acquire(&handle->h_lockdep_map); 272 lock_map_acquire(&handle->h_lockdep_map);
243out: 273 kfree(new_transaction);
244 if (unlikely(new_transaction)) /* It's usually NULL */ 274 return 0;
245 kfree(new_transaction);
246 return ret;
247} 275}
248 276
249static struct lock_class_key jbd2_handle_key; 277static struct lock_class_key jbd2_handle_key;
@@ -278,7 +306,7 @@ static handle_t *new_handle(int nblocks)
278 * 306 *
279 * Return a pointer to a newly allocated handle, or NULL on failure 307 * Return a pointer to a newly allocated handle, or NULL on failure
280 */ 308 */
281handle_t *jbd2_journal_start(journal_t *journal, int nblocks) 309handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int gfp_mask)
282{ 310{
283 handle_t *handle = journal_current_handle(); 311 handle_t *handle = journal_current_handle();
284 int err; 312 int err;
@@ -298,7 +326,7 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
298 326
299 current->journal_info = handle; 327 current->journal_info = handle;
300 328
301 err = start_this_handle(journal, handle); 329 err = start_this_handle(journal, handle, gfp_mask);
302 if (err < 0) { 330 if (err < 0) {
303 jbd2_free_handle(handle); 331 jbd2_free_handle(handle);
304 current->journal_info = NULL; 332 current->journal_info = NULL;
@@ -308,6 +336,15 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
308out: 336out:
309 return handle; 337 return handle;
310} 338}
339EXPORT_SYMBOL(jbd2__journal_start);
340
341
342handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
343{
344 return jbd2__journal_start(journal, nblocks, GFP_NOFS);
345}
346EXPORT_SYMBOL(jbd2_journal_start);
347
311 348
312/** 349/**
313 * int jbd2_journal_extend() - extend buffer credits. 350 * int jbd2_journal_extend() - extend buffer credits.
@@ -342,7 +379,7 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
342 379
343 result = 1; 380 result = 1;
344 381
345 spin_lock(&journal->j_state_lock); 382 read_lock(&journal->j_state_lock);
346 383
347 /* Don't extend a locked-down transaction! */ 384 /* Don't extend a locked-down transaction! */
348 if (handle->h_transaction->t_state != T_RUNNING) { 385 if (handle->h_transaction->t_state != T_RUNNING) {
@@ -352,7 +389,7 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
352 } 389 }
353 390
354 spin_lock(&transaction->t_handle_lock); 391 spin_lock(&transaction->t_handle_lock);
355 wanted = transaction->t_outstanding_credits + nblocks; 392 wanted = atomic_read(&transaction->t_outstanding_credits) + nblocks;
356 393
357 if (wanted > journal->j_max_transaction_buffers) { 394 if (wanted > journal->j_max_transaction_buffers) {
358 jbd_debug(3, "denied handle %p %d blocks: " 395 jbd_debug(3, "denied handle %p %d blocks: "
@@ -367,14 +404,14 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
367 } 404 }
368 405
369 handle->h_buffer_credits += nblocks; 406 handle->h_buffer_credits += nblocks;
370 transaction->t_outstanding_credits += nblocks; 407 atomic_add(nblocks, &transaction->t_outstanding_credits);
371 result = 0; 408 result = 0;
372 409
373 jbd_debug(3, "extended handle %p by %d\n", handle, nblocks); 410 jbd_debug(3, "extended handle %p by %d\n", handle, nblocks);
374unlock: 411unlock:
375 spin_unlock(&transaction->t_handle_lock); 412 spin_unlock(&transaction->t_handle_lock);
376error_out: 413error_out:
377 spin_unlock(&journal->j_state_lock); 414 read_unlock(&journal->j_state_lock);
378out: 415out:
379 return result; 416 return result;
380} 417}
@@ -394,8 +431,7 @@ out:
394 * transaction capabable of guaranteeing the requested number of 431 * transaction capabable of guaranteeing the requested number of
395 * credits. 432 * credits.
396 */ 433 */
397 434int jbd2__journal_restart(handle_t *handle, int nblocks, int gfp_mask)
398int jbd2_journal_restart(handle_t *handle, int nblocks)
399{ 435{
400 transaction_t *transaction = handle->h_transaction; 436 transaction_t *transaction = handle->h_transaction;
401 journal_t *journal = transaction->t_journal; 437 journal_t *journal = transaction->t_journal;
@@ -410,29 +446,35 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
410 * First unlink the handle from its current transaction, and start the 446 * First unlink the handle from its current transaction, and start the
411 * commit on that. 447 * commit on that.
412 */ 448 */
413 J_ASSERT(transaction->t_updates > 0); 449 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
414 J_ASSERT(journal_current_handle() == handle); 450 J_ASSERT(journal_current_handle() == handle);
415 451
416 spin_lock(&journal->j_state_lock); 452 read_lock(&journal->j_state_lock);
417 spin_lock(&transaction->t_handle_lock); 453 spin_lock(&transaction->t_handle_lock);
418 transaction->t_outstanding_credits -= handle->h_buffer_credits; 454 atomic_sub(handle->h_buffer_credits,
419 transaction->t_updates--; 455 &transaction->t_outstanding_credits);
420 456 if (atomic_dec_and_test(&transaction->t_updates))
421 if (!transaction->t_updates)
422 wake_up(&journal->j_wait_updates); 457 wake_up(&journal->j_wait_updates);
423 spin_unlock(&transaction->t_handle_lock); 458 spin_unlock(&transaction->t_handle_lock);
424 459
425 jbd_debug(2, "restarting handle %p\n", handle); 460 jbd_debug(2, "restarting handle %p\n", handle);
426 __jbd2_log_start_commit(journal, transaction->t_tid); 461 __jbd2_log_start_commit(journal, transaction->t_tid);
427 spin_unlock(&journal->j_state_lock); 462 read_unlock(&journal->j_state_lock);
428 463
429 lock_map_release(&handle->h_lockdep_map); 464 lock_map_release(&handle->h_lockdep_map);
430 handle->h_buffer_credits = nblocks; 465 handle->h_buffer_credits = nblocks;
431 ret = start_this_handle(journal, handle); 466 ret = start_this_handle(journal, handle, gfp_mask);
432 return ret; 467 return ret;
433} 468}
469EXPORT_SYMBOL(jbd2__journal_restart);
434 470
435 471
472int jbd2_journal_restart(handle_t *handle, int nblocks)
473{
474 return jbd2__journal_restart(handle, nblocks, GFP_NOFS);
475}
476EXPORT_SYMBOL(jbd2_journal_restart);
477
436/** 478/**
437 * void jbd2_journal_lock_updates () - establish a transaction barrier. 479 * void jbd2_journal_lock_updates () - establish a transaction barrier.
438 * @journal: Journal to establish a barrier on. 480 * @journal: Journal to establish a barrier on.
@@ -447,7 +489,7 @@ void jbd2_journal_lock_updates(journal_t *journal)
447{ 489{
448 DEFINE_WAIT(wait); 490 DEFINE_WAIT(wait);
449 491
450 spin_lock(&journal->j_state_lock); 492 write_lock(&journal->j_state_lock);
451 ++journal->j_barrier_count; 493 ++journal->j_barrier_count;
452 494
453 /* Wait until there are no running updates */ 495 /* Wait until there are no running updates */
@@ -458,19 +500,19 @@ void jbd2_journal_lock_updates(journal_t *journal)
458 break; 500 break;
459 501
460 spin_lock(&transaction->t_handle_lock); 502 spin_lock(&transaction->t_handle_lock);
461 if (!transaction->t_updates) { 503 if (!atomic_read(&transaction->t_updates)) {
462 spin_unlock(&transaction->t_handle_lock); 504 spin_unlock(&transaction->t_handle_lock);
463 break; 505 break;
464 } 506 }
465 prepare_to_wait(&journal->j_wait_updates, &wait, 507 prepare_to_wait(&journal->j_wait_updates, &wait,
466 TASK_UNINTERRUPTIBLE); 508 TASK_UNINTERRUPTIBLE);
467 spin_unlock(&transaction->t_handle_lock); 509 spin_unlock(&transaction->t_handle_lock);
468 spin_unlock(&journal->j_state_lock); 510 write_unlock(&journal->j_state_lock);
469 schedule(); 511 schedule();
470 finish_wait(&journal->j_wait_updates, &wait); 512 finish_wait(&journal->j_wait_updates, &wait);
471 spin_lock(&journal->j_state_lock); 513 write_lock(&journal->j_state_lock);
472 } 514 }
473 spin_unlock(&journal->j_state_lock); 515 write_unlock(&journal->j_state_lock);
474 516
475 /* 517 /*
476 * We have now established a barrier against other normal updates, but 518 * We have now established a barrier against other normal updates, but
@@ -494,9 +536,9 @@ void jbd2_journal_unlock_updates (journal_t *journal)
494 J_ASSERT(journal->j_barrier_count != 0); 536 J_ASSERT(journal->j_barrier_count != 0);
495 537
496 mutex_unlock(&journal->j_barrier); 538 mutex_unlock(&journal->j_barrier);
497 spin_lock(&journal->j_state_lock); 539 write_lock(&journal->j_state_lock);
498 --journal->j_barrier_count; 540 --journal->j_barrier_count;
499 spin_unlock(&journal->j_state_lock); 541 write_unlock(&journal->j_state_lock);
500 wake_up(&journal->j_wait_transaction_locked); 542 wake_up(&journal->j_wait_transaction_locked);
501} 543}
502 544
@@ -1238,7 +1280,8 @@ int jbd2_journal_stop(handle_t *handle)
1238{ 1280{
1239 transaction_t *transaction = handle->h_transaction; 1281 transaction_t *transaction = handle->h_transaction;
1240 journal_t *journal = transaction->t_journal; 1282 journal_t *journal = transaction->t_journal;
1241 int err; 1283 int err, wait_for_commit = 0;
1284 tid_t tid;
1242 pid_t pid; 1285 pid_t pid;
1243 1286
1244 J_ASSERT(journal_current_handle() == handle); 1287 J_ASSERT(journal_current_handle() == handle);
@@ -1246,7 +1289,7 @@ int jbd2_journal_stop(handle_t *handle)
1246 if (is_handle_aborted(handle)) 1289 if (is_handle_aborted(handle))
1247 err = -EIO; 1290 err = -EIO;
1248 else { 1291 else {
1249 J_ASSERT(transaction->t_updates > 0); 1292 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
1250 err = 0; 1293 err = 0;
1251 } 1294 }
1252 1295
@@ -1291,9 +1334,9 @@ int jbd2_journal_stop(handle_t *handle)
1291 1334
1292 journal->j_last_sync_writer = pid; 1335 journal->j_last_sync_writer = pid;
1293 1336
1294 spin_lock(&journal->j_state_lock); 1337 read_lock(&journal->j_state_lock);
1295 commit_time = journal->j_average_commit_time; 1338 commit_time = journal->j_average_commit_time;
1296 spin_unlock(&journal->j_state_lock); 1339 read_unlock(&journal->j_state_lock);
1297 1340
1298 trans_time = ktime_to_ns(ktime_sub(ktime_get(), 1341 trans_time = ktime_to_ns(ktime_sub(ktime_get(),
1299 transaction->t_start_time)); 1342 transaction->t_start_time));
@@ -1314,14 +1357,8 @@ int jbd2_journal_stop(handle_t *handle)
1314 if (handle->h_sync) 1357 if (handle->h_sync)
1315 transaction->t_synchronous_commit = 1; 1358 transaction->t_synchronous_commit = 1;
1316 current->journal_info = NULL; 1359 current->journal_info = NULL;
1317 spin_lock(&transaction->t_handle_lock); 1360 atomic_sub(handle->h_buffer_credits,
1318 transaction->t_outstanding_credits -= handle->h_buffer_credits; 1361 &transaction->t_outstanding_credits);
1319 transaction->t_updates--;
1320 if (!transaction->t_updates) {
1321 wake_up(&journal->j_wait_updates);
1322 if (journal->j_barrier_count)
1323 wake_up(&journal->j_wait_transaction_locked);
1324 }
1325 1362
1326 /* 1363 /*
1327 * If the handle is marked SYNC, we need to set another commit 1364 * If the handle is marked SYNC, we need to set another commit
@@ -1330,15 +1367,13 @@ int jbd2_journal_stop(handle_t *handle)
1330 * transaction is too old now. 1367 * transaction is too old now.
1331 */ 1368 */
1332 if (handle->h_sync || 1369 if (handle->h_sync ||
1333 transaction->t_outstanding_credits > 1370 (atomic_read(&transaction->t_outstanding_credits) >
1334 journal->j_max_transaction_buffers || 1371 journal->j_max_transaction_buffers) ||
1335 time_after_eq(jiffies, transaction->t_expires)) { 1372 time_after_eq(jiffies, transaction->t_expires)) {
1336 /* Do this even for aborted journals: an abort still 1373 /* Do this even for aborted journals: an abort still
1337 * completes the commit thread, it just doesn't write 1374 * completes the commit thread, it just doesn't write
1338 * anything to disk. */ 1375 * anything to disk. */
1339 tid_t tid = transaction->t_tid;
1340 1376
1341 spin_unlock(&transaction->t_handle_lock);
1342 jbd_debug(2, "transaction too old, requesting commit for " 1377 jbd_debug(2, "transaction too old, requesting commit for "
1343 "handle %p\n", handle); 1378 "handle %p\n", handle);
1344 /* This is non-blocking */ 1379 /* This is non-blocking */
@@ -1349,11 +1384,25 @@ int jbd2_journal_stop(handle_t *handle)
1349 * to wait for the commit to complete. 1384 * to wait for the commit to complete.
1350 */ 1385 */
1351 if (handle->h_sync && !(current->flags & PF_MEMALLOC)) 1386 if (handle->h_sync && !(current->flags & PF_MEMALLOC))
1352 err = jbd2_log_wait_commit(journal, tid); 1387 wait_for_commit = 1;
1353 } else {
1354 spin_unlock(&transaction->t_handle_lock);
1355 } 1388 }
1356 1389
1390 /*
1391 * Once we drop t_updates, if it goes to zero the transaction
1392 * could start commiting on us and eventually disappear. So
1393 * once we do this, we must not dereference transaction
1394 * pointer again.
1395 */
1396 tid = transaction->t_tid;
1397 if (atomic_dec_and_test(&transaction->t_updates)) {
1398 wake_up(&journal->j_wait_updates);
1399 if (journal->j_barrier_count)
1400 wake_up(&journal->j_wait_transaction_locked);
1401 }
1402
1403 if (wait_for_commit)
1404 err = jbd2_log_wait_commit(journal, tid);
1405
1357 lock_map_release(&handle->h_lockdep_map); 1406 lock_map_release(&handle->h_lockdep_map);
1358 1407
1359 jbd2_free_handle(handle); 1408 jbd2_free_handle(handle);
@@ -1719,7 +1768,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1719 goto zap_buffer_unlocked; 1768 goto zap_buffer_unlocked;
1720 1769
1721 /* OK, we have data buffer in journaled mode */ 1770 /* OK, we have data buffer in journaled mode */
1722 spin_lock(&journal->j_state_lock); 1771 write_lock(&journal->j_state_lock);
1723 jbd_lock_bh_state(bh); 1772 jbd_lock_bh_state(bh);
1724 spin_lock(&journal->j_list_lock); 1773 spin_lock(&journal->j_list_lock);
1725 1774
@@ -1772,7 +1821,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1772 jbd2_journal_put_journal_head(jh); 1821 jbd2_journal_put_journal_head(jh);
1773 spin_unlock(&journal->j_list_lock); 1822 spin_unlock(&journal->j_list_lock);
1774 jbd_unlock_bh_state(bh); 1823 jbd_unlock_bh_state(bh);
1775 spin_unlock(&journal->j_state_lock); 1824 write_unlock(&journal->j_state_lock);
1776 return ret; 1825 return ret;
1777 } else { 1826 } else {
1778 /* There is no currently-running transaction. So the 1827 /* There is no currently-running transaction. So the
@@ -1786,7 +1835,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1786 jbd2_journal_put_journal_head(jh); 1835 jbd2_journal_put_journal_head(jh);
1787 spin_unlock(&journal->j_list_lock); 1836 spin_unlock(&journal->j_list_lock);
1788 jbd_unlock_bh_state(bh); 1837 jbd_unlock_bh_state(bh);
1789 spin_unlock(&journal->j_state_lock); 1838 write_unlock(&journal->j_state_lock);
1790 return ret; 1839 return ret;
1791 } else { 1840 } else {
1792 /* The orphan record's transaction has 1841 /* The orphan record's transaction has
@@ -1810,7 +1859,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1810 jbd2_journal_put_journal_head(jh); 1859 jbd2_journal_put_journal_head(jh);
1811 spin_unlock(&journal->j_list_lock); 1860 spin_unlock(&journal->j_list_lock);
1812 jbd_unlock_bh_state(bh); 1861 jbd_unlock_bh_state(bh);
1813 spin_unlock(&journal->j_state_lock); 1862 write_unlock(&journal->j_state_lock);
1814 return 0; 1863 return 0;
1815 } else { 1864 } else {
1816 /* Good, the buffer belongs to the running transaction. 1865 /* Good, the buffer belongs to the running transaction.
@@ -1829,7 +1878,7 @@ zap_buffer:
1829zap_buffer_no_jh: 1878zap_buffer_no_jh:
1830 spin_unlock(&journal->j_list_lock); 1879 spin_unlock(&journal->j_list_lock);
1831 jbd_unlock_bh_state(bh); 1880 jbd_unlock_bh_state(bh);
1832 spin_unlock(&journal->j_state_lock); 1881 write_unlock(&journal->j_state_lock);
1833zap_buffer_unlocked: 1882zap_buffer_unlocked:
1834 clear_buffer_dirty(bh); 1883 clear_buffer_dirty(bh);
1835 J_ASSERT_BH(bh, !buffer_jbddirty(bh)); 1884 J_ASSERT_BH(bh, !buffer_jbddirty(bh));
@@ -2136,9 +2185,9 @@ int jbd2_journal_begin_ordered_truncate(journal_t *journal,
2136 /* Locks are here just to force reading of recent values, it is 2185 /* Locks are here just to force reading of recent values, it is
2137 * enough that the transaction was not committing before we started 2186 * enough that the transaction was not committing before we started
2138 * a transaction adding the inode to orphan list */ 2187 * a transaction adding the inode to orphan list */
2139 spin_lock(&journal->j_state_lock); 2188 read_lock(&journal->j_state_lock);
2140 commit_trans = journal->j_committing_transaction; 2189 commit_trans = journal->j_committing_transaction;
2141 spin_unlock(&journal->j_state_lock); 2190 read_unlock(&journal->j_state_lock);
2142 spin_lock(&journal->j_list_lock); 2191 spin_lock(&journal->j_list_lock);
2143 inode_trans = jinode->i_transaction; 2192 inode_trans = jinode->i_transaction;
2144 spin_unlock(&journal->j_list_lock); 2193 spin_unlock(&journal->j_list_lock);