diff options
Diffstat (limited to 'fs/btrfs/inode.c')
| -rw-r--r-- | fs/btrfs/inode.c | 72 |
1 files changed, 21 insertions, 51 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5440bab23635..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); |
| @@ -3995,7 +3954,11 @@ skip: | |||
| 3995 | 3954 | ||
| 3996 | /* Reached end of directory/root. Bump pos past the last item. */ | 3955 | /* Reached end of directory/root. Bump pos past the last item. */ |
| 3997 | if (key_type == BTRFS_DIR_INDEX_KEY) | 3956 | if (key_type == BTRFS_DIR_INDEX_KEY) |
| 3998 | filp->f_pos = INT_LIMIT(off_t); | 3957 | /* |
| 3958 | * 32-bit glibc will use getdents64, but then strtol - | ||
| 3959 | * so the last number we can serve is this. | ||
| 3960 | */ | ||
| 3961 | filp->f_pos = 0x7fffffff; | ||
| 3999 | else | 3962 | else |
| 4000 | filp->f_pos++; | 3963 | filp->f_pos++; |
| 4001 | nopos: | 3964 | nopos: |
| @@ -5789,7 +5752,7 @@ out_fail: | |||
| 5789 | } | 5752 | } |
| 5790 | 5753 | ||
| 5791 | 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, |
| 5792 | u64 alloc_hint, int mode) | 5755 | u64 alloc_hint, int mode, loff_t actual_len) |
| 5793 | { | 5756 | { |
| 5794 | struct btrfs_trans_handle *trans; | 5757 | struct btrfs_trans_handle *trans; |
| 5795 | struct btrfs_root *root = BTRFS_I(inode)->root; | 5758 | struct btrfs_root *root = BTRFS_I(inode)->root; |
| @@ -5798,6 +5761,7 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, | |||
| 5798 | u64 cur_offset = start; | 5761 | u64 cur_offset = start; |
| 5799 | u64 num_bytes = end - start; | 5762 | u64 num_bytes = end - start; |
| 5800 | int ret = 0; | 5763 | int ret = 0; |
| 5764 | u64 i_size; | ||
| 5801 | 5765 | ||
| 5802 | while (num_bytes > 0) { | 5766 | while (num_bytes > 0) { |
| 5803 | alloc_size = min(num_bytes, root->fs_info->max_extent); | 5767 | alloc_size = min(num_bytes, root->fs_info->max_extent); |
| @@ -5835,9 +5799,15 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end, | |||
| 5835 | inode->i_ctime = CURRENT_TIME; | 5799 | inode->i_ctime = CURRENT_TIME; |
| 5836 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; | 5800 | BTRFS_I(inode)->flags |= BTRFS_INODE_PREALLOC; |
| 5837 | if (!(mode & FALLOC_FL_KEEP_SIZE) && | 5801 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
| 5838 | cur_offset > inode->i_size) { | 5802 | (actual_len > inode->i_size) && |
| 5839 | i_size_write(inode, cur_offset); | 5803 | (cur_offset > inode->i_size)) { |
| 5840 | 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); | ||
| 5841 | } | 5811 | } |
| 5842 | 5812 | ||
| 5843 | ret = btrfs_update_inode(trans, root, inode); | 5813 | ret = btrfs_update_inode(trans, root, inode); |
| @@ -5930,7 +5900,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
| 5930 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { | 5900 | !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))) { |
| 5931 | ret = prealloc_file_range(inode, | 5901 | ret = prealloc_file_range(inode, |
| 5932 | cur_offset, last_byte, | 5902 | cur_offset, last_byte, |
| 5933 | alloc_hint, mode); | 5903 | alloc_hint, mode, offset+len); |
| 5934 | if (ret < 0) { | 5904 | if (ret < 0) { |
| 5935 | free_extent_map(em); | 5905 | free_extent_map(em); |
| 5936 | break; | 5906 | break; |
