diff options
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r-- | fs/ext4/extents.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 35f65cf4f318..4410cc3d6ee2 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -360,8 +360,10 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext) | |||
360 | { | 360 | { |
361 | ext4_fsblk_t block = ext4_ext_pblock(ext); | 361 | ext4_fsblk_t block = ext4_ext_pblock(ext); |
362 | int len = ext4_ext_get_actual_len(ext); | 362 | int len = ext4_ext_get_actual_len(ext); |
363 | ext4_lblk_t lblock = le32_to_cpu(ext->ee_block); | ||
364 | ext4_lblk_t last = lblock + len - 1; | ||
363 | 365 | ||
364 | if (len == 0) | 366 | if (lblock > last) |
365 | return 0; | 367 | return 0; |
366 | return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len); | 368 | return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len); |
367 | } | 369 | } |
@@ -387,11 +389,26 @@ static int ext4_valid_extent_entries(struct inode *inode, | |||
387 | if (depth == 0) { | 389 | if (depth == 0) { |
388 | /* leaf entries */ | 390 | /* leaf entries */ |
389 | struct ext4_extent *ext = EXT_FIRST_EXTENT(eh); | 391 | struct ext4_extent *ext = EXT_FIRST_EXTENT(eh); |
392 | struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es; | ||
393 | ext4_fsblk_t pblock = 0; | ||
394 | ext4_lblk_t lblock = 0; | ||
395 | ext4_lblk_t prev = 0; | ||
396 | int len = 0; | ||
390 | while (entries) { | 397 | while (entries) { |
391 | if (!ext4_valid_extent(inode, ext)) | 398 | if (!ext4_valid_extent(inode, ext)) |
392 | return 0; | 399 | return 0; |
400 | |||
401 | /* Check for overlapping extents */ | ||
402 | lblock = le32_to_cpu(ext->ee_block); | ||
403 | len = ext4_ext_get_actual_len(ext); | ||
404 | if ((lblock <= prev) && prev) { | ||
405 | pblock = ext4_ext_pblock(ext); | ||
406 | es->s_last_error_block = cpu_to_le64(pblock); | ||
407 | return 0; | ||
408 | } | ||
393 | ext++; | 409 | ext++; |
394 | entries--; | 410 | entries--; |
411 | prev = lblock + len - 1; | ||
395 | } | 412 | } |
396 | } else { | 413 | } else { |
397 | struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh); | 414 | struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh); |
@@ -1834,8 +1851,7 @@ static unsigned int ext4_ext_check_overlap(struct ext4_sb_info *sbi, | |||
1834 | depth = ext_depth(inode); | 1851 | depth = ext_depth(inode); |
1835 | if (!path[depth].p_ext) | 1852 | if (!path[depth].p_ext) |
1836 | goto out; | 1853 | goto out; |
1837 | b2 = le32_to_cpu(path[depth].p_ext->ee_block); | 1854 | b2 = EXT4_LBLK_CMASK(sbi, le32_to_cpu(path[depth].p_ext->ee_block)); |
1838 | b2 &= ~(sbi->s_cluster_ratio - 1); | ||
1839 | 1855 | ||
1840 | /* | 1856 | /* |
1841 | * get the next allocated block if the extent in the path | 1857 | * get the next allocated block if the extent in the path |
@@ -1845,7 +1861,7 @@ static unsigned int ext4_ext_check_overlap(struct ext4_sb_info *sbi, | |||
1845 | b2 = ext4_ext_next_allocated_block(path); | 1861 | b2 = ext4_ext_next_allocated_block(path); |
1846 | if (b2 == EXT_MAX_BLOCKS) | 1862 | if (b2 == EXT_MAX_BLOCKS) |
1847 | goto out; | 1863 | goto out; |
1848 | b2 &= ~(sbi->s_cluster_ratio - 1); | 1864 | b2 = EXT4_LBLK_CMASK(sbi, b2); |
1849 | } | 1865 | } |
1850 | 1866 | ||
1851 | /* check for wrap through zero on extent logical start block*/ | 1867 | /* check for wrap through zero on extent logical start block*/ |
@@ -2504,7 +2520,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode, | |||
2504 | * extent, we have to mark the cluster as used (store negative | 2520 | * extent, we have to mark the cluster as used (store negative |
2505 | * cluster number in partial_cluster). | 2521 | * cluster number in partial_cluster). |
2506 | */ | 2522 | */ |
2507 | unaligned = pblk & (sbi->s_cluster_ratio - 1); | 2523 | unaligned = EXT4_PBLK_COFF(sbi, pblk); |
2508 | if (unaligned && (ee_len == num) && | 2524 | if (unaligned && (ee_len == num) && |
2509 | (*partial_cluster != -((long long)EXT4_B2C(sbi, pblk)))) | 2525 | (*partial_cluster != -((long long)EXT4_B2C(sbi, pblk)))) |
2510 | *partial_cluster = EXT4_B2C(sbi, pblk); | 2526 | *partial_cluster = EXT4_B2C(sbi, pblk); |
@@ -2598,7 +2614,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, | |||
2598 | * accidentally freeing it later on | 2614 | * accidentally freeing it later on |
2599 | */ | 2615 | */ |
2600 | pblk = ext4_ext_pblock(ex); | 2616 | pblk = ext4_ext_pblock(ex); |
2601 | if (pblk & (sbi->s_cluster_ratio - 1)) | 2617 | if (EXT4_PBLK_COFF(sbi, pblk)) |
2602 | *partial_cluster = | 2618 | *partial_cluster = |
2603 | -((long long)EXT4_B2C(sbi, pblk)); | 2619 | -((long long)EXT4_B2C(sbi, pblk)); |
2604 | ex--; | 2620 | ex--; |
@@ -3753,7 +3769,7 @@ int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk) | |||
3753 | { | 3769 | { |
3754 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 3770 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
3755 | ext4_lblk_t lblk_start, lblk_end; | 3771 | ext4_lblk_t lblk_start, lblk_end; |
3756 | lblk_start = lblk & (~(sbi->s_cluster_ratio - 1)); | 3772 | lblk_start = EXT4_LBLK_CMASK(sbi, lblk); |
3757 | lblk_end = lblk_start + sbi->s_cluster_ratio - 1; | 3773 | lblk_end = lblk_start + sbi->s_cluster_ratio - 1; |
3758 | 3774 | ||
3759 | return ext4_find_delalloc_range(inode, lblk_start, lblk_end); | 3775 | return ext4_find_delalloc_range(inode, lblk_start, lblk_end); |
@@ -3812,9 +3828,9 @@ get_reserved_cluster_alloc(struct inode *inode, ext4_lblk_t lblk_start, | |||
3812 | trace_ext4_get_reserved_cluster_alloc(inode, lblk_start, num_blks); | 3828 | trace_ext4_get_reserved_cluster_alloc(inode, lblk_start, num_blks); |
3813 | 3829 | ||
3814 | /* Check towards left side */ | 3830 | /* Check towards left side */ |
3815 | c_offset = lblk_start & (sbi->s_cluster_ratio - 1); | 3831 | c_offset = EXT4_LBLK_COFF(sbi, lblk_start); |
3816 | if (c_offset) { | 3832 | if (c_offset) { |
3817 | lblk_from = lblk_start & (~(sbi->s_cluster_ratio - 1)); | 3833 | lblk_from = EXT4_LBLK_CMASK(sbi, lblk_start); |
3818 | lblk_to = lblk_from + c_offset - 1; | 3834 | lblk_to = lblk_from + c_offset - 1; |
3819 | 3835 | ||
3820 | if (ext4_find_delalloc_range(inode, lblk_from, lblk_to)) | 3836 | if (ext4_find_delalloc_range(inode, lblk_from, lblk_to)) |
@@ -3822,7 +3838,7 @@ get_reserved_cluster_alloc(struct inode *inode, ext4_lblk_t lblk_start, | |||
3822 | } | 3838 | } |
3823 | 3839 | ||
3824 | /* Now check towards right. */ | 3840 | /* Now check towards right. */ |
3825 | c_offset = (lblk_start + num_blks) & (sbi->s_cluster_ratio - 1); | 3841 | c_offset = EXT4_LBLK_COFF(sbi, lblk_start + num_blks); |
3826 | if (allocated_clusters && c_offset) { | 3842 | if (allocated_clusters && c_offset) { |
3827 | lblk_from = lblk_start + num_blks; | 3843 | lblk_from = lblk_start + num_blks; |
3828 | lblk_to = lblk_from + (sbi->s_cluster_ratio - c_offset) - 1; | 3844 | lblk_to = lblk_from + (sbi->s_cluster_ratio - c_offset) - 1; |
@@ -4030,7 +4046,7 @@ static int get_implied_cluster_alloc(struct super_block *sb, | |||
4030 | struct ext4_ext_path *path) | 4046 | struct ext4_ext_path *path) |
4031 | { | 4047 | { |
4032 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 4048 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
4033 | ext4_lblk_t c_offset = map->m_lblk & (sbi->s_cluster_ratio-1); | 4049 | ext4_lblk_t c_offset = EXT4_LBLK_COFF(sbi, map->m_lblk); |
4034 | ext4_lblk_t ex_cluster_start, ex_cluster_end; | 4050 | ext4_lblk_t ex_cluster_start, ex_cluster_end; |
4035 | ext4_lblk_t rr_cluster_start; | 4051 | ext4_lblk_t rr_cluster_start; |
4036 | ext4_lblk_t ee_block = le32_to_cpu(ex->ee_block); | 4052 | ext4_lblk_t ee_block = le32_to_cpu(ex->ee_block); |
@@ -4048,8 +4064,7 @@ static int get_implied_cluster_alloc(struct super_block *sb, | |||
4048 | (rr_cluster_start == ex_cluster_start)) { | 4064 | (rr_cluster_start == ex_cluster_start)) { |
4049 | if (rr_cluster_start == ex_cluster_end) | 4065 | if (rr_cluster_start == ex_cluster_end) |
4050 | ee_start += ee_len - 1; | 4066 | ee_start += ee_len - 1; |
4051 | map->m_pblk = (ee_start & ~(sbi->s_cluster_ratio - 1)) + | 4067 | map->m_pblk = EXT4_PBLK_CMASK(sbi, ee_start) + c_offset; |
4052 | c_offset; | ||
4053 | map->m_len = min(map->m_len, | 4068 | map->m_len = min(map->m_len, |
4054 | (unsigned) sbi->s_cluster_ratio - c_offset); | 4069 | (unsigned) sbi->s_cluster_ratio - c_offset); |
4055 | /* | 4070 | /* |
@@ -4203,7 +4218,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4203 | */ | 4218 | */ |
4204 | map->m_flags &= ~EXT4_MAP_FROM_CLUSTER; | 4219 | map->m_flags &= ~EXT4_MAP_FROM_CLUSTER; |
4205 | newex.ee_block = cpu_to_le32(map->m_lblk); | 4220 | newex.ee_block = cpu_to_le32(map->m_lblk); |
4206 | cluster_offset = map->m_lblk & (sbi->s_cluster_ratio-1); | 4221 | cluster_offset = EXT4_LBLK_CMASK(sbi, map->m_lblk); |
4207 | 4222 | ||
4208 | /* | 4223 | /* |
4209 | * If we are doing bigalloc, check to see if the extent returned | 4224 | * If we are doing bigalloc, check to see if the extent returned |
@@ -4271,7 +4286,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, | |||
4271 | * needed so that future calls to get_implied_cluster_alloc() | 4286 | * needed so that future calls to get_implied_cluster_alloc() |
4272 | * work correctly. | 4287 | * work correctly. |
4273 | */ | 4288 | */ |
4274 | offset = map->m_lblk & (sbi->s_cluster_ratio - 1); | 4289 | offset = EXT4_LBLK_COFF(sbi, map->m_lblk); |
4275 | ar.len = EXT4_NUM_B2C(sbi, offset+allocated); | 4290 | ar.len = EXT4_NUM_B2C(sbi, offset+allocated); |
4276 | ar.goal -= offset; | 4291 | ar.goal -= offset; |
4277 | ar.logical -= offset; | 4292 | ar.logical -= offset; |