diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 235 |
1 files changed, 107 insertions, 128 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 2c8caa51addb..ab807963a614 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -71,58 +71,6 @@ static int ext4_inode_is_fast_symlink(struct inode *inode) | |||
71 | } | 71 | } |
72 | 72 | ||
73 | /* | 73 | /* |
74 | * The ext4 forget function must perform a revoke if we are freeing data | ||
75 | * which has been journaled. Metadata (eg. indirect blocks) must be | ||
76 | * revoked in all cases. | ||
77 | * | ||
78 | * "bh" may be NULL: a metadata block may have been freed from memory | ||
79 | * but there may still be a record of it in the journal, and that record | ||
80 | * still needs to be revoked. | ||
81 | * | ||
82 | * If the handle isn't valid we're not journaling, but we still need to | ||
83 | * call into ext4_journal_revoke() to put the buffer head. | ||
84 | */ | ||
85 | int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode, | ||
86 | struct buffer_head *bh, ext4_fsblk_t blocknr) | ||
87 | { | ||
88 | int err; | ||
89 | |||
90 | might_sleep(); | ||
91 | |||
92 | BUFFER_TRACE(bh, "enter"); | ||
93 | |||
94 | jbd_debug(4, "forgetting bh %p: is_metadata = %d, mode %o, " | ||
95 | "data mode %x\n", | ||
96 | bh, is_metadata, inode->i_mode, | ||
97 | test_opt(inode->i_sb, DATA_FLAGS)); | ||
98 | |||
99 | /* Never use the revoke function if we are doing full data | ||
100 | * journaling: there is no need to, and a V1 superblock won't | ||
101 | * support it. Otherwise, only skip the revoke on un-journaled | ||
102 | * data blocks. */ | ||
103 | |||
104 | if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA || | ||
105 | (!is_metadata && !ext4_should_journal_data(inode))) { | ||
106 | if (bh) { | ||
107 | BUFFER_TRACE(bh, "call jbd2_journal_forget"); | ||
108 | return ext4_journal_forget(handle, bh); | ||
109 | } | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * data!=journal && (is_metadata || should_journal_data(inode)) | ||
115 | */ | ||
116 | BUFFER_TRACE(bh, "call ext4_journal_revoke"); | ||
117 | err = ext4_journal_revoke(handle, blocknr, bh); | ||
118 | if (err) | ||
119 | ext4_abort(inode->i_sb, __func__, | ||
120 | "error %d when attempting revoke", err); | ||
121 | BUFFER_TRACE(bh, "exit"); | ||
122 | return err; | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * Work out how many blocks we need to proceed with the next chunk of a | 74 | * Work out how many blocks we need to proceed with the next chunk of a |
127 | * truncate transaction. | 75 | * truncate transaction. |
128 | */ | 76 | */ |
@@ -721,7 +669,7 @@ allocated: | |||
721 | return ret; | 669 | return ret; |
722 | failed_out: | 670 | failed_out: |
723 | for (i = 0; i < index; i++) | 671 | for (i = 0; i < index; i++) |
724 | ext4_free_blocks(handle, inode, new_blocks[i], 1, 0); | 672 | ext4_free_blocks(handle, inode, 0, new_blocks[i], 1, 0); |
725 | return ret; | 673 | return ret; |
726 | } | 674 | } |
727 | 675 | ||
@@ -817,14 +765,20 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode, | |||
817 | return err; | 765 | return err; |
818 | failed: | 766 | failed: |
819 | /* Allocation failed, free what we already allocated */ | 767 | /* Allocation failed, free what we already allocated */ |
768 | ext4_free_blocks(handle, inode, 0, new_blocks[0], 1, 0); | ||
820 | for (i = 1; i <= n ; i++) { | 769 | for (i = 1; i <= n ; i++) { |
821 | BUFFER_TRACE(branch[i].bh, "call jbd2_journal_forget"); | 770 | /* |
822 | ext4_journal_forget(handle, branch[i].bh); | 771 | * branch[i].bh is newly allocated, so there is no |
772 | * need to revoke the block, which is why we don't | ||
773 | * need to set EXT4_FREE_BLOCKS_METADATA. | ||
774 | */ | ||
775 | ext4_free_blocks(handle, inode, 0, new_blocks[i], 1, | ||
776 | EXT4_FREE_BLOCKS_FORGET); | ||
823 | } | 777 | } |
824 | for (i = 0; i < indirect_blks; i++) | 778 | for (i = n+1; i < indirect_blks; i++) |
825 | ext4_free_blocks(handle, inode, new_blocks[i], 1, 0); | 779 | ext4_free_blocks(handle, inode, 0, new_blocks[i], 1, 0); |
826 | 780 | ||
827 | ext4_free_blocks(handle, inode, new_blocks[i], num, 0); | 781 | ext4_free_blocks(handle, inode, 0, new_blocks[i], num, 0); |
828 | 782 | ||
829 | return err; | 783 | return err; |
830 | } | 784 | } |
@@ -903,12 +857,16 @@ static int ext4_splice_branch(handle_t *handle, struct inode *inode, | |||
903 | 857 | ||
904 | err_out: | 858 | err_out: |
905 | for (i = 1; i <= num; i++) { | 859 | for (i = 1; i <= num; i++) { |
906 | BUFFER_TRACE(where[i].bh, "call jbd2_journal_forget"); | 860 | /* |
907 | ext4_journal_forget(handle, where[i].bh); | 861 | * branch[i].bh is newly allocated, so there is no |
908 | ext4_free_blocks(handle, inode, | 862 | * need to revoke the block, which is why we don't |
909 | le32_to_cpu(where[i-1].key), 1, 0); | 863 | * need to set EXT4_FREE_BLOCKS_METADATA. |
864 | */ | ||
865 | ext4_free_blocks(handle, inode, where[i].bh, 0, 1, | ||
866 | EXT4_FREE_BLOCKS_FORGET); | ||
910 | } | 867 | } |
911 | ext4_free_blocks(handle, inode, le32_to_cpu(where[num].key), blks, 0); | 868 | ext4_free_blocks(handle, inode, 0, le32_to_cpu(where[num].key), |
869 | blks, 0); | ||
912 | 870 | ||
913 | return err; | 871 | return err; |
914 | } | 872 | } |
@@ -1021,10 +979,12 @@ static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode, | |||
1021 | if (!err) | 979 | if (!err) |
1022 | err = ext4_splice_branch(handle, inode, iblock, | 980 | err = ext4_splice_branch(handle, inode, iblock, |
1023 | partial, indirect_blks, count); | 981 | partial, indirect_blks, count); |
1024 | else | 982 | if (err) |
1025 | goto cleanup; | 983 | goto cleanup; |
1026 | 984 | ||
1027 | set_buffer_new(bh_result); | 985 | set_buffer_new(bh_result); |
986 | |||
987 | ext4_update_inode_fsync_trans(handle, inode, 1); | ||
1028 | got_it: | 988 | got_it: |
1029 | map_bh(bh_result, inode->i_sb, le32_to_cpu(chain[depth-1].key)); | 989 | map_bh(bh_result, inode->i_sb, le32_to_cpu(chain[depth-1].key)); |
1030 | if (count > blocks_to_boundary) | 990 | if (count > blocks_to_boundary) |
@@ -1043,17 +1003,12 @@ out: | |||
1043 | return err; | 1003 | return err; |
1044 | } | 1004 | } |
1045 | 1005 | ||
1046 | qsize_t ext4_get_reserved_space(struct inode *inode) | 1006 | #ifdef CONFIG_QUOTA |
1007 | qsize_t *ext4_get_reserved_space(struct inode *inode) | ||
1047 | { | 1008 | { |
1048 | unsigned long long total; | 1009 | return &EXT4_I(inode)->i_reserved_quota; |
1049 | |||
1050 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1051 | total = EXT4_I(inode)->i_reserved_data_blocks + | ||
1052 | EXT4_I(inode)->i_reserved_meta_blocks; | ||
1053 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1054 | |||
1055 | return total; | ||
1056 | } | 1010 | } |
1011 | #endif | ||
1057 | /* | 1012 | /* |
1058 | * Calculate the number of metadata blocks need to reserve | 1013 | * Calculate the number of metadata blocks need to reserve |
1059 | * to allocate @blocks for non extent file based file | 1014 | * to allocate @blocks for non extent file based file |
@@ -1091,7 +1046,7 @@ static int ext4_calc_metadata_amount(struct inode *inode, int blocks) | |||
1091 | static void ext4_da_update_reserve_space(struct inode *inode, int used) | 1046 | static void ext4_da_update_reserve_space(struct inode *inode, int used) |
1092 | { | 1047 | { |
1093 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1048 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
1094 | int total, mdb, mdb_free; | 1049 | int total, mdb, mdb_free, mdb_claim = 0; |
1095 | 1050 | ||
1096 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | 1051 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); |
1097 | /* recalculate the number of metablocks still need to be reserved */ | 1052 | /* recalculate the number of metablocks still need to be reserved */ |
@@ -1104,7 +1059,9 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
1104 | 1059 | ||
1105 | if (mdb_free) { | 1060 | if (mdb_free) { |
1106 | /* Account for allocated meta_blocks */ | 1061 | /* Account for allocated meta_blocks */ |
1107 | mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks; | 1062 | mdb_claim = EXT4_I(inode)->i_allocated_meta_blocks; |
1063 | BUG_ON(mdb_free < mdb_claim); | ||
1064 | mdb_free -= mdb_claim; | ||
1108 | 1065 | ||
1109 | /* update fs dirty blocks counter */ | 1066 | /* update fs dirty blocks counter */ |
1110 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); | 1067 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); |
@@ -1115,8 +1072,11 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) | |||
1115 | /* update per-inode reservations */ | 1072 | /* update per-inode reservations */ |
1116 | BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); | 1073 | BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); |
1117 | EXT4_I(inode)->i_reserved_data_blocks -= used; | 1074 | EXT4_I(inode)->i_reserved_data_blocks -= used; |
1075 | percpu_counter_sub(&sbi->s_dirtyblocks_counter, used + mdb_claim); | ||
1118 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1076 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1119 | 1077 | ||
1078 | vfs_dq_claim_block(inode, used + mdb_claim); | ||
1079 | |||
1120 | /* | 1080 | /* |
1121 | * free those over-booking quota for metadata blocks | 1081 | * free those over-booking quota for metadata blocks |
1122 | */ | 1082 | */ |
@@ -1534,6 +1494,16 @@ static int do_journal_get_write_access(handle_t *handle, | |||
1534 | return ext4_journal_get_write_access(handle, bh); | 1494 | return ext4_journal_get_write_access(handle, bh); |
1535 | } | 1495 | } |
1536 | 1496 | ||
1497 | /* | ||
1498 | * Truncate blocks that were not used by write. We have to truncate the | ||
1499 | * pagecache as well so that corresponding buffers get properly unmapped. | ||
1500 | */ | ||
1501 | static void ext4_truncate_failed_write(struct inode *inode) | ||
1502 | { | ||
1503 | truncate_inode_pages(inode->i_mapping, inode->i_size); | ||
1504 | ext4_truncate(inode); | ||
1505 | } | ||
1506 | |||
1537 | static int ext4_write_begin(struct file *file, struct address_space *mapping, | 1507 | static int ext4_write_begin(struct file *file, struct address_space *mapping, |
1538 | loff_t pos, unsigned len, unsigned flags, | 1508 | loff_t pos, unsigned len, unsigned flags, |
1539 | struct page **pagep, void **fsdata) | 1509 | struct page **pagep, void **fsdata) |
@@ -1599,7 +1569,7 @@ retry: | |||
1599 | 1569 | ||
1600 | ext4_journal_stop(handle); | 1570 | ext4_journal_stop(handle); |
1601 | if (pos + len > inode->i_size) { | 1571 | if (pos + len > inode->i_size) { |
1602 | ext4_truncate(inode); | 1572 | ext4_truncate_failed_write(inode); |
1603 | /* | 1573 | /* |
1604 | * If truncate failed early the inode might | 1574 | * If truncate failed early the inode might |
1605 | * still be on the orphan list; we need to | 1575 | * still be on the orphan list; we need to |
@@ -1709,7 +1679,7 @@ static int ext4_ordered_write_end(struct file *file, | |||
1709 | ret = ret2; | 1679 | ret = ret2; |
1710 | 1680 | ||
1711 | if (pos + len > inode->i_size) { | 1681 | if (pos + len > inode->i_size) { |
1712 | ext4_truncate(inode); | 1682 | ext4_truncate_failed_write(inode); |
1713 | /* | 1683 | /* |
1714 | * If truncate failed early the inode might still be | 1684 | * If truncate failed early the inode might still be |
1715 | * on the orphan list; we need to make sure the inode | 1685 | * on the orphan list; we need to make sure the inode |
@@ -1751,7 +1721,7 @@ static int ext4_writeback_write_end(struct file *file, | |||
1751 | ret = ret2; | 1721 | ret = ret2; |
1752 | 1722 | ||
1753 | if (pos + len > inode->i_size) { | 1723 | if (pos + len > inode->i_size) { |
1754 | ext4_truncate(inode); | 1724 | ext4_truncate_failed_write(inode); |
1755 | /* | 1725 | /* |
1756 | * If truncate failed early the inode might still be | 1726 | * If truncate failed early the inode might still be |
1757 | * on the orphan list; we need to make sure the inode | 1727 | * on the orphan list; we need to make sure the inode |
@@ -1814,7 +1784,7 @@ static int ext4_journalled_write_end(struct file *file, | |||
1814 | if (!ret) | 1784 | if (!ret) |
1815 | ret = ret2; | 1785 | ret = ret2; |
1816 | if (pos + len > inode->i_size) { | 1786 | if (pos + len > inode->i_size) { |
1817 | ext4_truncate(inode); | 1787 | ext4_truncate_failed_write(inode); |
1818 | /* | 1788 | /* |
1819 | * If truncate failed early the inode might still be | 1789 | * If truncate failed early the inode might still be |
1820 | * on the orphan list; we need to make sure the inode | 1790 | * on the orphan list; we need to make sure the inode |
@@ -1846,19 +1816,17 @@ repeat: | |||
1846 | 1816 | ||
1847 | md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; | 1817 | md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; |
1848 | total = md_needed + nrblocks; | 1818 | total = md_needed + nrblocks; |
1819 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1849 | 1820 | ||
1850 | /* | 1821 | /* |
1851 | * Make quota reservation here to prevent quota overflow | 1822 | * Make quota reservation here to prevent quota overflow |
1852 | * later. Real quota accounting is done at pages writeout | 1823 | * later. Real quota accounting is done at pages writeout |
1853 | * time. | 1824 | * time. |
1854 | */ | 1825 | */ |
1855 | if (vfs_dq_reserve_block(inode, total)) { | 1826 | if (vfs_dq_reserve_block(inode, total)) |
1856 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1857 | return -EDQUOT; | 1827 | return -EDQUOT; |
1858 | } | ||
1859 | 1828 | ||
1860 | if (ext4_claim_free_blocks(sbi, total)) { | 1829 | if (ext4_claim_free_blocks(sbi, total)) { |
1861 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1862 | vfs_dq_release_reservation_block(inode, total); | 1830 | vfs_dq_release_reservation_block(inode, total); |
1863 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { | 1831 | if (ext4_should_retry_alloc(inode->i_sb, &retries)) { |
1864 | yield(); | 1832 | yield(); |
@@ -1866,10 +1834,11 @@ repeat: | |||
1866 | } | 1834 | } |
1867 | return -ENOSPC; | 1835 | return -ENOSPC; |
1868 | } | 1836 | } |
1837 | spin_lock(&EXT4_I(inode)->i_block_reservation_lock); | ||
1869 | EXT4_I(inode)->i_reserved_data_blocks += nrblocks; | 1838 | EXT4_I(inode)->i_reserved_data_blocks += nrblocks; |
1870 | EXT4_I(inode)->i_reserved_meta_blocks = mdblocks; | 1839 | EXT4_I(inode)->i_reserved_meta_blocks += md_needed; |
1871 | |||
1872 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); | 1840 | spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); |
1841 | |||
1873 | return 0; /* success */ | 1842 | return 0; /* success */ |
1874 | } | 1843 | } |
1875 | 1844 | ||
@@ -2600,7 +2569,6 @@ static int bput_one(handle_t *handle, struct buffer_head *bh) | |||
2600 | } | 2569 | } |
2601 | 2570 | ||
2602 | static int __ext4_journalled_writepage(struct page *page, | 2571 | static int __ext4_journalled_writepage(struct page *page, |
2603 | struct writeback_control *wbc, | ||
2604 | unsigned int len) | 2572 | unsigned int len) |
2605 | { | 2573 | { |
2606 | struct address_space *mapping = page->mapping; | 2574 | struct address_space *mapping = page->mapping; |
@@ -2758,7 +2726,7 @@ static int ext4_writepage(struct page *page, | |||
2758 | * doesn't seem much point in redirtying the page here. | 2726 | * doesn't seem much point in redirtying the page here. |
2759 | */ | 2727 | */ |
2760 | ClearPageChecked(page); | 2728 | ClearPageChecked(page); |
2761 | return __ext4_journalled_writepage(page, wbc, len); | 2729 | return __ext4_journalled_writepage(page, len); |
2762 | } | 2730 | } |
2763 | 2731 | ||
2764 | if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) | 2732 | if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) |
@@ -2788,7 +2756,7 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode) | |||
2788 | * number of contiguous block. So we will limit | 2756 | * number of contiguous block. So we will limit |
2789 | * number of contiguous block to a sane value | 2757 | * number of contiguous block to a sane value |
2790 | */ | 2758 | */ |
2791 | if (!(inode->i_flags & EXT4_EXTENTS_FL) && | 2759 | if (!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) && |
2792 | (max_blocks > EXT4_MAX_TRANS_DATA)) | 2760 | (max_blocks > EXT4_MAX_TRANS_DATA)) |
2793 | max_blocks = EXT4_MAX_TRANS_DATA; | 2761 | max_blocks = EXT4_MAX_TRANS_DATA; |
2794 | 2762 | ||
@@ -2933,7 +2901,7 @@ retry: | |||
2933 | ret = write_cache_pages(mapping, wbc, __mpage_da_writepage, | 2901 | ret = write_cache_pages(mapping, wbc, __mpage_da_writepage, |
2934 | &mpd); | 2902 | &mpd); |
2935 | /* | 2903 | /* |
2936 | * If we have a contigous extent of pages and we | 2904 | * If we have a contiguous extent of pages and we |
2937 | * haven't done the I/O yet, map the blocks and submit | 2905 | * haven't done the I/O yet, map the blocks and submit |
2938 | * them for I/O. | 2906 | * them for I/O. |
2939 | */ | 2907 | */ |
@@ -3091,7 +3059,7 @@ retry: | |||
3091 | * i_size_read because we hold i_mutex. | 3059 | * i_size_read because we hold i_mutex. |
3092 | */ | 3060 | */ |
3093 | if (pos + len > inode->i_size) | 3061 | if (pos + len > inode->i_size) |
3094 | ext4_truncate(inode); | 3062 | ext4_truncate_failed_write(inode); |
3095 | } | 3063 | } |
3096 | 3064 | ||
3097 | if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) | 3065 | if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) |
@@ -4064,7 +4032,7 @@ static Indirect *ext4_find_shared(struct inode *inode, int depth, | |||
4064 | int k, err; | 4032 | int k, err; |
4065 | 4033 | ||
4066 | *top = 0; | 4034 | *top = 0; |
4067 | /* Make k index the deepest non-null offest + 1 */ | 4035 | /* Make k index the deepest non-null offset + 1 */ |
4068 | for (k = depth; k > 1 && !offsets[k-1]; k--) | 4036 | for (k = depth; k > 1 && !offsets[k-1]; k--) |
4069 | ; | 4037 | ; |
4070 | partial = ext4_get_branch(inode, k, offsets, chain, &err); | 4038 | partial = ext4_get_branch(inode, k, offsets, chain, &err); |
@@ -4120,6 +4088,11 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode, | |||
4120 | __le32 *last) | 4088 | __le32 *last) |
4121 | { | 4089 | { |
4122 | __le32 *p; | 4090 | __le32 *p; |
4091 | int flags = EXT4_FREE_BLOCKS_FORGET; | ||
4092 | |||
4093 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | ||
4094 | flags |= EXT4_FREE_BLOCKS_METADATA; | ||
4095 | |||
4123 | if (try_to_extend_transaction(handle, inode)) { | 4096 | if (try_to_extend_transaction(handle, inode)) { |
4124 | if (bh) { | 4097 | if (bh) { |
4125 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); | 4098 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
@@ -4134,27 +4107,10 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode, | |||
4134 | } | 4107 | } |
4135 | } | 4108 | } |
4136 | 4109 | ||
4137 | /* | 4110 | for (p = first; p < last; p++) |
4138 | * Any buffers which are on the journal will be in memory. We | 4111 | *p = 0; |
4139 | * find them on the hash table so jbd2_journal_revoke() will | ||
4140 | * run jbd2_journal_forget() on them. We've already detached | ||
4141 | * each block from the file, so bforget() in | ||
4142 | * jbd2_journal_forget() should be safe. | ||
4143 | * | ||
4144 | * AKPM: turn on bforget in jbd2_journal_forget()!!! | ||
4145 | */ | ||
4146 | for (p = first; p < last; p++) { | ||
4147 | u32 nr = le32_to_cpu(*p); | ||
4148 | if (nr) { | ||
4149 | struct buffer_head *tbh; | ||
4150 | 4112 | ||
4151 | *p = 0; | 4113 | ext4_free_blocks(handle, inode, 0, block_to_free, count, flags); |
4152 | tbh = sb_find_get_block(inode->i_sb, nr); | ||
4153 | ext4_forget(handle, 0, inode, tbh, nr); | ||
4154 | } | ||
4155 | } | ||
4156 | |||
4157 | ext4_free_blocks(handle, inode, block_to_free, count, 0); | ||
4158 | } | 4114 | } |
4159 | 4115 | ||
4160 | /** | 4116 | /** |
@@ -4342,7 +4298,8 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, | |||
4342 | blocks_for_truncate(inode)); | 4298 | blocks_for_truncate(inode)); |
4343 | } | 4299 | } |
4344 | 4300 | ||
4345 | ext4_free_blocks(handle, inode, nr, 1, 1); | 4301 | ext4_free_blocks(handle, inode, 0, nr, 1, |
4302 | EXT4_FREE_BLOCKS_METADATA); | ||
4346 | 4303 | ||
4347 | if (parent_bh) { | 4304 | if (parent_bh) { |
4348 | /* | 4305 | /* |
@@ -4781,8 +4738,8 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4781 | struct ext4_iloc iloc; | 4738 | struct ext4_iloc iloc; |
4782 | struct ext4_inode *raw_inode; | 4739 | struct ext4_inode *raw_inode; |
4783 | struct ext4_inode_info *ei; | 4740 | struct ext4_inode_info *ei; |
4784 | struct buffer_head *bh; | ||
4785 | struct inode *inode; | 4741 | struct inode *inode; |
4742 | journal_t *journal = EXT4_SB(sb)->s_journal; | ||
4786 | long ret; | 4743 | long ret; |
4787 | int block; | 4744 | int block; |
4788 | 4745 | ||
@@ -4793,11 +4750,11 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4793 | return inode; | 4750 | return inode; |
4794 | 4751 | ||
4795 | ei = EXT4_I(inode); | 4752 | ei = EXT4_I(inode); |
4753 | iloc.bh = 0; | ||
4796 | 4754 | ||
4797 | ret = __ext4_get_inode_loc(inode, &iloc, 0); | 4755 | ret = __ext4_get_inode_loc(inode, &iloc, 0); |
4798 | if (ret < 0) | 4756 | if (ret < 0) |
4799 | goto bad_inode; | 4757 | goto bad_inode; |
4800 | bh = iloc.bh; | ||
4801 | raw_inode = ext4_raw_inode(&iloc); | 4758 | raw_inode = ext4_raw_inode(&iloc); |
4802 | inode->i_mode = le16_to_cpu(raw_inode->i_mode); | 4759 | inode->i_mode = le16_to_cpu(raw_inode->i_mode); |
4803 | inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); | 4760 | inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low); |
@@ -4820,7 +4777,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4820 | if (inode->i_mode == 0 || | 4777 | if (inode->i_mode == 0 || |
4821 | !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) { | 4778 | !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) { |
4822 | /* this inode is deleted */ | 4779 | /* this inode is deleted */ |
4823 | brelse(bh); | ||
4824 | ret = -ESTALE; | 4780 | ret = -ESTALE; |
4825 | goto bad_inode; | 4781 | goto bad_inode; |
4826 | } | 4782 | } |
@@ -4837,6 +4793,9 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4837 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; | 4793 | ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; |
4838 | inode->i_size = ext4_isize(raw_inode); | 4794 | inode->i_size = ext4_isize(raw_inode); |
4839 | ei->i_disksize = inode->i_size; | 4795 | ei->i_disksize = inode->i_size; |
4796 | #ifdef CONFIG_QUOTA | ||
4797 | ei->i_reserved_quota = 0; | ||
4798 | #endif | ||
4840 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); | 4799 | inode->i_generation = le32_to_cpu(raw_inode->i_generation); |
4841 | ei->i_block_group = iloc.block_group; | 4800 | ei->i_block_group = iloc.block_group; |
4842 | ei->i_last_alloc_group = ~0; | 4801 | ei->i_last_alloc_group = ~0; |
@@ -4848,11 +4807,35 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4848 | ei->i_data[block] = raw_inode->i_block[block]; | 4807 | ei->i_data[block] = raw_inode->i_block[block]; |
4849 | INIT_LIST_HEAD(&ei->i_orphan); | 4808 | INIT_LIST_HEAD(&ei->i_orphan); |
4850 | 4809 | ||
4810 | /* | ||
4811 | * Set transaction id's of transactions that have to be committed | ||
4812 | * to finish f[data]sync. We set them to currently running transaction | ||
4813 | * as we cannot be sure that the inode or some of its metadata isn't | ||
4814 | * part of the transaction - the inode could have been reclaimed and | ||
4815 | * now it is reread from disk. | ||
4816 | */ | ||
4817 | if (journal) { | ||
4818 | transaction_t *transaction; | ||
4819 | tid_t tid; | ||
4820 | |||
4821 | spin_lock(&journal->j_state_lock); | ||
4822 | if (journal->j_running_transaction) | ||
4823 | transaction = journal->j_running_transaction; | ||
4824 | else | ||
4825 | transaction = journal->j_committing_transaction; | ||
4826 | if (transaction) | ||
4827 | tid = transaction->t_tid; | ||
4828 | else | ||
4829 | tid = journal->j_commit_sequence; | ||
4830 | spin_unlock(&journal->j_state_lock); | ||
4831 | ei->i_sync_tid = tid; | ||
4832 | ei->i_datasync_tid = tid; | ||
4833 | } | ||
4834 | |||
4851 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { | 4835 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { |
4852 | ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); | 4836 | ei->i_extra_isize = le16_to_cpu(raw_inode->i_extra_isize); |
4853 | if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > | 4837 | if (EXT4_GOOD_OLD_INODE_SIZE + ei->i_extra_isize > |
4854 | EXT4_INODE_SIZE(inode->i_sb)) { | 4838 | EXT4_INODE_SIZE(inode->i_sb)) { |
4855 | brelse(bh); | ||
4856 | ret = -EIO; | 4839 | ret = -EIO; |
4857 | goto bad_inode; | 4840 | goto bad_inode; |
4858 | } | 4841 | } |
@@ -4884,10 +4867,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4884 | 4867 | ||
4885 | ret = 0; | 4868 | ret = 0; |
4886 | if (ei->i_file_acl && | 4869 | if (ei->i_file_acl && |
4887 | ((ei->i_file_acl < | 4870 | !ext4_data_block_valid(EXT4_SB(sb), ei->i_file_acl, 1)) { |
4888 | (le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block) + | ||
4889 | EXT4_SB(sb)->s_gdb_count)) || | ||
4890 | (ei->i_file_acl >= ext4_blocks_count(EXT4_SB(sb)->s_es)))) { | ||
4891 | ext4_error(sb, __func__, | 4871 | ext4_error(sb, __func__, |
4892 | "bad extended attribute block %llu in inode #%lu", | 4872 | "bad extended attribute block %llu in inode #%lu", |
4893 | ei->i_file_acl, inode->i_ino); | 4873 | ei->i_file_acl, inode->i_ino); |
@@ -4905,10 +4885,8 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4905 | /* Validate block references which are part of inode */ | 4885 | /* Validate block references which are part of inode */ |
4906 | ret = ext4_check_inode_blockref(inode); | 4886 | ret = ext4_check_inode_blockref(inode); |
4907 | } | 4887 | } |
4908 | if (ret) { | 4888 | if (ret) |
4909 | brelse(bh); | ||
4910 | goto bad_inode; | 4889 | goto bad_inode; |
4911 | } | ||
4912 | 4890 | ||
4913 | if (S_ISREG(inode->i_mode)) { | 4891 | if (S_ISREG(inode->i_mode)) { |
4914 | inode->i_op = &ext4_file_inode_operations; | 4892 | inode->i_op = &ext4_file_inode_operations; |
@@ -4936,7 +4914,6 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4936 | init_special_inode(inode, inode->i_mode, | 4914 | init_special_inode(inode, inode->i_mode, |
4937 | new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); | 4915 | new_decode_dev(le32_to_cpu(raw_inode->i_block[1]))); |
4938 | } else { | 4916 | } else { |
4939 | brelse(bh); | ||
4940 | ret = -EIO; | 4917 | ret = -EIO; |
4941 | ext4_error(inode->i_sb, __func__, | 4918 | ext4_error(inode->i_sb, __func__, |
4942 | "bogus i_mode (%o) for inode=%lu", | 4919 | "bogus i_mode (%o) for inode=%lu", |
@@ -4949,6 +4926,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4949 | return inode; | 4926 | return inode; |
4950 | 4927 | ||
4951 | bad_inode: | 4928 | bad_inode: |
4929 | brelse(iloc.bh); | ||
4952 | iget_failed(inode); | 4930 | iget_failed(inode); |
4953 | return ERR_PTR(ret); | 4931 | return ERR_PTR(ret); |
4954 | } | 4932 | } |
@@ -5108,6 +5086,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
5108 | err = rc; | 5086 | err = rc; |
5109 | ei->i_state &= ~EXT4_STATE_NEW; | 5087 | ei->i_state &= ~EXT4_STATE_NEW; |
5110 | 5088 | ||
5089 | ext4_update_inode_fsync_trans(handle, inode, 0); | ||
5111 | out_brelse: | 5090 | out_brelse: |
5112 | brelse(bh); | 5091 | brelse(bh); |
5113 | ext4_std_error(inode->i_sb, err); | 5092 | ext4_std_error(inode->i_sb, err); |
@@ -5227,8 +5206,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
5227 | 5206 | ||
5228 | /* (user+group)*(old+new) structure, inode write (sb, | 5207 | /* (user+group)*(old+new) structure, inode write (sb, |
5229 | * inode block, ? - but truncate inode update has it) */ | 5208 | * inode block, ? - but truncate inode update has it) */ |
5230 | handle = ext4_journal_start(inode, 2*(EXT4_QUOTA_INIT_BLOCKS(inode->i_sb)+ | 5209 | handle = ext4_journal_start(inode, (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb)+ |
5231 | EXT4_QUOTA_DEL_BLOCKS(inode->i_sb))+3); | 5210 | EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb))+3); |
5232 | if (IS_ERR(handle)) { | 5211 | if (IS_ERR(handle)) { |
5233 | error = PTR_ERR(handle); | 5212 | error = PTR_ERR(handle); |
5234 | goto err_out; | 5213 | goto err_out; |
@@ -5376,7 +5355,7 @@ static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk) | |||
5376 | * worse case, the indexs blocks spread over different block groups | 5355 | * worse case, the indexs blocks spread over different block groups |
5377 | * | 5356 | * |
5378 | * If datablocks are discontiguous, they are possible to spread over | 5357 | * If datablocks are discontiguous, they are possible to spread over |
5379 | * different block groups too. If they are contiugous, with flexbg, | 5358 | * different block groups too. If they are contiuguous, with flexbg, |
5380 | * they could still across block group boundary. | 5359 | * they could still across block group boundary. |
5381 | * | 5360 | * |
5382 | * Also account for superblock, inode, quota and xattr blocks | 5361 | * Also account for superblock, inode, quota and xattr blocks |
@@ -5452,7 +5431,7 @@ int ext4_writepage_trans_blocks(struct inode *inode) | |||
5452 | * Calculate the journal credits for a chunk of data modification. | 5431 | * Calculate the journal credits for a chunk of data modification. |
5453 | * | 5432 | * |
5454 | * This is called from DIO, fallocate or whoever calling | 5433 | * This is called from DIO, fallocate or whoever calling |
5455 | * ext4_get_blocks() to map/allocate a chunk of contigous disk blocks. | 5434 | * ext4_get_blocks() to map/allocate a chunk of contiguous disk blocks. |
5456 | * | 5435 | * |
5457 | * journal buffers for data blocks are not included here, as DIO | 5436 | * journal buffers for data blocks are not included here, as DIO |
5458 | * and fallocate do no need to journal data buffers. | 5437 | * and fallocate do no need to journal data buffers. |