aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd2
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jbd2')
-rw-r--r--fs/jbd2/commit.c12
-rw-r--r--fs/jbd2/journal.c41
-rw-r--r--fs/jbd2/transaction.c75
3 files changed, 71 insertions, 57 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 7b4088b2364d..26d991ddc1e6 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -25,6 +25,7 @@
25#include <linux/writeback.h> 25#include <linux/writeback.h>
26#include <linux/backing-dev.h> 26#include <linux/backing-dev.h>
27#include <linux/bio.h> 27#include <linux/bio.h>
28#include <linux/blkdev.h>
28#include <trace/events/jbd2.h> 29#include <trace/events/jbd2.h>
29 30
30/* 31/*
@@ -133,8 +134,8 @@ static int journal_submit_commit_record(journal_t *journal,
133 bh->b_end_io = journal_end_buffer_io_sync; 134 bh->b_end_io = journal_end_buffer_io_sync;
134 135
135 if (journal->j_flags & JBD2_BARRIER && 136 if (journal->j_flags & JBD2_BARRIER &&
136 !JBD2_HAS_INCOMPAT_FEATURE(journal, 137 !JBD2_HAS_INCOMPAT_FEATURE(journal,
137 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { 138 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
138 set_buffer_ordered(bh); 139 set_buffer_ordered(bh);
139 barrier_done = 1; 140 barrier_done = 1;
140 } 141 }
@@ -220,7 +221,6 @@ static int journal_submit_inode_data_buffers(struct address_space *mapping)
220 .nr_to_write = mapping->nrpages * 2, 221 .nr_to_write = mapping->nrpages * 2,
221 .range_start = 0, 222 .range_start = 0,
222 .range_end = i_size_read(mapping->host), 223 .range_end = i_size_read(mapping->host),
223 .for_writepages = 1,
224 }; 224 };
225 225
226 ret = generic_writepages(mapping, &wbc); 226 ret = generic_writepages(mapping, &wbc);
@@ -707,11 +707,13 @@ start_journal_io:
707 /* Done it all: now write the commit record asynchronously. */ 707 /* Done it all: now write the commit record asynchronously. */
708 708
709 if (JBD2_HAS_INCOMPAT_FEATURE(journal, 709 if (JBD2_HAS_INCOMPAT_FEATURE(journal,
710 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { 710 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
711 err = journal_submit_commit_record(journal, commit_transaction, 711 err = journal_submit_commit_record(journal, commit_transaction,
712 &cbh, crc32_sum); 712 &cbh, crc32_sum);
713 if (err) 713 if (err)
714 __jbd2_journal_abort_hard(journal); 714 __jbd2_journal_abort_hard(journal);
715 if (journal->j_flags & JBD2_BARRIER)
716 blkdev_issue_flush(journal->j_dev, NULL);
715 } 717 }
716 718
717 /* 719 /*
@@ -834,7 +836,7 @@ wait_for_iobuf:
834 jbd_debug(3, "JBD: commit phase 5\n"); 836 jbd_debug(3, "JBD: commit phase 5\n");
835 837
836 if (!JBD2_HAS_INCOMPAT_FEATURE(journal, 838 if (!JBD2_HAS_INCOMPAT_FEATURE(journal,
837 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) { 839 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)) {
838 err = journal_submit_commit_record(journal, commit_transaction, 840 err = journal_submit_commit_record(journal, commit_transaction,
839 &cbh, crc32_sum); 841 &cbh, crc32_sum);
840 if (err) 842 if (err)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 18bfd5dab642..53b86e16e5fe 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -297,6 +297,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
297 unsigned int new_offset; 297 unsigned int new_offset;
298 struct buffer_head *bh_in = jh2bh(jh_in); 298 struct buffer_head *bh_in = jh2bh(jh_in);
299 struct jbd2_buffer_trigger_type *triggers; 299 struct jbd2_buffer_trigger_type *triggers;
300 journal_t *journal = transaction->t_journal;
300 301
301 /* 302 /*
302 * The buffer really shouldn't be locked: only the current committing 303 * The buffer really shouldn't be locked: only the current committing
@@ -310,6 +311,11 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
310 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in)); 311 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
311 312
312 new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL); 313 new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL);
314 /* keep subsequent assertions sane */
315 new_bh->b_state = 0;
316 init_buffer(new_bh, NULL, NULL);
317 atomic_set(&new_bh->b_count, 1);
318 new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
313 319
314 /* 320 /*
315 * If a new transaction has already done a buffer copy-out, then 321 * If a new transaction has already done a buffer copy-out, then
@@ -388,14 +394,6 @@ repeat:
388 kunmap_atomic(mapped_data, KM_USER0); 394 kunmap_atomic(mapped_data, KM_USER0);
389 } 395 }
390 396
391 /* keep subsequent assertions sane */
392 new_bh->b_state = 0;
393 init_buffer(new_bh, NULL, NULL);
394 atomic_set(&new_bh->b_count, 1);
395 jbd_unlock_bh_state(bh_in);
396
397 new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
398
399 set_bh_page(new_bh, new_page, new_offset); 397 set_bh_page(new_bh, new_page, new_offset);
400 new_jh->b_transaction = NULL; 398 new_jh->b_transaction = NULL;
401 new_bh->b_size = jh2bh(jh_in)->b_size; 399 new_bh->b_size = jh2bh(jh_in)->b_size;
@@ -412,7 +410,11 @@ repeat:
412 * copying is moved to the transaction's shadow queue. 410 * copying is moved to the transaction's shadow queue.
413 */ 411 */
414 JBUFFER_TRACE(jh_in, "file as BJ_Shadow"); 412 JBUFFER_TRACE(jh_in, "file as BJ_Shadow");
415 jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow); 413 spin_lock(&journal->j_list_lock);
414 __jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow);
415 spin_unlock(&journal->j_list_lock);
416 jbd_unlock_bh_state(bh_in);
417
416 JBUFFER_TRACE(new_jh, "file as BJ_IO"); 418 JBUFFER_TRACE(new_jh, "file as BJ_IO");
417 jbd2_journal_file_buffer(new_jh, transaction, BJ_IO); 419 jbd2_journal_file_buffer(new_jh, transaction, BJ_IO);
418 420
@@ -766,7 +768,7 @@ static void jbd2_seq_history_stop(struct seq_file *seq, void *v)
766{ 768{
767} 769}
768 770
769static struct seq_operations jbd2_seq_history_ops = { 771static const struct seq_operations jbd2_seq_history_ops = {
770 .start = jbd2_seq_history_start, 772 .start = jbd2_seq_history_start,
771 .next = jbd2_seq_history_next, 773 .next = jbd2_seq_history_next,
772 .stop = jbd2_seq_history_stop, 774 .stop = jbd2_seq_history_stop,
@@ -870,7 +872,7 @@ static void jbd2_seq_info_stop(struct seq_file *seq, void *v)
870{ 872{
871} 873}
872 874
873static struct seq_operations jbd2_seq_info_ops = { 875static const struct seq_operations jbd2_seq_info_ops = {
874 .start = jbd2_seq_info_start, 876 .start = jbd2_seq_info_start,
875 .next = jbd2_seq_info_next, 877 .next = jbd2_seq_info_next,
876 .stop = jbd2_seq_info_stop, 878 .stop = jbd2_seq_info_stop,
@@ -1185,6 +1187,12 @@ static int journal_reset(journal_t *journal)
1185 1187
1186 first = be32_to_cpu(sb->s_first); 1188 first = be32_to_cpu(sb->s_first);
1187 last = be32_to_cpu(sb->s_maxlen); 1189 last = be32_to_cpu(sb->s_maxlen);
1190 if (first + JBD2_MIN_JOURNAL_BLOCKS > last + 1) {
1191 printk(KERN_ERR "JBD: Journal too short (blocks %llu-%llu).\n",
1192 first, last);
1193 journal_fail_superblock(journal);
1194 return -EINVAL;
1195 }
1188 1196
1189 journal->j_first = first; 1197 journal->j_first = first;
1190 journal->j_last = last; 1198 journal->j_last = last;
@@ -2410,6 +2418,7 @@ const char *jbd2_dev_to_name(dev_t device)
2410 int i = hash_32(device, CACHE_SIZE_BITS); 2418 int i = hash_32(device, CACHE_SIZE_BITS);
2411 char *ret; 2419 char *ret;
2412 struct block_device *bd; 2420 struct block_device *bd;
2421 static struct devname_cache *new_dev;
2413 2422
2414 rcu_read_lock(); 2423 rcu_read_lock();
2415 if (devcache[i] && devcache[i]->device == device) { 2424 if (devcache[i] && devcache[i]->device == device) {
@@ -2419,20 +2428,20 @@ const char *jbd2_dev_to_name(dev_t device)
2419 } 2428 }
2420 rcu_read_unlock(); 2429 rcu_read_unlock();
2421 2430
2431 new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
2432 if (!new_dev)
2433 return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
2422 spin_lock(&devname_cache_lock); 2434 spin_lock(&devname_cache_lock);
2423 if (devcache[i]) { 2435 if (devcache[i]) {
2424 if (devcache[i]->device == device) { 2436 if (devcache[i]->device == device) {
2437 kfree(new_dev);
2425 ret = devcache[i]->devname; 2438 ret = devcache[i]->devname;
2426 spin_unlock(&devname_cache_lock); 2439 spin_unlock(&devname_cache_lock);
2427 return ret; 2440 return ret;
2428 } 2441 }
2429 call_rcu(&devcache[i]->rcu, free_devcache); 2442 call_rcu(&devcache[i]->rcu, free_devcache);
2430 } 2443 }
2431 devcache[i] = kmalloc(sizeof(struct devname_cache), GFP_KERNEL); 2444 devcache[i] = new_dev;
2432 if (!devcache[i]) {
2433 spin_unlock(&devname_cache_lock);
2434 return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
2435 }
2436 devcache[i]->device = device; 2445 devcache[i]->device = device;
2437 bd = bdget(device); 2446 bd = bdget(device);
2438 if (bd) { 2447 if (bd) {
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 494501edba6b..a0512700542f 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -57,7 +57,7 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
57 INIT_LIST_HEAD(&transaction->t_private_list); 57 INIT_LIST_HEAD(&transaction->t_private_list);
58 58
59 /* Set up the commit timer for the new transaction. */ 59 /* Set up the commit timer for the new transaction. */
60 journal->j_commit_timer.expires = round_jiffies(transaction->t_expires); 60 journal->j_commit_timer.expires = round_jiffies_up(transaction->t_expires);
61 add_timer(&journal->j_commit_timer); 61 add_timer(&journal->j_commit_timer);
62 62
63 J_ASSERT(journal->j_running_transaction == NULL); 63 J_ASSERT(journal->j_running_transaction == NULL);
@@ -238,6 +238,8 @@ repeat_locked:
238 __jbd2_log_space_left(journal)); 238 __jbd2_log_space_left(journal));
239 spin_unlock(&transaction->t_handle_lock); 239 spin_unlock(&transaction->t_handle_lock);
240 spin_unlock(&journal->j_state_lock); 240 spin_unlock(&journal->j_state_lock);
241
242 lock_map_acquire(&handle->h_lockdep_map);
241out: 243out:
242 if (unlikely(new_transaction)) /* It's usually NULL */ 244 if (unlikely(new_transaction)) /* It's usually NULL */
243 kfree(new_transaction); 245 kfree(new_transaction);
@@ -303,8 +305,6 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
303 handle = ERR_PTR(err); 305 handle = ERR_PTR(err);
304 goto out; 306 goto out;
305 } 307 }
306
307 lock_map_acquire(&handle->h_lockdep_map);
308out: 308out:
309 return handle; 309 return handle;
310} 310}
@@ -426,6 +426,7 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
426 __jbd2_log_start_commit(journal, transaction->t_tid); 426 __jbd2_log_start_commit(journal, transaction->t_tid);
427 spin_unlock(&journal->j_state_lock); 427 spin_unlock(&journal->j_state_lock);
428 428
429 lock_map_release(&handle->h_lockdep_map);
429 handle->h_buffer_credits = nblocks; 430 handle->h_buffer_credits = nblocks;
430 ret = start_this_handle(journal, handle); 431 ret = start_this_handle(journal, handle);
431 return ret; 432 return ret;
@@ -499,34 +500,15 @@ void jbd2_journal_unlock_updates (journal_t *journal)
499 wake_up(&journal->j_wait_transaction_locked); 500 wake_up(&journal->j_wait_transaction_locked);
500} 501}
501 502
502/* 503static void warn_dirty_buffer(struct buffer_head *bh)
503 * Report any unexpected dirty buffers which turn up. Normally those
504 * indicate an error, but they can occur if the user is running (say)
505 * tune2fs to modify the live filesystem, so we need the option of
506 * continuing as gracefully as possible. #
507 *
508 * The caller should already hold the journal lock and
509 * j_list_lock spinlock: most callers will need those anyway
510 * in order to probe the buffer's journaling state safely.
511 */
512static void jbd_unexpected_dirty_buffer(struct journal_head *jh)
513{ 504{
514 int jlist; 505 char b[BDEVNAME_SIZE];
515
516 /* If this buffer is one which might reasonably be dirty
517 * --- ie. data, or not part of this journal --- then
518 * we're OK to leave it alone, but otherwise we need to
519 * move the dirty bit to the journal's own internal
520 * JBDDirty bit. */
521 jlist = jh->b_jlist;
522
523 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
524 jlist == BJ_Shadow || jlist == BJ_Forget) {
525 struct buffer_head *bh = jh2bh(jh);
526 506
527 if (test_clear_buffer_dirty(bh)) 507 printk(KERN_WARNING
528 set_buffer_jbddirty(bh); 508 "JBD: Spotted dirty metadata buffer (dev = %s, blocknr = %llu). "
529 } 509 "There's a risk of filesystem corruption in case of system "
510 "crash.\n",
511 bdevname(bh->b_bdev, b), (unsigned long long)bh->b_blocknr);
530} 512}
531 513
532/* 514/*
@@ -593,14 +575,16 @@ repeat:
593 if (jh->b_next_transaction) 575 if (jh->b_next_transaction)
594 J_ASSERT_JH(jh, jh->b_next_transaction == 576 J_ASSERT_JH(jh, jh->b_next_transaction ==
595 transaction); 577 transaction);
578 warn_dirty_buffer(bh);
596 } 579 }
597 /* 580 /*
598 * In any case we need to clean the dirty flag and we must 581 * In any case we need to clean the dirty flag and we must
599 * do it under the buffer lock to be sure we don't race 582 * do it under the buffer lock to be sure we don't race
600 * with running write-out. 583 * with running write-out.
601 */ 584 */
602 JBUFFER_TRACE(jh, "Unexpected dirty buffer"); 585 JBUFFER_TRACE(jh, "Journalling dirty buffer");
603 jbd_unexpected_dirty_buffer(jh); 586 clear_buffer_dirty(bh);
587 set_buffer_jbddirty(bh);
604 } 588 }
605 589
606 unlock_buffer(bh); 590 unlock_buffer(bh);
@@ -843,6 +827,15 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
843 J_ASSERT_JH(jh, buffer_locked(jh2bh(jh))); 827 J_ASSERT_JH(jh, buffer_locked(jh2bh(jh)));
844 828
845 if (jh->b_transaction == NULL) { 829 if (jh->b_transaction == NULL) {
830 /*
831 * Previous jbd2_journal_forget() could have left the buffer
832 * with jbddirty bit set because it was being committed. When
833 * the commit finished, we've filed the buffer for
834 * checkpointing and marked it dirty. Now we are reallocating
835 * the buffer so the transaction freeing it must have
836 * committed and so it's safe to clear the dirty bit.
837 */
838 clear_buffer_dirty(jh2bh(jh));
846 jh->b_transaction = transaction; 839 jh->b_transaction = transaction;
847 840
848 /* first access by this transaction */ 841 /* first access by this transaction */
@@ -1644,8 +1637,13 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
1644 1637
1645 if (jh->b_cp_transaction) { 1638 if (jh->b_cp_transaction) {
1646 JBUFFER_TRACE(jh, "on running+cp transaction"); 1639 JBUFFER_TRACE(jh, "on running+cp transaction");
1640 /*
1641 * We don't want to write the buffer anymore, clear the
1642 * bit so that we don't confuse checks in
1643 * __journal_file_buffer
1644 */
1645 clear_buffer_dirty(bh);
1647 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget); 1646 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1648 clear_buffer_jbddirty(bh);
1649 may_free = 0; 1647 may_free = 0;
1650 } else { 1648 } else {
1651 JBUFFER_TRACE(jh, "on running transaction"); 1649 JBUFFER_TRACE(jh, "on running transaction");
@@ -1896,12 +1894,17 @@ void __jbd2_journal_file_buffer(struct journal_head *jh,
1896 if (jh->b_transaction && jh->b_jlist == jlist) 1894 if (jh->b_transaction && jh->b_jlist == jlist)
1897 return; 1895 return;
1898 1896
1899 /* The following list of buffer states needs to be consistent
1900 * with __jbd_unexpected_dirty_buffer()'s handling of dirty
1901 * state. */
1902
1903 if (jlist == BJ_Metadata || jlist == BJ_Reserved || 1897 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
1904 jlist == BJ_Shadow || jlist == BJ_Forget) { 1898 jlist == BJ_Shadow || jlist == BJ_Forget) {
1899 /*
1900 * For metadata buffers, we track dirty bit in buffer_jbddirty
1901 * instead of buffer_dirty. We should not see a dirty bit set
1902 * here because we clear it in do_get_write_access but e.g.
1903 * tune2fs can modify the sb and set the dirty bit at any time
1904 * so we try to gracefully handle that.
1905 */
1906 if (buffer_dirty(bh))
1907 warn_dirty_buffer(bh);
1905 if (test_clear_buffer_dirty(bh) || 1908 if (test_clear_buffer_dirty(bh) ||
1906 test_clear_buffer_jbddirty(bh)) 1909 test_clear_buffer_jbddirty(bh))
1907 was_dirty = 1; 1910 was_dirty = 1;