diff options
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 72 |
1 files changed, 16 insertions, 56 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b330e27c2d8b..4deb280f8969 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -483,7 +483,8 @@ again: | |||
483 | nr_pages_ret = 0; | 483 | nr_pages_ret = 0; |
484 | 484 | ||
485 | /* flag the file so we don't compress in the future */ | 485 | /* flag the file so we don't compress in the future */ |
486 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; | 486 | if (!btrfs_test_opt(root, FORCE_COMPRESS)) |
487 | BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; | ||
487 | } | 488 | } |
488 | if (will_compress) { | 489 | if (will_compress) { |
489 | *num_added += 1; | 490 | *num_added += 1; |
@@ -1680,24 +1681,6 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1680 | * before we start the transaction. It limits the amount of btree | 1681 | * before we start the transaction. It limits the amount of btree |
1681 | * reads required while inside the transaction. | 1682 | * reads required while inside the transaction. |
1682 | */ | 1683 | */ |
1683 | static noinline void reada_csum(struct btrfs_root *root, | ||
1684 | struct btrfs_path *path, | ||
1685 | struct btrfs_ordered_extent *ordered_extent) | ||
1686 | { | ||
1687 | struct btrfs_ordered_sum *sum; | ||
1688 | u64 bytenr; | ||
1689 | |||
1690 | sum = list_entry(ordered_extent->list.next, struct btrfs_ordered_sum, | ||
1691 | list); | ||
1692 | bytenr = sum->sums[0].bytenr; | ||
1693 | |||
1694 | /* | ||
1695 | * we don't care about the results, the point of this search is | ||
1696 | * just to get the btree leaves into ram | ||
1697 | */ | ||
1698 | btrfs_lookup_csum(NULL, root->fs_info->csum_root, path, bytenr, 0); | ||
1699 | } | ||
1700 | |||
1701 | /* as ordered data IO finishes, this gets called so we can finish | 1684 | /* as ordered data IO finishes, this gets called so we can finish |
1702 | * an ordered extent if the range of bytes in the file it covers are | 1685 | * an ordered extent if the range of bytes in the file it covers are |
1703 | * fully written. | 1686 | * fully written. |
@@ -1708,7 +1691,6 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1708 | struct btrfs_trans_handle *trans; | 1691 | struct btrfs_trans_handle *trans; |
1709 | struct btrfs_ordered_extent *ordered_extent = NULL; | 1692 | struct btrfs_ordered_extent *ordered_extent = NULL; |
1710 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 1693 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
1711 | struct btrfs_path *path; | ||
1712 | int compressed = 0; | 1694 | int compressed = 0; |
1713 | int ret; | 1695 | int ret; |
1714 | 1696 | ||
@@ -1716,32 +1698,9 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1716 | if (!ret) | 1698 | if (!ret) |
1717 | return 0; | 1699 | return 0; |
1718 | 1700 | ||
1719 | /* | 1701 | ordered_extent = btrfs_lookup_ordered_extent(inode, start); |
1720 | * before we join the transaction, try to do some of our IO. | ||
1721 | * This will limit the amount of IO that we have to do with | ||
1722 | * the transaction running. We're unlikely to need to do any | ||
1723 | * IO if the file extents are new, the disk_i_size checks | ||
1724 | * covers the most common case. | ||
1725 | */ | ||
1726 | if (start < BTRFS_I(inode)->disk_i_size) { | ||
1727 | path = btrfs_alloc_path(); | ||
1728 | if (path) { | ||
1729 | ret = btrfs_lookup_file_extent(NULL, root, path, | ||
1730 | inode->i_ino, | ||
1731 | start, 0); | ||
1732 | ordered_extent = btrfs_lookup_ordered_extent(inode, | ||
1733 | start); | ||
1734 | if (!list_empty(&ordered_extent->list)) { | ||
1735 | btrfs_release_path(root, path); | ||
1736 | reada_csum(root, path, ordered_extent); | ||
1737 | } | ||
1738 | btrfs_free_path(path); | ||
1739 | } | ||
1740 | } | ||
1741 | |||
1742 | if (!ordered_extent) | ||
1743 | ordered_extent = btrfs_lookup_ordered_extent(inode, start); | ||
1744 | BUG_ON(!ordered_extent); | 1702 | BUG_ON(!ordered_extent); |
1703 | |||
1745 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { | 1704 | if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { |
1746 | BUG_ON(!list_empty(&ordered_extent->list)); | 1705 | BUG_ON(!list_empty(&ordered_extent->list)); |
1747 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); | 1706 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
@@ -3796,12 +3755,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) | |||
3796 | 3755 | ||
3797 | if (location.type == BTRFS_INODE_ITEM_KEY) { | 3756 | if (location.type == BTRFS_INODE_ITEM_KEY) { |
3798 | inode = btrfs_iget(dir->i_sb, &location, root); | 3757 | inode = btrfs_iget(dir->i_sb, &location, root); |
3799 | if (unlikely(root->clean_orphans) && | ||
3800 | !(inode->i_sb->s_flags & MS_RDONLY)) { | ||
3801 | down_read(&root->fs_info->cleanup_work_sem); | ||
3802 | btrfs_orphan_cleanup(root); | ||
3803 | up_read(&root->fs_info->cleanup_work_sem); | ||
3804 | } | ||
3805 | return inode; | 3758 | return inode; |
3806 | } | 3759 | } |
3807 | 3760 | ||
@@ -5799,7 +5752,7 @@ out_fail: | |||
5799 | } | 5752 | } |
5800 | 5753 | ||
5801 | static int prealloc_file_range(struct inode *inode, u64 start, u64 end, | 5754 | static int prealloc_file_range(struct inode *inode, u64 start, u64 end, |
5802 | u64 alloc_hint, int mode) | 5755 | u64 alloc_hint, int mode, loff_t actual_len) |
5803 | { | 5756 | { |
5804 | struct btrfs_trans_handle *trans; | 5757 | struct btrfs_trans_handle *trans; |
5805 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5758 | struct btrfs_root *root = BTRFS_I(inode)->root; |
@@ -5808,6 +5761,7 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, | |||
5808 | u64 cur_offset = start; | 5761 | u64 cur_offset = start; |
5809 | u64 num_bytes = end - start; | 5762 | u64 num_bytes = end - start; |
5810 | int ret = 0; | 5763 | int ret = 0; |
5764 | u64 i_size; | ||
5811 | 5765 | ||
5812 | while (num_bytes > 0) { | 5766 | while (num_bytes > 0) { |
5813 | alloc_size = min(num_bytes, root->fs_info->max_extent); | 5767 | alloc_size = min(num_bytes, root->fs_info->max_extent); |
@@ -5845,9 +5799,15 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, | |||
5845 | inode->i_ctime = CURRENT_TIME; | 5799 | inode->i_ctime = CURRENT_TIME; |
5846 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; | 5800 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
5847 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 5801 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
5848 | cur_offset > inode->i_size) { | 5802 | (actual_len > inode->i_size) && |
5849 | i_size_write(inode, cur_offset); | 5803 | (cur_offset > inode->i_size)) { |
5850 | btrfs_ordered_update_i_size(inode, cur_offset, NULL); | 5804 | |
5805 | if (cur_offset > actual_len) | ||
5806 | i_size = actual_len; | ||
5807 | else | ||
5808 | i_size = cur_offset; | ||
5809 | i_size_write(inode, i_size); | ||
5810 | btrfs_ordered_update_i_size(inode, i_size, NULL); | ||
5851 | } | 5811 | } |
5852 | 5812 | ||
5853 | ret = btrfs_update_inode(trans, root, inode); | 5813 | ret = btrfs_update_inode(trans, root, inode); |
@@ -5940,7 +5900,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5940 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { | 5900 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { |
5941 | ret = prealloc_file_range(inode, | 5901 | ret = prealloc_file_range(inode, |
5942 | cur_offset, last_byte, | 5902 | cur_offset, last_byte, |
5943 | alloc_hint, mode); | 5903 | alloc_hint, mode, offset+len); |
5944 | if (ret < 0) { | 5904 | if (ret < 0) { |
5945 | free_extent_map(em); | 5905 | free_extent_map(em); |
5946 | break; | 5906 | break; |