diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 139 |
1 files changed, 86 insertions, 53 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c41db6d45ab6..02bb099845fd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -379,7 +379,8 @@ again: | |||
379 | * change at any time if we discover bad compression ratios. | 379 | * change at any time if we discover bad compression ratios. |
380 | */ | 380 | */ |
381 | if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) && | 381 | if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) && |
382 | btrfs_test_opt(root, COMPRESS)) { | 382 | (btrfs_test_opt(root, COMPRESS) || |
383 | (BTRFS_I(inode)->force_compress))) { | ||
383 | WARN_ON(pages); | 384 | WARN_ON(pages); |
384 | pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); | 385 | pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); |
385 | 386 | ||
@@ -483,8 +484,10 @@ again: | |||
483 | nr_pages_ret = 0; | 484 | nr_pages_ret = 0; |
484 | 485 | ||
485 | /* flag the file so we don't compress in the future */ | 486 | /* flag the file so we don't compress in the future */ |
486 | if (!btrfs_test_opt(root, FORCE_COMPRESS)) | 487 | if (!btrfs_test_opt(root, FORCE_COMPRESS) && |
488 | !(BTRFS_I(inode)->force_compress)) { | ||
487 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; | 489 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; |
490 | } | ||
488 | } | 491 | } |
489 | if (will_compress) { | 492 | if (will_compress) { |
490 | *num_added += 1; | 493 | *num_added += 1; |
@@ -570,8 +573,8 @@ retry: | |||
570 | unsigned long nr_written = 0; | 573 | unsigned long nr_written = 0; |
571 | 574 | ||
572 | lock_extent(io_tree, async_extent->start, | 575 | lock_extent(io_tree, async_extent->start, |
573 | async_extent->start + | 576 | async_extent->start + |
574 | async_extent->ram_size - 1, GFP_NOFS); | 577 | async_extent->ram_size - 1, GFP_NOFS); |
575 | 578 | ||
576 | /* allocate blocks */ | 579 | /* allocate blocks */ |
577 | ret = cow_file_range(inode, async_cow->locked_page, | 580 | ret = cow_file_range(inode, async_cow->locked_page, |
@@ -1211,7 +1214,8 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, | |||
1211 | else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) | 1214 | else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) |
1212 | ret = run_delalloc_nocow(inode, locked_page, start, end, | 1215 | ret = run_delalloc_nocow(inode, locked_page, start, end, |
1213 | page_started, 0, nr_written); | 1216 | page_started, 0, nr_written); |
1214 | else if (!btrfs_test_opt(root, COMPRESS)) | 1217 | else if (!btrfs_test_opt(root, COMPRESS) && |
1218 | !(BTRFS_I(inode)->force_compress)) | ||
1215 | ret = cow_file_range(inode, locked_page, start, end, | 1219 | ret = cow_file_range(inode, locked_page, start, end, |
1216 | page_started, nr_written, 1); | 1220 | page_started, nr_written, 1); |
1217 | else | 1221 | else |
@@ -1508,12 +1512,13 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, | |||
1508 | return 0; | 1512 | return 0; |
1509 | } | 1513 | } |
1510 | 1514 | ||
1511 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end) | 1515 | int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, |
1516 | struct extent_state **cached_state) | ||
1512 | { | 1517 | { |
1513 | if ((end & (PAGE_CACHE_SIZE - 1)) == 0) | 1518 | if ((end & (PAGE_CACHE_SIZE - 1)) == 0) |
1514 | WARN_ON(1); | 1519 | WARN_ON(1); |
1515 | return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end, | 1520 | return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end, |
1516 | GFP_NOFS); | 1521 | cached_state, GFP_NOFS); |
1517 | } | 1522 | } |
1518 | 1523 | ||
1519 | /* see btrfs_writepage_start_hook for details on why this is required */ | 1524 | /* see btrfs_writepage_start_hook for details on why this is required */ |
@@ -1526,6 +1531,7 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) | |||
1526 | { | 1531 | { |
1527 | struct btrfs_writepage_fixup *fixup; | 1532 | struct btrfs_writepage_fixup *fixup; |
1528 | struct btrfs_ordered_extent *ordered; | 1533 | struct btrfs_ordered_extent *ordered; |
1534 | struct extent_state *cached_state = NULL; | ||
1529 | struct page *page; | 1535 | struct page *page; |
1530 | struct inode *inode; | 1536 | struct inode *inode; |
1531 | u64 page_start; | 1537 | u64 page_start; |
@@ -1544,7 +1550,8 @@ again: | |||
1544 | page_start = page_offset(page); | 1550 | page_start = page_offset(page); |
1545 | page_end = page_offset(page) + PAGE_CACHE_SIZE - 1; | 1551 | page_end = page_offset(page) + PAGE_CACHE_SIZE - 1; |
1546 | 1552 | ||
1547 | lock_extent(&BTRFS_I(inode)->io_tree, page_start, page_end, GFP_NOFS); | 1553 | lock_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, 0, |
1554 | &cached_state, GFP_NOFS); | ||
1548 | 1555 | ||
1549 | /* already ordered? We're done */ | 1556 | /* already ordered? We're done */ |
1550 | if (PagePrivate2(page)) | 1557 | if (PagePrivate2(page)) |
@@ -1552,17 +1559,18 @@ again: | |||
1552 | 1559 | ||
1553 | ordered = btrfs_lookup_ordered_extent(inode, page_start); | 1560 | ordered = btrfs_lookup_ordered_extent(inode, page_start); |
1554 | if (ordered) { | 1561 | if (ordered) { |
1555 | unlock_extent(&BTRFS_I(inode)->io_tree, page_start, | 1562 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, |
1556 | page_end, GFP_NOFS); | 1563 | page_end, &cached_state, GFP_NOFS); |
1557 | unlock_page(page); | 1564 | unlock_page(page); |
1558 | btrfs_start_ordered_extent(inode, ordered, 1); | 1565 | btrfs_start_ordered_extent(inode, ordered, 1); |
1559 | goto again; | 1566 | goto again; |
1560 | } | 1567 | } |
1561 | 1568 | ||
1562 | btrfs_set_extent_delalloc(inode, page_start, page_end); | 1569 | btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); |
1563 | ClearPageChecked(page); | 1570 | ClearPageChecked(page); |
1564 | out: | 1571 | out: |
1565 | unlock_extent(&BTRFS_I(inode)->io_tree, page_start, page_end, GFP_NOFS); | 1572 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end, |
1573 | &cached_state, GFP_NOFS); | ||
1566 | out_page: | 1574 | out_page: |
1567 | unlock_page(page); | 1575 | unlock_page(page); |
1568 | page_cache_release(page); | 1576 | page_cache_release(page); |
@@ -1691,14 +1699,14 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1691 | struct btrfs_trans_handle *trans; | 1699 | struct btrfs_trans_handle *trans; |
1692 | struct btrfs_ordered_extent *ordered_extent = NULL; | 1700 | struct btrfs_ordered_extent *ordered_extent = NULL; |
1693 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 1701 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
1702 | struct extent_state *cached_state = NULL; | ||
1694 | int compressed = 0; | 1703 | int compressed = 0; |
1695 | int ret; | 1704 | int ret; |
1696 | 1705 | ||
1697 | ret = btrfs_dec_test_ordered_pending(inode, start, end - start + 1); | 1706 | ret = btrfs_dec_test_ordered_pending(inode, &ordered_extent, start, |
1707 | end - start + 1); | ||
1698 | if (!ret) | 1708 | if (!ret) |
1699 | return 0; | 1709 | return 0; |
1700 | |||
1701 | ordered_extent = btrfs_lookup_ordered_extent(inode, start); | ||
1702 | BUG_ON(!ordered_extent); | 1710 | BUG_ON(!ordered_extent); |
1703 | 1711 | ||
1704 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { | 1712 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { |
@@ -1713,9 +1721,9 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1713 | goto out; | 1721 | goto out; |
1714 | } | 1722 | } |
1715 | 1723 | ||
1716 | lock_extent(io_tree, ordered_extent->file_offset, | 1724 | lock_extent_bits(io_tree, ordered_extent->file_offset, |
1717 | ordered_extent->file_offset + ordered_extent->len - 1, | 1725 | ordered_extent->file_offset + ordered_extent->len - 1, |
1718 | GFP_NOFS); | 1726 | 0, &cached_state, GFP_NOFS); |
1719 | 1727 | ||
1720 | trans = btrfs_join_transaction(root, 1); | 1728 | trans = btrfs_join_transaction(root, 1); |
1721 | 1729 | ||
@@ -1742,9 +1750,10 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1742 | ordered_extent->len); | 1750 | ordered_extent->len); |
1743 | BUG_ON(ret); | 1751 | BUG_ON(ret); |
1744 | } | 1752 | } |
1745 | unlock_extent(io_tree, ordered_extent->file_offset, | 1753 | unlock_extent_cached(io_tree, ordered_extent->file_offset, |
1746 | ordered_extent->file_offset + ordered_extent->len - 1, | 1754 | ordered_extent->file_offset + |
1747 | GFP_NOFS); | 1755 | ordered_extent->len - 1, &cached_state, GFP_NOFS); |
1756 | |||
1748 | add_pending_csums(trans, inode, ordered_extent->file_offset, | 1757 | add_pending_csums(trans, inode, ordered_extent->file_offset, |
1749 | &ordered_extent->list); | 1758 | &ordered_extent->list); |
1750 | 1759 | ||
@@ -2153,7 +2162,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) | |||
2153 | found_key.objectid = found_key.offset; | 2162 | found_key.objectid = found_key.offset; |
2154 | found_key.type = BTRFS_INODE_ITEM_KEY; | 2163 | found_key.type = BTRFS_INODE_ITEM_KEY; |
2155 | found_key.offset = 0; | 2164 | found_key.offset = 0; |
2156 | inode = btrfs_iget(root->fs_info->sb, &found_key, root); | 2165 | inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); |
2157 | if (IS_ERR(inode)) | 2166 | if (IS_ERR(inode)) |
2158 | break; | 2167 | break; |
2159 | 2168 | ||
@@ -3081,6 +3090,7 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) | |||
3081 | struct btrfs_root *root = BTRFS_I(inode)->root; | 3090 | struct btrfs_root *root = BTRFS_I(inode)->root; |
3082 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 3091 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
3083 | struct btrfs_ordered_extent *ordered; | 3092 | struct btrfs_ordered_extent *ordered; |
3093 | struct extent_state *cached_state = NULL; | ||
3084 | char *kaddr; | 3094 | char *kaddr; |
3085 | u32 blocksize = root->sectorsize; | 3095 | u32 blocksize = root->sectorsize; |
3086 | pgoff_t index = from >> PAGE_CACHE_SHIFT; | 3096 | pgoff_t index = from >> PAGE_CACHE_SHIFT; |
@@ -3127,12 +3137,14 @@ again: | |||
3127 | } | 3137 | } |
3128 | wait_on_page_writeback(page); | 3138 | wait_on_page_writeback(page); |
3129 | 3139 | ||
3130 | lock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3140 | lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state, |
3141 | GFP_NOFS); | ||
3131 | set_page_extent_mapped(page); | 3142 | set_page_extent_mapped(page); |
3132 | 3143 | ||
3133 | ordered = btrfs_lookup_ordered_extent(inode, page_start); | 3144 | ordered = btrfs_lookup_ordered_extent(inode, page_start); |
3134 | if (ordered) { | 3145 | if (ordered) { |
3135 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3146 | unlock_extent_cached(io_tree, page_start, page_end, |
3147 | &cached_state, GFP_NOFS); | ||
3136 | unlock_page(page); | 3148 | unlock_page(page); |
3137 | page_cache_release(page); | 3149 | page_cache_release(page); |
3138 | btrfs_start_ordered_extent(inode, ordered, 1); | 3150 | btrfs_start_ordered_extent(inode, ordered, 1); |
@@ -3140,13 +3152,15 @@ again: | |||
3140 | goto again; | 3152 | goto again; |
3141 | } | 3153 | } |
3142 | 3154 | ||
3143 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | 3155 | clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, |
3144 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, | 3156 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, |
3145 | GFP_NOFS); | 3157 | 0, 0, &cached_state, GFP_NOFS); |
3146 | 3158 | ||
3147 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 3159 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end, |
3160 | &cached_state); | ||
3148 | if (ret) { | 3161 | if (ret) { |
3149 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3162 | unlock_extent_cached(io_tree, page_start, page_end, |
3163 | &cached_state, GFP_NOFS); | ||
3150 | goto out_unlock; | 3164 | goto out_unlock; |
3151 | } | 3165 | } |
3152 | 3166 | ||
@@ -3159,7 +3173,8 @@ again: | |||
3159 | } | 3173 | } |
3160 | ClearPageChecked(page); | 3174 | ClearPageChecked(page); |
3161 | set_page_dirty(page); | 3175 | set_page_dirty(page); |
3162 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 3176 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, |
3177 | GFP_NOFS); | ||
3163 | 3178 | ||
3164 | out_unlock: | 3179 | out_unlock: |
3165 | if (ret) | 3180 | if (ret) |
@@ -3177,6 +3192,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3177 | struct btrfs_root *root = BTRFS_I(inode)->root; | 3192 | struct btrfs_root *root = BTRFS_I(inode)->root; |
3178 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 3193 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
3179 | struct extent_map *em; | 3194 | struct extent_map *em; |
3195 | struct extent_state *cached_state = NULL; | ||
3180 | u64 mask = root->sectorsize - 1; | 3196 | u64 mask = root->sectorsize - 1; |
3181 | u64 hole_start = (inode->i_size + mask) & ~mask; | 3197 | u64 hole_start = (inode->i_size + mask) & ~mask; |
3182 | u64 block_end = (size + mask) & ~mask; | 3198 | u64 block_end = (size + mask) & ~mask; |
@@ -3192,11 +3208,13 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3192 | struct btrfs_ordered_extent *ordered; | 3208 | struct btrfs_ordered_extent *ordered; |
3193 | btrfs_wait_ordered_range(inode, hole_start, | 3209 | btrfs_wait_ordered_range(inode, hole_start, |
3194 | block_end - hole_start); | 3210 | block_end - hole_start); |
3195 | lock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 3211 | lock_extent_bits(io_tree, hole_start, block_end - 1, 0, |
3212 | &cached_state, GFP_NOFS); | ||
3196 | ordered = btrfs_lookup_ordered_extent(inode, hole_start); | 3213 | ordered = btrfs_lookup_ordered_extent(inode, hole_start); |
3197 | if (!ordered) | 3214 | if (!ordered) |
3198 | break; | 3215 | break; |
3199 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 3216 | unlock_extent_cached(io_tree, hole_start, block_end - 1, |
3217 | &cached_state, GFP_NOFS); | ||
3200 | btrfs_put_ordered_extent(ordered); | 3218 | btrfs_put_ordered_extent(ordered); |
3201 | } | 3219 | } |
3202 | 3220 | ||
@@ -3241,7 +3259,8 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) | |||
3241 | break; | 3259 | break; |
3242 | } | 3260 | } |
3243 | 3261 | ||
3244 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 3262 | unlock_extent_cached(io_tree, hole_start, block_end - 1, &cached_state, |
3263 | GFP_NOFS); | ||
3245 | return err; | 3264 | return err; |
3246 | } | 3265 | } |
3247 | 3266 | ||
@@ -3639,6 +3658,7 @@ static noinline void init_btrfs_i(struct inode *inode) | |||
3639 | bi->index_cnt = (u64)-1; | 3658 | bi->index_cnt = (u64)-1; |
3640 | bi->last_unlink_trans = 0; | 3659 | bi->last_unlink_trans = 0; |
3641 | bi->ordered_data_close = 0; | 3660 | bi->ordered_data_close = 0; |
3661 | bi->force_compress = 0; | ||
3642 | extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); | 3662 | extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); |
3643 | extent_io_tree_init(&BTRFS_I(inode)->io_tree, | 3663 | extent_io_tree_init(&BTRFS_I(inode)->io_tree, |
3644 | inode->i_mapping, GFP_NOFS); | 3664 | inode->i_mapping, GFP_NOFS); |
@@ -3687,7 +3707,7 @@ static struct inode *btrfs_iget_locked(struct super_block *s, | |||
3687 | * Returns in *is_new if the inode was read from disk | 3707 | * Returns in *is_new if the inode was read from disk |
3688 | */ | 3708 | */ |
3689 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, | 3709 | struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, |
3690 | struct btrfs_root *root) | 3710 | struct btrfs_root *root, int *new) |
3691 | { | 3711 | { |
3692 | struct inode *inode; | 3712 | struct inode *inode; |
3693 | 3713 | ||
@@ -3702,6 +3722,8 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, | |||
3702 | 3722 | ||
3703 | inode_tree_add(inode); | 3723 | inode_tree_add(inode); |
3704 | unlock_new_inode(inode); | 3724 | unlock_new_inode(inode); |
3725 | if (new) | ||
3726 | *new = 1; | ||
3705 | } | 3727 | } |
3706 | 3728 | ||
3707 | return inode; | 3729 | return inode; |
@@ -3754,7 +3776,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3754 | return NULL; | 3776 | return NULL; |
3755 | 3777 | ||
3756 | if (location.type == BTRFS_INODE_ITEM_KEY) { | 3778 | if (location.type == BTRFS_INODE_ITEM_KEY) { |
3757 | inode = btrfs_iget(dir->i_sb, &location, root); | 3779 | inode = btrfs_iget(dir->i_sb, &location, root, NULL); |
3758 | return inode; | 3780 | return inode; |
3759 | } | 3781 | } |
3760 | 3782 | ||
@@ -3769,7 +3791,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3769 | else | 3791 | else |
3770 | inode = new_simple_dir(dir->i_sb, &location, sub_root); | 3792 | inode = new_simple_dir(dir->i_sb, &location, sub_root); |
3771 | } else { | 3793 | } else { |
3772 | inode = btrfs_iget(dir->i_sb, &location, sub_root); | 3794 | inode = btrfs_iget(dir->i_sb, &location, sub_root, NULL); |
3773 | } | 3795 | } |
3774 | srcu_read_unlock(&root->fs_info->subvol_srcu, index); | 3796 | srcu_read_unlock(&root->fs_info->subvol_srcu, index); |
3775 | 3797 | ||
@@ -4501,7 +4523,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
4501 | err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); | 4523 | err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); |
4502 | if (err) { | 4524 | if (err) { |
4503 | err = -ENOSPC; | 4525 | err = -ENOSPC; |
4504 | goto out_unlock; | 4526 | goto out_fail; |
4505 | } | 4527 | } |
4506 | 4528 | ||
4507 | inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, | 4529 | inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, |
@@ -4979,6 +5001,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4979 | { | 5001 | { |
4980 | struct extent_io_tree *tree; | 5002 | struct extent_io_tree *tree; |
4981 | struct btrfs_ordered_extent *ordered; | 5003 | struct btrfs_ordered_extent *ordered; |
5004 | struct extent_state *cached_state = NULL; | ||
4982 | u64 page_start = page_offset(page); | 5005 | u64 page_start = page_offset(page); |
4983 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; | 5006 | u64 page_end = page_start + PAGE_CACHE_SIZE - 1; |
4984 | 5007 | ||
@@ -4997,7 +5020,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
4997 | btrfs_releasepage(page, GFP_NOFS); | 5020 | btrfs_releasepage(page, GFP_NOFS); |
4998 | return; | 5021 | return; |
4999 | } | 5022 | } |
5000 | lock_extent(tree, page_start, page_end, GFP_NOFS); | 5023 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state, |
5024 | GFP_NOFS); | ||
5001 | ordered = btrfs_lookup_ordered_extent(page->mapping->host, | 5025 | ordered = btrfs_lookup_ordered_extent(page->mapping->host, |
5002 | page_offset(page)); | 5026 | page_offset(page)); |
5003 | if (ordered) { | 5027 | if (ordered) { |
@@ -5008,7 +5032,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
5008 | clear_extent_bit(tree, page_start, page_end, | 5032 | clear_extent_bit(tree, page_start, page_end, |
5009 | EXTENT_DIRTY | EXTENT_DELALLOC | | 5033 | EXTENT_DIRTY | EXTENT_DELALLOC | |
5010 | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING, 1, 0, | 5034 | EXTENT_LOCKED | EXTENT_DO_ACCOUNTING, 1, 0, |
5011 | NULL, GFP_NOFS); | 5035 | &cached_state, GFP_NOFS); |
5012 | /* | 5036 | /* |
5013 | * whoever cleared the private bit is responsible | 5037 | * whoever cleared the private bit is responsible |
5014 | * for the finish_ordered_io | 5038 | * for the finish_ordered_io |
@@ -5018,11 +5042,13 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) | |||
5018 | page_start, page_end); | 5042 | page_start, page_end); |
5019 | } | 5043 | } |
5020 | btrfs_put_ordered_extent(ordered); | 5044 | btrfs_put_ordered_extent(ordered); |
5021 | lock_extent(tree, page_start, page_end, GFP_NOFS); | 5045 | cached_state = NULL; |
5046 | lock_extent_bits(tree, page_start, page_end, 0, &cached_state, | ||
5047 | GFP_NOFS); | ||
5022 | } | 5048 | } |
5023 | clear_extent_bit(tree, page_start, page_end, | 5049 | clear_extent_bit(tree, page_start, page_end, |
5024 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | | 5050 | EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | |
5025 | EXTENT_DO_ACCOUNTING, 1, 1, NULL, GFP_NOFS); | 5051 | EXTENT_DO_ACCOUNTING, 1, 1, &cached_state, GFP_NOFS); |
5026 | __btrfs_releasepage(page, GFP_NOFS); | 5052 | __btrfs_releasepage(page, GFP_NOFS); |
5027 | 5053 | ||
5028 | ClearPageChecked(page); | 5054 | ClearPageChecked(page); |
@@ -5055,6 +5081,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
5055 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5081 | struct btrfs_root *root = BTRFS_I(inode)->root; |
5056 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 5082 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
5057 | struct btrfs_ordered_extent *ordered; | 5083 | struct btrfs_ordered_extent *ordered; |
5084 | struct extent_state *cached_state = NULL; | ||
5058 | char *kaddr; | 5085 | char *kaddr; |
5059 | unsigned long zero_start; | 5086 | unsigned long zero_start; |
5060 | loff_t size; | 5087 | loff_t size; |
@@ -5093,7 +5120,8 @@ again: | |||
5093 | } | 5120 | } |
5094 | wait_on_page_writeback(page); | 5121 | wait_on_page_writeback(page); |
5095 | 5122 | ||
5096 | lock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5123 | lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state, |
5124 | GFP_NOFS); | ||
5097 | set_page_extent_mapped(page); | 5125 | set_page_extent_mapped(page); |
5098 | 5126 | ||
5099 | /* | 5127 | /* |
@@ -5102,7 +5130,8 @@ again: | |||
5102 | */ | 5130 | */ |
5103 | ordered = btrfs_lookup_ordered_extent(inode, page_start); | 5131 | ordered = btrfs_lookup_ordered_extent(inode, page_start); |
5104 | if (ordered) { | 5132 | if (ordered) { |
5105 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5133 | unlock_extent_cached(io_tree, page_start, page_end, |
5134 | &cached_state, GFP_NOFS); | ||
5106 | unlock_page(page); | 5135 | unlock_page(page); |
5107 | btrfs_start_ordered_extent(inode, ordered, 1); | 5136 | btrfs_start_ordered_extent(inode, ordered, 1); |
5108 | btrfs_put_ordered_extent(ordered); | 5137 | btrfs_put_ordered_extent(ordered); |
@@ -5116,13 +5145,15 @@ again: | |||
5116 | * is probably a better way to do this, but for now keep consistent with | 5145 | * is probably a better way to do this, but for now keep consistent with |
5117 | * prepare_pages in the normal write path. | 5146 | * prepare_pages in the normal write path. |
5118 | */ | 5147 | */ |
5119 | clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, | 5148 | clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, |
5120 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, | 5149 | EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, |
5121 | GFP_NOFS); | 5150 | 0, 0, &cached_state, GFP_NOFS); |
5122 | 5151 | ||
5123 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end); | 5152 | ret = btrfs_set_extent_delalloc(inode, page_start, page_end, |
5153 | &cached_state); | ||
5124 | if (ret) { | 5154 | if (ret) { |
5125 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5155 | unlock_extent_cached(io_tree, page_start, page_end, |
5156 | &cached_state, GFP_NOFS); | ||
5126 | ret = VM_FAULT_SIGBUS; | 5157 | ret = VM_FAULT_SIGBUS; |
5127 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | 5158 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); |
5128 | goto out_unlock; | 5159 | goto out_unlock; |
@@ -5148,7 +5179,7 @@ again: | |||
5148 | BTRFS_I(inode)->last_trans = root->fs_info->generation; | 5179 | BTRFS_I(inode)->last_trans = root->fs_info->generation; |
5149 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; | 5180 | BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; |
5150 | 5181 | ||
5151 | unlock_extent(io_tree, page_start, page_end, GFP_NOFS); | 5182 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); |
5152 | 5183 | ||
5153 | out_unlock: | 5184 | out_unlock: |
5154 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | 5185 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); |
@@ -5827,6 +5858,7 @@ stop_trans: | |||
5827 | static long btrfs_fallocate(struct inode *inode, int mode, | 5858 | static long btrfs_fallocate(struct inode *inode, int mode, |
5828 | loff_t offset, loff_t len) | 5859 | loff_t offset, loff_t len) |
5829 | { | 5860 | { |
5861 | struct extent_state *cached_state = NULL; | ||
5830 | u64 cur_offset; | 5862 | u64 cur_offset; |
5831 | u64 last_byte; | 5863 | u64 last_byte; |
5832 | u64 alloc_start; | 5864 | u64 alloc_start; |
@@ -5865,16 +5897,17 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5865 | /* the extent lock is ordered inside the running | 5897 | /* the extent lock is ordered inside the running |
5866 | * transaction | 5898 | * transaction |
5867 | */ | 5899 | */ |
5868 | lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, | 5900 | lock_extent_bits(&BTRFS_I(inode)->io_tree, alloc_start, |
5869 | GFP_NOFS); | 5901 | locked_end, 0, &cached_state, GFP_NOFS); |
5870 | ordered = btrfs_lookup_first_ordered_extent(inode, | 5902 | ordered = btrfs_lookup_first_ordered_extent(inode, |
5871 | alloc_end - 1); | 5903 | alloc_end - 1); |
5872 | if (ordered && | 5904 | if (ordered && |
5873 | ordered->file_offset + ordered->len > alloc_start && | 5905 | ordered->file_offset + ordered->len > alloc_start && |
5874 | ordered->file_offset < alloc_end) { | 5906 | ordered->file_offset < alloc_end) { |
5875 | btrfs_put_ordered_extent(ordered); | 5907 | btrfs_put_ordered_extent(ordered); |
5876 | unlock_extent(&BTRFS_I(inode)->io_tree, | 5908 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, |
5877 | alloc_start, locked_end, GFP_NOFS); | 5909 | alloc_start, locked_end, |
5910 | &cached_state, GFP_NOFS); | ||
5878 | /* | 5911 | /* |
5879 | * we can't wait on the range with the transaction | 5912 | * we can't wait on the range with the transaction |
5880 | * running or with the extent lock held | 5913 | * running or with the extent lock held |
@@ -5916,8 +5949,8 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5916 | break; | 5949 | break; |
5917 | } | 5950 | } |
5918 | } | 5951 | } |
5919 | unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, | 5952 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, |
5920 | GFP_NOFS); | 5953 | &cached_state, GFP_NOFS); |
5921 | 5954 | ||
5922 | btrfs_free_reserved_data_space(BTRFS_I(inode)->root, inode, | 5955 | btrfs_free_reserved_data_space(BTRFS_I(inode)->root, inode, |
5923 | alloc_end - alloc_start); | 5956 | alloc_end - alloc_start); |