aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-10-13 05:05:51 -0400
committerIngo Molnar <mingo@elte.hu>2008-10-13 05:05:51 -0400
commitaccba5f3965d6a9d1bf7c1e1a7995d17e9d521b6 (patch)
tree8fb40782e79472ed882ff2098d4dd295557278ee /fs/jbd2
parent6852fd9b86d05063c6ef49d2e12e061cc7f6a105 (diff)
parent4480f15b3306f43bbb0310d461142b4e897ca45b (diff)
Merge branch 'linus' into oprofile-v2
Conflicts: arch/x86/kernel/apic_32.c arch/x86/oprofile/nmi_int.c include/linux/pci_ids.h
Diffstat (limited to 'fs/jbd2')
-rw-r--r--fs/jbd2/checkpoint.c71
-rw-r--r--fs/jbd2/commit.c52
-rw-r--r--fs/jbd2/journal.c104
-rw-r--r--fs/jbd2/recovery.c7
-rw-r--r--fs/jbd2/transaction.c4
5 files changed, 165 insertions, 73 deletions
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 91389c8aee8a..9203c3332f17 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -20,6 +20,7 @@
20#include <linux/time.h> 20#include <linux/time.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/jbd2.h> 22#include <linux/jbd2.h>
23#include <linux/marker.h>
23#include <linux/errno.h> 24#include <linux/errno.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25 26
@@ -93,7 +94,8 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
93 int ret = 0; 94 int ret = 0;
94 struct buffer_head *bh = jh2bh(jh); 95 struct buffer_head *bh = jh2bh(jh);
95 96
96 if (jh->b_jlist == BJ_None && !buffer_locked(bh) && !buffer_dirty(bh)) { 97 if (jh->b_jlist == BJ_None && !buffer_locked(bh) &&
98 !buffer_dirty(bh) && !buffer_write_io_error(bh)) {
97 JBUFFER_TRACE(jh, "remove from checkpoint list"); 99 JBUFFER_TRACE(jh, "remove from checkpoint list");
98 ret = __jbd2_journal_remove_checkpoint(jh) + 1; 100 ret = __jbd2_journal_remove_checkpoint(jh) + 1;
99 jbd_unlock_bh_state(bh); 101 jbd_unlock_bh_state(bh);
@@ -126,14 +128,29 @@ void __jbd2_log_wait_for_space(journal_t *journal)
126 128
127 /* 129 /*
128 * Test again, another process may have checkpointed while we 130 * Test again, another process may have checkpointed while we
129 * were waiting for the checkpoint lock 131 * were waiting for the checkpoint lock. If there are no
132 * outstanding transactions there is nothing to checkpoint and
133 * we can't make progress. Abort the journal in this case.
130 */ 134 */
131 spin_lock(&journal->j_state_lock); 135 spin_lock(&journal->j_state_lock);
136 spin_lock(&journal->j_list_lock);
132 nblocks = jbd_space_needed(journal); 137 nblocks = jbd_space_needed(journal);
133 if (__jbd2_log_space_left(journal) < nblocks) { 138 if (__jbd2_log_space_left(journal) < nblocks) {
139 int chkpt = journal->j_checkpoint_transactions != NULL;
140
141 spin_unlock(&journal->j_list_lock);
134 spin_unlock(&journal->j_state_lock); 142 spin_unlock(&journal->j_state_lock);
135 jbd2_log_do_checkpoint(journal); 143 if (chkpt) {
144 jbd2_log_do_checkpoint(journal);
145 } else {
146 printk(KERN_ERR "%s: no transactions\n",
147 __func__);
148 jbd2_journal_abort(journal, 0);
149 }
150
136 spin_lock(&journal->j_state_lock); 151 spin_lock(&journal->j_state_lock);
152 } else {
153 spin_unlock(&journal->j_list_lock);
137 } 154 }
138 mutex_unlock(&journal->j_checkpoint_mutex); 155 mutex_unlock(&journal->j_checkpoint_mutex);
139 } 156 }
@@ -160,21 +177,25 @@ static void jbd_sync_bh(journal_t *journal, struct buffer_head *bh)
160 * buffers. Note that we take the buffers in the opposite ordering 177 * buffers. Note that we take the buffers in the opposite ordering
161 * from the one in which they were submitted for IO. 178 * from the one in which they were submitted for IO.
162 * 179 *
180 * Return 0 on success, and return <0 if some buffers have failed
181 * to be written out.
182 *
163 * Called with j_list_lock held. 183 * Called with j_list_lock held.
164 */ 184 */
165static void __wait_cp_io(journal_t *journal, transaction_t *transaction) 185static int __wait_cp_io(journal_t *journal, transaction_t *transaction)
166{ 186{
167 struct journal_head *jh; 187 struct journal_head *jh;
168 struct buffer_head *bh; 188 struct buffer_head *bh;
169 tid_t this_tid; 189 tid_t this_tid;
170 int released = 0; 190 int released = 0;
191 int ret = 0;
171 192
172 this_tid = transaction->t_tid; 193 this_tid = transaction->t_tid;
173restart: 194restart:
174 /* Did somebody clean up the transaction in the meanwhile? */ 195 /* Did somebody clean up the transaction in the meanwhile? */
175 if (journal->j_checkpoint_transactions != transaction || 196 if (journal->j_checkpoint_transactions != transaction ||
176 transaction->t_tid != this_tid) 197 transaction->t_tid != this_tid)
177 return; 198 return ret;
178 while (!released && transaction->t_checkpoint_io_list) { 199 while (!released && transaction->t_checkpoint_io_list) {
179 jh = transaction->t_checkpoint_io_list; 200 jh = transaction->t_checkpoint_io_list;
180 bh = jh2bh(jh); 201 bh = jh2bh(jh);
@@ -194,6 +215,9 @@ restart:
194 spin_lock(&journal->j_list_lock); 215 spin_lock(&journal->j_list_lock);
195 goto restart; 216 goto restart;
196 } 217 }
218 if (unlikely(buffer_write_io_error(bh)))
219 ret = -EIO;
220
197 /* 221 /*
198 * Now in whatever state the buffer currently is, we know that 222 * Now in whatever state the buffer currently is, we know that
199 * it has been written out and so we can drop it from the list 223 * it has been written out and so we can drop it from the list
@@ -203,6 +227,8 @@ restart:
203 jbd2_journal_remove_journal_head(bh); 227 jbd2_journal_remove_journal_head(bh);
204 __brelse(bh); 228 __brelse(bh);
205 } 229 }
230
231 return ret;
206} 232}
207 233
208#define NR_BATCH 64 234#define NR_BATCH 64
@@ -226,7 +252,8 @@ __flush_batch(journal_t *journal, struct buffer_head **bhs, int *batch_count)
226 * Try to flush one buffer from the checkpoint list to disk. 252 * Try to flush one buffer from the checkpoint list to disk.
227 * 253 *
228 * Return 1 if something happened which requires us to abort the current 254 * Return 1 if something happened which requires us to abort the current
229 * scan of the checkpoint list. 255 * scan of the checkpoint list. Return <0 if the buffer has failed to
256 * be written out.
230 * 257 *
231 * Called with j_list_lock held and drops it if 1 is returned 258 * Called with j_list_lock held and drops it if 1 is returned
232 * Called under jbd_lock_bh_state(jh2bh(jh)), and drops it 259 * Called under jbd_lock_bh_state(jh2bh(jh)), and drops it
@@ -258,6 +285,9 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh,
258 jbd2_log_wait_commit(journal, tid); 285 jbd2_log_wait_commit(journal, tid);
259 ret = 1; 286 ret = 1;
260 } else if (!buffer_dirty(bh)) { 287 } else if (!buffer_dirty(bh)) {
288 ret = 1;
289 if (unlikely(buffer_write_io_error(bh)))
290 ret = -EIO;
261 J_ASSERT_JH(jh, !buffer_jbddirty(bh)); 291 J_ASSERT_JH(jh, !buffer_jbddirty(bh));
262 BUFFER_TRACE(bh, "remove from checkpoint"); 292 BUFFER_TRACE(bh, "remove from checkpoint");
263 __jbd2_journal_remove_checkpoint(jh); 293 __jbd2_journal_remove_checkpoint(jh);
@@ -265,7 +295,6 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh,
265 jbd_unlock_bh_state(bh); 295 jbd_unlock_bh_state(bh);
266 jbd2_journal_remove_journal_head(bh); 296 jbd2_journal_remove_journal_head(bh);
267 __brelse(bh); 297 __brelse(bh);
268 ret = 1;
269 } else { 298 } else {
270 /* 299 /*
271 * Important: we are about to write the buffer, and 300 * Important: we are about to write the buffer, and
@@ -298,6 +327,7 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh,
298 * to disk. We submit larger chunks of data at once. 327 * to disk. We submit larger chunks of data at once.
299 * 328 *
300 * The journal should be locked before calling this function. 329 * The journal should be locked before calling this function.
330 * Called with j_checkpoint_mutex held.
301 */ 331 */
302int jbd2_log_do_checkpoint(journal_t *journal) 332int jbd2_log_do_checkpoint(journal_t *journal)
303{ 333{
@@ -313,6 +343,8 @@ int jbd2_log_do_checkpoint(journal_t *journal)
313 * journal straight away. 343 * journal straight away.
314 */ 344 */
315 result = jbd2_cleanup_journal_tail(journal); 345 result = jbd2_cleanup_journal_tail(journal);
346 trace_mark(jbd2_checkpoint, "dev %s need_checkpoint %d",
347 journal->j_devname, result);
316 jbd_debug(1, "cleanup_journal_tail returned %d\n", result); 348 jbd_debug(1, "cleanup_journal_tail returned %d\n", result);
317 if (result <= 0) 349 if (result <= 0)
318 return result; 350 return result;
@@ -321,6 +353,7 @@ int jbd2_log_do_checkpoint(journal_t *journal)
321 * OK, we need to start writing disk blocks. Take one transaction 353 * OK, we need to start writing disk blocks. Take one transaction
322 * and write it. 354 * and write it.
323 */ 355 */
356 result = 0;
324 spin_lock(&journal->j_list_lock); 357 spin_lock(&journal->j_list_lock);
325 if (!journal->j_checkpoint_transactions) 358 if (!journal->j_checkpoint_transactions)
326 goto out; 359 goto out;
@@ -339,7 +372,7 @@ restart:
339 int batch_count = 0; 372 int batch_count = 0;
340 struct buffer_head *bhs[NR_BATCH]; 373 struct buffer_head *bhs[NR_BATCH];
341 struct journal_head *jh; 374 struct journal_head *jh;
342 int retry = 0; 375 int retry = 0, err;
343 376
344 while (!retry && transaction->t_checkpoint_list) { 377 while (!retry && transaction->t_checkpoint_list) {
345 struct buffer_head *bh; 378 struct buffer_head *bh;
@@ -353,6 +386,8 @@ restart:
353 } 386 }
354 retry = __process_buffer(journal, jh, bhs, &batch_count, 387 retry = __process_buffer(journal, jh, bhs, &batch_count,
355 transaction); 388 transaction);
389 if (retry < 0 && !result)
390 result = retry;
356 if (!retry && (need_resched() || 391 if (!retry && (need_resched() ||
357 spin_needbreak(&journal->j_list_lock))) { 392 spin_needbreak(&journal->j_list_lock))) {
358 spin_unlock(&journal->j_list_lock); 393 spin_unlock(&journal->j_list_lock);
@@ -377,14 +412,18 @@ restart:
377 * Now we have cleaned up the first transaction's checkpoint 412 * Now we have cleaned up the first transaction's checkpoint
378 * list. Let's clean up the second one 413 * list. Let's clean up the second one
379 */ 414 */
380 __wait_cp_io(journal, transaction); 415 err = __wait_cp_io(journal, transaction);
416 if (!result)
417 result = err;
381 } 418 }
382out: 419out:
383 spin_unlock(&journal->j_list_lock); 420 spin_unlock(&journal->j_list_lock);
384 result = jbd2_cleanup_journal_tail(journal);
385 if (result < 0) 421 if (result < 0)
386 return result; 422 jbd2_journal_abort(journal, result);
387 return 0; 423 else
424 result = jbd2_cleanup_journal_tail(journal);
425
426 return (result < 0) ? result : 0;
388} 427}
389 428
390/* 429/*
@@ -400,8 +439,9 @@ out:
400 * This is the only part of the journaling code which really needs to be 439 * This is the only part of the journaling code which really needs to be
401 * aware of transaction aborts. Checkpointing involves writing to the 440 * aware of transaction aborts. Checkpointing involves writing to the
402 * main filesystem area rather than to the journal, so it can proceed 441 * main filesystem area rather than to the journal, so it can proceed
403 * even in abort state, but we must not update the journal superblock if 442 * even in abort state, but we must not update the super block if
404 * we have an abort error outstanding. 443 * checkpointing may have failed. Otherwise, we would lose some metadata
444 * buffers which should be written-back to the filesystem.
405 */ 445 */
406 446
407int jbd2_cleanup_journal_tail(journal_t *journal) 447int jbd2_cleanup_journal_tail(journal_t *journal)
@@ -410,6 +450,9 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
410 tid_t first_tid; 450 tid_t first_tid;
411 unsigned long blocknr, freed; 451 unsigned long blocknr, freed;
412 452
453 if (is_journal_aborted(journal))
454 return 1;
455
413 /* OK, work out the oldest transaction remaining in the log, and 456 /* OK, work out the oldest transaction remaining in the log, and
414 * the log block it starts at. 457 * the log block it starts at.
415 * 458 *
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index f8b3be873226..0abe02c4242a 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -16,6 +16,7 @@
16#include <linux/time.h> 16#include <linux/time.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/jbd2.h> 18#include <linux/jbd2.h>
19#include <linux/marker.h>
19#include <linux/errno.h> 20#include <linux/errno.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/mm.h> 22#include <linux/mm.h>
@@ -67,7 +68,7 @@ static void release_buffer_page(struct buffer_head *bh)
67 goto nope; 68 goto nope;
68 69
69 /* OK, it's a truncated page */ 70 /* OK, it's a truncated page */
70 if (TestSetPageLocked(page)) 71 if (!trylock_page(page))
71 goto nope; 72 goto nope;
72 73
73 page_cache_get(page); 74 page_cache_get(page);
@@ -126,8 +127,7 @@ static int journal_submit_commit_record(journal_t *journal,
126 127
127 JBUFFER_TRACE(descriptor, "submit commit block"); 128 JBUFFER_TRACE(descriptor, "submit commit block");
128 lock_buffer(bh); 129 lock_buffer(bh);
129 get_bh(bh); 130 clear_buffer_dirty(bh);
130 set_buffer_dirty(bh);
131 set_buffer_uptodate(bh); 131 set_buffer_uptodate(bh);
132 bh->b_end_io = journal_end_buffer_io_sync; 132 bh->b_end_io = journal_end_buffer_io_sync;
133 133
@@ -147,12 +147,9 @@ static int journal_submit_commit_record(journal_t *journal,
147 * to remember if we sent a barrier request 147 * to remember if we sent a barrier request
148 */ 148 */
149 if (ret == -EOPNOTSUPP && barrier_done) { 149 if (ret == -EOPNOTSUPP && barrier_done) {
150 char b[BDEVNAME_SIZE];
151
152 printk(KERN_WARNING 150 printk(KERN_WARNING
153 "JBD: barrier-based sync failed on %s - " 151 "JBD: barrier-based sync failed on %s - "
154 "disabling barriers\n", 152 "disabling barriers\n", journal->j_devname);
155 bdevname(journal->j_dev, b));
156 spin_lock(&journal->j_state_lock); 153 spin_lock(&journal->j_state_lock);
157 journal->j_flags &= ~JBD2_BARRIER; 154 journal->j_flags &= ~JBD2_BARRIER;
158 spin_unlock(&journal->j_state_lock); 155 spin_unlock(&journal->j_state_lock);
@@ -160,7 +157,7 @@ static int journal_submit_commit_record(journal_t *journal,
160 /* And try again, without the barrier */ 157 /* And try again, without the barrier */
161 lock_buffer(bh); 158 lock_buffer(bh);
162 set_buffer_uptodate(bh); 159 set_buffer_uptodate(bh);
163 set_buffer_dirty(bh); 160 clear_buffer_dirty(bh);
164 ret = submit_bh(WRITE, bh); 161 ret = submit_bh(WRITE, bh);
165 } 162 }
166 *cbh = bh; 163 *cbh = bh;
@@ -262,8 +259,18 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
262 jinode->i_flags |= JI_COMMIT_RUNNING; 259 jinode->i_flags |= JI_COMMIT_RUNNING;
263 spin_unlock(&journal->j_list_lock); 260 spin_unlock(&journal->j_list_lock);
264 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping); 261 err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
265 if (!ret) 262 if (err) {
266 ret = err; 263 /*
264 * Because AS_EIO is cleared by
265 * wait_on_page_writeback_range(), set it again so
266 * that user process can get -EIO from fsync().
267 */
268 set_bit(AS_EIO,
269 &jinode->i_vfs_inode->i_mapping->flags);
270
271 if (!ret)
272 ret = err;
273 }
267 spin_lock(&journal->j_list_lock); 274 spin_lock(&journal->j_list_lock);
268 jinode->i_flags &= ~JI_COMMIT_RUNNING; 275 jinode->i_flags &= ~JI_COMMIT_RUNNING;
269 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); 276 wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING);
@@ -361,6 +368,8 @@ void jbd2_journal_commit_transaction(journal_t *journal)
361 commit_transaction = journal->j_running_transaction; 368 commit_transaction = journal->j_running_transaction;
362 J_ASSERT(commit_transaction->t_state == T_RUNNING); 369 J_ASSERT(commit_transaction->t_state == T_RUNNING);
363 370
371 trace_mark(jbd2_start_commit, "dev %s transaction %d",
372 journal->j_devname, commit_transaction->t_tid);
364 jbd_debug(1, "JBD: starting commit of transaction %d\n", 373 jbd_debug(1, "JBD: starting commit of transaction %d\n",
365 commit_transaction->t_tid); 374 commit_transaction->t_tid);
366 375
@@ -495,9 +504,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)
495 jh = commit_transaction->t_buffers; 504 jh = commit_transaction->t_buffers;
496 505
497 /* If we're in abort mode, we just un-journal the buffer and 506 /* If we're in abort mode, we just un-journal the buffer and
498 release it for background writing. */ 507 release it. */
499 508
500 if (is_journal_aborted(journal)) { 509 if (is_journal_aborted(journal)) {
510 clear_buffer_jbddirty(jh2bh(jh));
501 JBUFFER_TRACE(jh, "journal is aborting: refile"); 511 JBUFFER_TRACE(jh, "journal is aborting: refile");
502 jbd2_journal_refile_buffer(journal, jh); 512 jbd2_journal_refile_buffer(journal, jh);
503 /* If that was the last one, we need to clean up 513 /* If that was the last one, we need to clean up
@@ -670,8 +680,14 @@ start_journal_io:
670 * commit block, which happens below in such setting. 680 * commit block, which happens below in such setting.
671 */ 681 */
672 err = journal_finish_inode_data_buffers(journal, commit_transaction); 682 err = journal_finish_inode_data_buffers(journal, commit_transaction);
673 if (err) 683 if (err) {
674 jbd2_journal_abort(journal, err); 684 printk(KERN_WARNING
685 "JBD2: Detected IO errors while flushing file data "
686 "on %s\n", journal->j_devname);
687 if (journal->j_flags & JBD2_ABORT_ON_SYNCDATA_ERR)
688 jbd2_journal_abort(journal, err);
689 err = 0;
690 }
675 691
676 /* Lo and behold: we have just managed to send a transaction to 692 /* Lo and behold: we have just managed to send a transaction to
677 the log. Before we can commit it, wait for the IO so far to 693 the log. Before we can commit it, wait for the IO so far to
@@ -770,6 +786,9 @@ wait_for_iobuf:
770 /* AKPM: bforget here */ 786 /* AKPM: bforget here */
771 } 787 }
772 788
789 if (err)
790 jbd2_journal_abort(journal, err);
791
773 jbd_debug(3, "JBD: commit phase 5\n"); 792 jbd_debug(3, "JBD: commit phase 5\n");
774 793
775 if (!JBD2_HAS_INCOMPAT_FEATURE(journal, 794 if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
@@ -868,6 +887,8 @@ restart_loop:
868 if (buffer_jbddirty(bh)) { 887 if (buffer_jbddirty(bh)) {
869 JBUFFER_TRACE(jh, "add to new checkpointing trans"); 888 JBUFFER_TRACE(jh, "add to new checkpointing trans");
870 __jbd2_journal_insert_checkpoint(jh, commit_transaction); 889 __jbd2_journal_insert_checkpoint(jh, commit_transaction);
890 if (is_journal_aborted(journal))
891 clear_buffer_jbddirty(bh);
871 JBUFFER_TRACE(jh, "refile for checkpoint writeback"); 892 JBUFFER_TRACE(jh, "refile for checkpoint writeback");
872 __jbd2_journal_refile_buffer(jh); 893 __jbd2_journal_refile_buffer(jh);
873 jbd_unlock_bh_state(bh); 894 jbd_unlock_bh_state(bh);
@@ -974,6 +995,9 @@ restart_loop:
974 } 995 }
975 spin_unlock(&journal->j_list_lock); 996 spin_unlock(&journal->j_list_lock);
976 997
998 trace_mark(jbd2_end_commit, "dev %s transaction %d head %d",
999 journal->j_devname, commit_transaction->t_tid,
1000 journal->j_tail_sequence);
977 jbd_debug(1, "JBD: commit %d complete, head %d\n", 1001 jbd_debug(1, "JBD: commit %d complete, head %d\n",
978 journal->j_commit_sequence, journal->j_tail_sequence); 1002 journal->j_commit_sequence, journal->j_tail_sequence);
979 1003
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b26c6d9fe6ae..783de118de92 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -68,7 +68,6 @@ EXPORT_SYMBOL(jbd2_journal_set_features);
68EXPORT_SYMBOL(jbd2_journal_create); 68EXPORT_SYMBOL(jbd2_journal_create);
69EXPORT_SYMBOL(jbd2_journal_load); 69EXPORT_SYMBOL(jbd2_journal_load);
70EXPORT_SYMBOL(jbd2_journal_destroy); 70EXPORT_SYMBOL(jbd2_journal_destroy);
71EXPORT_SYMBOL(jbd2_journal_update_superblock);
72EXPORT_SYMBOL(jbd2_journal_abort); 71EXPORT_SYMBOL(jbd2_journal_abort);
73EXPORT_SYMBOL(jbd2_journal_errno); 72EXPORT_SYMBOL(jbd2_journal_errno);
74EXPORT_SYMBOL(jbd2_journal_ack_err); 73EXPORT_SYMBOL(jbd2_journal_ack_err);
@@ -598,13 +597,9 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
598 if (ret) 597 if (ret)
599 *retp = ret; 598 *retp = ret;
600 else { 599 else {
601 char b[BDEVNAME_SIZE];
602
603 printk(KERN_ALERT "%s: journal block not found " 600 printk(KERN_ALERT "%s: journal block not found "
604 "at offset %lu on %s\n", 601 "at offset %lu on %s\n",
605 __func__, 602 __func__, blocknr, journal->j_devname);
606 blocknr,
607 bdevname(journal->j_dev, b));
608 err = -EIO; 603 err = -EIO;
609 __journal_abort_soft(journal, err); 604 __journal_abort_soft(journal, err);
610 } 605 }
@@ -902,10 +897,7 @@ static struct proc_dir_entry *proc_jbd2_stats;
902 897
903static void jbd2_stats_proc_init(journal_t *journal) 898static void jbd2_stats_proc_init(journal_t *journal)
904{ 899{
905 char name[BDEVNAME_SIZE]; 900 journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
906
907 bdevname(journal->j_dev, name);
908 journal->j_proc_entry = proc_mkdir(name, proc_jbd2_stats);
909 if (journal->j_proc_entry) { 901 if (journal->j_proc_entry) {
910 proc_create_data("history", S_IRUGO, journal->j_proc_entry, 902 proc_create_data("history", S_IRUGO, journal->j_proc_entry,
911 &jbd2_seq_history_fops, journal); 903 &jbd2_seq_history_fops, journal);
@@ -916,12 +908,9 @@ static void jbd2_stats_proc_init(journal_t *journal)
916 908
917static void jbd2_stats_proc_exit(journal_t *journal) 909static void jbd2_stats_proc_exit(journal_t *journal)
918{ 910{
919 char name[BDEVNAME_SIZE];
920
921 bdevname(journal->j_dev, name);
922 remove_proc_entry("info", journal->j_proc_entry); 911 remove_proc_entry("info", journal->j_proc_entry);
923 remove_proc_entry("history", journal->j_proc_entry); 912 remove_proc_entry("history", journal->j_proc_entry);
924 remove_proc_entry(name, proc_jbd2_stats); 913 remove_proc_entry(journal->j_devname, proc_jbd2_stats);
925} 914}
926 915
927static void journal_init_stats(journal_t *journal) 916static void journal_init_stats(journal_t *journal)
@@ -1019,6 +1008,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
1019{ 1008{
1020 journal_t *journal = journal_init_common(); 1009 journal_t *journal = journal_init_common();
1021 struct buffer_head *bh; 1010 struct buffer_head *bh;
1011 char *p;
1022 int n; 1012 int n;
1023 1013
1024 if (!journal) 1014 if (!journal)
@@ -1040,6 +1030,10 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
1040 journal->j_fs_dev = fs_dev; 1030 journal->j_fs_dev = fs_dev;
1041 journal->j_blk_offset = start; 1031 journal->j_blk_offset = start;
1042 journal->j_maxlen = len; 1032 journal->j_maxlen = len;
1033 bdevname(journal->j_dev, journal->j_devname);
1034 p = journal->j_devname;
1035 while ((p = strchr(p, '/')))
1036 *p = '!';
1043 jbd2_stats_proc_init(journal); 1037 jbd2_stats_proc_init(journal);
1044 1038
1045 bh = __getblk(journal->j_dev, start, journal->j_blocksize); 1039 bh = __getblk(journal->j_dev, start, journal->j_blocksize);
@@ -1062,6 +1056,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
1062{ 1056{
1063 struct buffer_head *bh; 1057 struct buffer_head *bh;
1064 journal_t *journal = journal_init_common(); 1058 journal_t *journal = journal_init_common();
1059 char *p;
1065 int err; 1060 int err;
1066 int n; 1061 int n;
1067 unsigned long long blocknr; 1062 unsigned long long blocknr;
@@ -1071,6 +1066,12 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
1071 1066
1072 journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev; 1067 journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
1073 journal->j_inode = inode; 1068 journal->j_inode = inode;
1069 bdevname(journal->j_dev, journal->j_devname);
1070 p = journal->j_devname;
1071 while ((p = strchr(p, '/')))
1072 *p = '!';
1073 p = journal->j_devname + strlen(journal->j_devname);
1074 sprintf(p, ":%lu", journal->j_inode->i_ino);
1074 jbd_debug(1, 1075 jbd_debug(1,
1075 "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n", 1076 "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
1076 journal, inode->i_sb->s_id, inode->i_ino, 1077 journal, inode->i_sb->s_id, inode->i_ino,
@@ -1254,6 +1255,22 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
1254 goto out; 1255 goto out;
1255 } 1256 }
1256 1257
1258 if (buffer_write_io_error(bh)) {
1259 /*
1260 * Oh, dear. A previous attempt to write the journal
1261 * superblock failed. This could happen because the
1262 * USB device was yanked out. Or it could happen to
1263 * be a transient write error and maybe the block will
1264 * be remapped. Nothing we can do but to retry the
1265 * write and hope for the best.
1266 */
1267 printk(KERN_ERR "JBD2: previous I/O error detected "
1268 "for journal superblock update for %s.\n",
1269 journal->j_devname);
1270 clear_buffer_write_io_error(bh);
1271 set_buffer_uptodate(bh);
1272 }
1273
1257 spin_lock(&journal->j_state_lock); 1274 spin_lock(&journal->j_state_lock);
1258 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n", 1275 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
1259 journal->j_tail, journal->j_tail_sequence, journal->j_errno); 1276 journal->j_tail, journal->j_tail_sequence, journal->j_errno);
@@ -1265,9 +1282,16 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
1265 1282
1266 BUFFER_TRACE(bh, "marking dirty"); 1283 BUFFER_TRACE(bh, "marking dirty");
1267 mark_buffer_dirty(bh); 1284 mark_buffer_dirty(bh);
1268 if (wait) 1285 if (wait) {
1269 sync_dirty_buffer(bh); 1286 sync_dirty_buffer(bh);
1270 else 1287 if (buffer_write_io_error(bh)) {
1288 printk(KERN_ERR "JBD2: I/O error detected "
1289 "when updating journal superblock for %s.\n",
1290 journal->j_devname);
1291 clear_buffer_write_io_error(bh);
1292 set_buffer_uptodate(bh);
1293 }
1294 } else
1271 ll_rw_block(SWRITE, 1, &bh); 1295 ll_rw_block(SWRITE, 1, &bh);
1272 1296
1273out: 1297out:
@@ -1427,9 +1451,12 @@ recovery_error:
1427 * 1451 *
1428 * Release a journal_t structure once it is no longer in use by the 1452 * Release a journal_t structure once it is no longer in use by the
1429 * journaled object. 1453 * journaled object.
1454 * Return <0 if we couldn't clean up the journal.
1430 */ 1455 */
1431void jbd2_journal_destroy(journal_t *journal) 1456int jbd2_journal_destroy(journal_t *journal)
1432{ 1457{
1458 int err = 0;
1459
1433 /* Wait for the commit thread to wake up and die. */ 1460 /* Wait for the commit thread to wake up and die. */
1434 journal_kill_thread(journal); 1461 journal_kill_thread(journal);
1435 1462
@@ -1452,11 +1479,16 @@ void jbd2_journal_destroy(journal_t *journal)
1452 J_ASSERT(journal->j_checkpoint_transactions == NULL); 1479 J_ASSERT(journal->j_checkpoint_transactions == NULL);
1453 spin_unlock(&journal->j_list_lock); 1480 spin_unlock(&journal->j_list_lock);
1454 1481
1455 /* We can now mark the journal as empty. */
1456 journal->j_tail = 0;
1457 journal->j_tail_sequence = ++journal->j_transaction_sequence;
1458 if (journal->j_sb_buffer) { 1482 if (journal->j_sb_buffer) {
1459 jbd2_journal_update_superblock(journal, 1); 1483 if (!is_journal_aborted(journal)) {
1484 /* We can now mark the journal as empty. */
1485 journal->j_tail = 0;
1486 journal->j_tail_sequence =
1487 ++journal->j_transaction_sequence;
1488 jbd2_journal_update_superblock(journal, 1);
1489 } else {
1490 err = -EIO;
1491 }
1460 brelse(journal->j_sb_buffer); 1492 brelse(journal->j_sb_buffer);
1461 } 1493 }
1462 1494
@@ -1468,6 +1500,8 @@ void jbd2_journal_destroy(journal_t *journal)
1468 jbd2_journal_destroy_revoke(journal); 1500 jbd2_journal_destroy_revoke(journal);
1469 kfree(journal->j_wbuf); 1501 kfree(journal->j_wbuf);
1470 kfree(journal); 1502 kfree(journal);
1503
1504 return err;
1471} 1505}
1472 1506
1473 1507
@@ -1693,10 +1727,16 @@ int jbd2_journal_flush(journal_t *journal)
1693 spin_lock(&journal->j_list_lock); 1727 spin_lock(&journal->j_list_lock);
1694 while (!err && journal->j_checkpoint_transactions != NULL) { 1728 while (!err && journal->j_checkpoint_transactions != NULL) {
1695 spin_unlock(&journal->j_list_lock); 1729 spin_unlock(&journal->j_list_lock);
1730 mutex_lock(&journal->j_checkpoint_mutex);
1696 err = jbd2_log_do_checkpoint(journal); 1731 err = jbd2_log_do_checkpoint(journal);
1732 mutex_unlock(&journal->j_checkpoint_mutex);
1697 spin_lock(&journal->j_list_lock); 1733 spin_lock(&journal->j_list_lock);
1698 } 1734 }
1699 spin_unlock(&journal->j_list_lock); 1735 spin_unlock(&journal->j_list_lock);
1736
1737 if (is_journal_aborted(journal))
1738 return -EIO;
1739
1700 jbd2_cleanup_journal_tail(journal); 1740 jbd2_cleanup_journal_tail(journal);
1701 1741
1702 /* Finally, mark the journal as really needing no recovery. 1742 /* Finally, mark the journal as really needing no recovery.
@@ -1718,7 +1758,7 @@ int jbd2_journal_flush(journal_t *journal)
1718 J_ASSERT(journal->j_head == journal->j_tail); 1758 J_ASSERT(journal->j_head == journal->j_tail);
1719 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence); 1759 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
1720 spin_unlock(&journal->j_state_lock); 1760 spin_unlock(&journal->j_state_lock);
1721 return err; 1761 return 0;
1722} 1762}
1723 1763
1724/** 1764/**
@@ -1762,23 +1802,6 @@ int jbd2_journal_wipe(journal_t *journal, int write)
1762} 1802}
1763 1803
1764/* 1804/*
1765 * journal_dev_name: format a character string to describe on what
1766 * device this journal is present.
1767 */
1768
1769static const char *journal_dev_name(journal_t *journal, char *buffer)
1770{
1771 struct block_device *bdev;
1772
1773 if (journal->j_inode)
1774 bdev = journal->j_inode->i_sb->s_bdev;
1775 else
1776 bdev = journal->j_dev;
1777
1778 return bdevname(bdev, buffer);
1779}
1780
1781/*
1782 * Journal abort has very specific semantics, which we describe 1805 * Journal abort has very specific semantics, which we describe
1783 * for journal abort. 1806 * for journal abort.
1784 * 1807 *
@@ -1794,13 +1817,12 @@ static const char *journal_dev_name(journal_t *journal, char *buffer)
1794void __jbd2_journal_abort_hard(journal_t *journal) 1817void __jbd2_journal_abort_hard(journal_t *journal)
1795{ 1818{
1796 transaction_t *transaction; 1819 transaction_t *transaction;
1797 char b[BDEVNAME_SIZE];
1798 1820
1799 if (journal->j_flags & JBD2_ABORT) 1821 if (journal->j_flags & JBD2_ABORT)
1800 return; 1822 return;
1801 1823
1802 printk(KERN_ERR "Aborting journal on device %s.\n", 1824 printk(KERN_ERR "Aborting journal on device %s.\n",
1803 journal_dev_name(journal, b)); 1825 journal->j_devname);
1804 1826
1805 spin_lock(&journal->j_state_lock); 1827 spin_lock(&journal->j_state_lock);
1806 journal->j_flags |= JBD2_ABORT; 1828 journal->j_flags |= JBD2_ABORT;
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 058f50f65b76..73063285b13f 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -225,7 +225,7 @@ do { \
225 */ 225 */
226int jbd2_journal_recover(journal_t *journal) 226int jbd2_journal_recover(journal_t *journal)
227{ 227{
228 int err; 228 int err, err2;
229 journal_superblock_t * sb; 229 journal_superblock_t * sb;
230 230
231 struct recovery_info info; 231 struct recovery_info info;
@@ -263,7 +263,10 @@ int jbd2_journal_recover(journal_t *journal)
263 journal->j_transaction_sequence = ++info.end_transaction; 263 journal->j_transaction_sequence = ++info.end_transaction;
264 264
265 jbd2_journal_clear_revoke(journal); 265 jbd2_journal_clear_revoke(journal);
266 sync_blockdev(journal->j_fs_dev); 266 err2 = sync_blockdev(journal->j_fs_dev);
267 if (!err)
268 err = err2;
269
267 return err; 270 return err;
268} 271}
269 272
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 4f7cadbb19fa..e5d540588fa9 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -301,7 +301,7 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
301 goto out; 301 goto out;
302 } 302 }
303 303
304 lock_acquire(&handle->h_lockdep_map, 0, 0, 0, 2, _THIS_IP_); 304 lock_map_acquire(&handle->h_lockdep_map);
305out: 305out:
306 return handle; 306 return handle;
307} 307}
@@ -1279,7 +1279,7 @@ int jbd2_journal_stop(handle_t *handle)
1279 spin_unlock(&journal->j_state_lock); 1279 spin_unlock(&journal->j_state_lock);
1280 } 1280 }
1281 1281
1282 lock_release(&handle->h_lockdep_map, 1, _THIS_IP_); 1282 lock_map_release(&handle->h_lockdep_map);
1283 1283
1284 jbd2_free_handle(handle); 1284 jbd2_free_handle(handle);
1285 return err; 1285 return err;