aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-06-15 19:04:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-06-15 19:04:37 -0400
commit718f58ad61810b7d4a6c9178185495f762e90807 (patch)
tree6f61597bea9b8dadeee13a888b969d021e5ec05d /fs/btrfs/disk-io.c
parent424d54d2dca03805942055e5b19926d33a7d1e31 (diff)
parent9c106405ddf893fcd04cd46555464417d2df8451 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs update from Chris Mason: "The dates look like I had to rebase this morning because there was a compiler warning for a printk arg that I had missed earlier. These are all fixes, including one to prevent using stale pointers for device names, and lots of fixes around transaction abort cleanups (Josef, Liu Bo). Jan Schmidt also sent in a number of fixes for the new reference number tracking code. Liu Bo beat me to updating the MAINTAINERS file. Since he thought to also fix the git url, I kept his commit." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (24 commits) Btrfs: update MAINTAINERS info for BTRFS FILE SYSTEM Btrfs: destroy the items of the delayed inodes in error handling routine Btrfs: make sure that we've made everything in pinned tree clean Btrfs: avoid memory leak of extent state in error handling routine Btrfs: do not resize a seeding device Btrfs: fix missing inherited flag in rename Btrfs: fix incompat flags setting Btrfs: fix defrag regression Btrfs: call filemap_fdatawrite twice for compression Btrfs: keep inode pinned when compressing writes Btrfs: implement ->show_devname Btrfs: use rcu to protect device->name Btrfs: unlock everything properly in the error case for nocow Btrfs: fix btrfs_destroy_marked_extents Btrfs: abort the transaction if the commit fails Btrfs: wake up transaction waiters when aborting a transaction Btrfs: fix locking in btrfs_destroy_delayed_refs Btrfs: pass locked_page into extent_clear_unlock_delalloc if theres an error Btrfs: fix race in tree mod log addition Btrfs: add btrfs_next_old_leaf ...
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c76
1 files changed, 48 insertions, 28 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 7ae51decf6d3..e1890b1d3075 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -44,6 +44,7 @@
44#include "free-space-cache.h" 44#include "free-space-cache.h"
45#include "inode-map.h" 45#include "inode-map.h"
46#include "check-integrity.h" 46#include "check-integrity.h"
47#include "rcu-string.h"
47 48
48static struct extent_io_ops btree_extent_io_ops; 49static struct extent_io_ops btree_extent_io_ops;
49static void end_workqueue_fn(struct btrfs_work *work); 50static void end_workqueue_fn(struct btrfs_work *work);
@@ -2118,7 +2119,7 @@ int open_ctree(struct super_block *sb,
2118 2119
2119 features = btrfs_super_incompat_flags(disk_super); 2120 features = btrfs_super_incompat_flags(disk_super);
2120 features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF; 2121 features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
2121 if (tree_root->fs_info->compress_type & BTRFS_COMPRESS_LZO) 2122 if (tree_root->fs_info->compress_type == BTRFS_COMPRESS_LZO)
2122 features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; 2123 features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
2123 2124
2124 /* 2125 /*
@@ -2575,8 +2576,9 @@ static void btrfs_end_buffer_write_sync(struct buffer_head *bh, int uptodate)
2575 struct btrfs_device *device = (struct btrfs_device *) 2576 struct btrfs_device *device = (struct btrfs_device *)
2576 bh->b_private; 2577 bh->b_private;
2577 2578
2578 printk_ratelimited(KERN_WARNING "lost page write due to " 2579 printk_ratelimited_in_rcu(KERN_WARNING "lost page write due to "
2579 "I/O error on %s\n", device->name); 2580 "I/O error on %s\n",
2581 rcu_str_deref(device->name));
2580 /* note, we dont' set_buffer_write_io_error because we have 2582 /* note, we dont' set_buffer_write_io_error because we have
2581 * our own ways of dealing with the IO errors 2583 * our own ways of dealing with the IO errors
2582 */ 2584 */
@@ -2749,8 +2751,8 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
2749 wait_for_completion(&device->flush_wait); 2751 wait_for_completion(&device->flush_wait);
2750 2752
2751 if (bio_flagged(bio, BIO_EOPNOTSUPP)) { 2753 if (bio_flagged(bio, BIO_EOPNOTSUPP)) {
2752 printk("btrfs: disabling barriers on dev %s\n", 2754 printk_in_rcu("btrfs: disabling barriers on dev %s\n",
2753 device->name); 2755 rcu_str_deref(device->name));
2754 device->nobarriers = 1; 2756 device->nobarriers = 1;
2755 } 2757 }
2756 if (!bio_flagged(bio, BIO_UPTODATE)) { 2758 if (!bio_flagged(bio, BIO_UPTODATE)) {
@@ -3400,7 +3402,6 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
3400 3402
3401 delayed_refs = &trans->delayed_refs; 3403 delayed_refs = &trans->delayed_refs;
3402 3404
3403again:
3404 spin_lock(&delayed_refs->lock); 3405 spin_lock(&delayed_refs->lock);
3405 if (delayed_refs->num_entries == 0) { 3406 if (delayed_refs->num_entries == 0) {
3406 spin_unlock(&delayed_refs->lock); 3407 spin_unlock(&delayed_refs->lock);
@@ -3408,31 +3409,36 @@ again:
3408 return ret; 3409 return ret;
3409 } 3410 }
3410 3411
3411 node = rb_first(&delayed_refs->root); 3412 while ((node = rb_first(&delayed_refs->root)) != NULL) {
3412 while (node) {
3413 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); 3413 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node);
3414 node = rb_next(node);
3415
3416 ref->in_tree = 0;
3417 rb_erase(&ref->rb_node, &delayed_refs->root);
3418 delayed_refs->num_entries--;
3419 3414
3420 atomic_set(&ref->refs, 1); 3415 atomic_set(&ref->refs, 1);
3421 if (btrfs_delayed_ref_is_head(ref)) { 3416 if (btrfs_delayed_ref_is_head(ref)) {
3422 struct btrfs_delayed_ref_head *head; 3417 struct btrfs_delayed_ref_head *head;
3423 3418
3424 head = btrfs_delayed_node_to_head(ref); 3419 head = btrfs_delayed_node_to_head(ref);
3425 spin_unlock(&delayed_refs->lock); 3420 if (!mutex_trylock(&head->mutex)) {
3426 mutex_lock(&head->mutex); 3421 atomic_inc(&ref->refs);
3422 spin_unlock(&delayed_refs->lock);
3423
3424 /* Need to wait for the delayed ref to run */
3425 mutex_lock(&head->mutex);
3426 mutex_unlock(&head->mutex);
3427 btrfs_put_delayed_ref(ref);
3428
3429 continue;
3430 }
3431
3427 kfree(head->extent_op); 3432 kfree(head->extent_op);
3428 delayed_refs->num_heads--; 3433 delayed_refs->num_heads--;
3429 if (list_empty(&head->cluster)) 3434 if (list_empty(&head->cluster))
3430 delayed_refs->num_heads_ready--; 3435 delayed_refs->num_heads_ready--;
3431 list_del_init(&head->cluster); 3436 list_del_init(&head->cluster);
3432 mutex_unlock(&head->mutex);
3433 btrfs_put_delayed_ref(ref);
3434 goto again;
3435 } 3437 }
3438 ref->in_tree = 0;
3439 rb_erase(&ref->rb_node, &delayed_refs->root);
3440 delayed_refs->num_entries--;
3441
3436 spin_unlock(&delayed_refs->lock); 3442 spin_unlock(&delayed_refs->lock);
3437 btrfs_put_delayed_ref(ref); 3443 btrfs_put_delayed_ref(ref);
3438 3444
@@ -3520,11 +3526,9 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
3520 &(&BTRFS_I(page->mapping->host)->io_tree)->buffer, 3526 &(&BTRFS_I(page->mapping->host)->io_tree)->buffer,
3521 offset >> PAGE_CACHE_SHIFT); 3527 offset >> PAGE_CACHE_SHIFT);
3522 spin_unlock(&dirty_pages->buffer_lock); 3528 spin_unlock(&dirty_pages->buffer_lock);
3523 if (eb) { 3529 if (eb)
3524 ret = test_and_clear_bit(EXTENT_BUFFER_DIRTY, 3530 ret = test_and_clear_bit(EXTENT_BUFFER_DIRTY,
3525 &eb->bflags); 3531 &eb->bflags);
3526 atomic_set(&eb->refs, 1);
3527 }
3528 if (PageWriteback(page)) 3532 if (PageWriteback(page))
3529 end_page_writeback(page); 3533 end_page_writeback(page);
3530 3534
@@ -3538,8 +3542,8 @@ static int btrfs_destroy_marked_extents(struct btrfs_root *root,
3538 spin_unlock_irq(&page->mapping->tree_lock); 3542 spin_unlock_irq(&page->mapping->tree_lock);
3539 } 3543 }
3540 3544
3541 page->mapping->a_ops->invalidatepage(page, 0);
3542 unlock_page(page); 3545 unlock_page(page);
3546 page_cache_release(page);
3543 } 3547 }
3544 } 3548 }
3545 3549
@@ -3553,8 +3557,10 @@ static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
3553 u64 start; 3557 u64 start;
3554 u64 end; 3558 u64 end;
3555 int ret; 3559 int ret;
3560 bool loop = true;
3556 3561
3557 unpin = pinned_extents; 3562 unpin = pinned_extents;
3563again:
3558 while (1) { 3564 while (1) {
3559 ret = find_first_extent_bit(unpin, 0, &start, &end, 3565 ret = find_first_extent_bit(unpin, 0, &start, &end,
3560 EXTENT_DIRTY); 3566 EXTENT_DIRTY);
@@ -3572,6 +3578,15 @@ static int btrfs_destroy_pinned_extent(struct btrfs_root *root,
3572 cond_resched(); 3578 cond_resched();
3573 } 3579 }
3574 3580
3581 if (loop) {
3582 if (unpin == &root->fs_info->freed_extents[0])
3583 unpin = &root->fs_info->freed_extents[1];
3584 else
3585 unpin = &root->fs_info->freed_extents[0];
3586 loop = false;
3587 goto again;
3588 }
3589
3575 return 0; 3590 return 0;
3576} 3591}
3577 3592
@@ -3585,21 +3600,23 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans,
3585 /* FIXME: cleanup wait for commit */ 3600 /* FIXME: cleanup wait for commit */
3586 cur_trans->in_commit = 1; 3601 cur_trans->in_commit = 1;
3587 cur_trans->blocked = 1; 3602 cur_trans->blocked = 1;
3588 if (waitqueue_active(&root->fs_info->transaction_blocked_wait)) 3603 wake_up(&root->fs_info->transaction_blocked_wait);
3589 wake_up(&root->fs_info->transaction_blocked_wait);
3590 3604
3591 cur_trans->blocked = 0; 3605 cur_trans->blocked = 0;
3592 if (waitqueue_active(&root->fs_info->transaction_wait)) 3606 wake_up(&root->fs_info->transaction_wait);
3593 wake_up(&root->fs_info->transaction_wait);
3594 3607
3595 cur_trans->commit_done = 1; 3608 cur_trans->commit_done = 1;
3596 if (waitqueue_active(&cur_trans->commit_wait)) 3609 wake_up(&cur_trans->commit_wait);
3597 wake_up(&cur_trans->commit_wait); 3610
3611 btrfs_destroy_delayed_inodes(root);
3612 btrfs_assert_delayed_root_empty(root);
3598 3613
3599 btrfs_destroy_pending_snapshots(cur_trans); 3614 btrfs_destroy_pending_snapshots(cur_trans);
3600 3615
3601 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages, 3616 btrfs_destroy_marked_extents(root, &cur_trans->dirty_pages,
3602 EXTENT_DIRTY); 3617 EXTENT_DIRTY);
3618 btrfs_destroy_pinned_extent(root,
3619 root->fs_info->pinned_extents);
3603 3620
3604 /* 3621 /*
3605 memset(cur_trans, 0, sizeof(*cur_trans)); 3622 memset(cur_trans, 0, sizeof(*cur_trans));
@@ -3648,6 +3665,9 @@ int btrfs_cleanup_transaction(struct btrfs_root *root)
3648 if (waitqueue_active(&t->commit_wait)) 3665 if (waitqueue_active(&t->commit_wait))
3649 wake_up(&t->commit_wait); 3666 wake_up(&t->commit_wait);
3650 3667
3668 btrfs_destroy_delayed_inodes(root);
3669 btrfs_assert_delayed_root_empty(root);
3670
3651 btrfs_destroy_pending_snapshots(t); 3671 btrfs_destroy_pending_snapshots(t);
3652 3672
3653 btrfs_destroy_delalloc_inodes(root); 3673 btrfs_destroy_delalloc_inodes(root);