|
@@ -4298,28 +4298,28 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
|
|
|
EXT4_BLOCK_SIZE_BITS(sb);
|
|
|
stop_block = (offset + length) >> EXT4_BLOCK_SIZE_BITS(sb);
|
|
|
|
|
|
- /* If there are no blocks to remove, return now */
|
|
|
- if (first_block >= stop_block)
|
|
|
- goto out_stop;
|
|
|
+ /* If there are blocks to remove, do it */
|
|
|
+ if (stop_block > first_block) {
|
|
|
|
|
|
- down_write(&EXT4_I(inode)->i_data_sem);
|
|
|
- ext4_discard_preallocations(inode);
|
|
|
+ down_write(&EXT4_I(inode)->i_data_sem);
|
|
|
+ ext4_discard_preallocations(inode);
|
|
|
|
|
|
- ret = ext4_es_remove_extent(inode, first_block,
|
|
|
- stop_block - first_block);
|
|
|
- if (ret) {
|
|
|
- up_write(&EXT4_I(inode)->i_data_sem);
|
|
|
- goto out_stop;
|
|
|
- }
|
|
|
+ ret = ext4_es_remove_extent(inode, first_block,
|
|
|
+ stop_block - first_block);
|
|
|
+ if (ret) {
|
|
|
+ up_write(&EXT4_I(inode)->i_data_sem);
|
|
|
+ goto out_stop;
|
|
|
+ }
|
|
|
|
|
|
- if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
|
|
|
- ret = ext4_ext_remove_space(inode, first_block,
|
|
|
- stop_block - 1);
|
|
|
- else
|
|
|
- ret = ext4_ind_remove_space(handle, inode, first_block,
|
|
|
- stop_block);
|
|
|
+ if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
|
|
|
+ ret = ext4_ext_remove_space(inode, first_block,
|
|
|
+ stop_block - 1);
|
|
|
+ else
|
|
|
+ ret = ext4_ind_remove_space(handle, inode, first_block,
|
|
|
+ stop_block);
|
|
|
|
|
|
- up_write(&EXT4_I(inode)->i_data_sem);
|
|
|
+ up_write(&EXT4_I(inode)->i_data_sem);
|
|
|
+ }
|
|
|
if (IS_SYNC(inode))
|
|
|
ext4_handle_sync(handle);
|
|
|
|